function main() { $callback = ''; if (isset($_GET['callback'])) { $callback = $_GET['callback']; } if (isset($_GET['rid'])) { $rid = $_GET['rid']; } $accessions = array(); $xml_filename = 'tmp/' . $rid . '.xml'; $xml = file_get_contents($xml_filename); $dom = new DOMDocument(); $dom->loadXML($xml); $xpath = new DOMXPath($dom); $xpath_query = "//Hit_accession"; $nodeCollection = $xpath->query($xpath_query); foreach ($nodeCollection as $node) { $accessions[] = $node->firstChild->nodeValue; } $ids = array_slice($accessions, 0, NumSequences); $hits = fetch_sequences($ids); if ($callback != '') { echo $callback . '('; } echo json_format(json_encode($hits)); if ($callback != '') { echo ')'; } }
function setConfigData($cfg) { $tmplFile = '<? $GLOBALS[$cfgCategory] = json_decode(\''.json_format(json_encode($cfg)).'\', true); ?>'; $cfgFileName = 'conf/default.php'; @chmod('conf', 0777); if(file_exists($cfgFileName)) unlink($cfgFileName); WriteToFile($cfgFileName, $tmplFile); }
public function export($var) { $var = $this->_formatVarAsJSON($var); $string = json_encode($var); foreach ($this->_jsonParams as $index => $value) { $string = str_replace("\"" . $this->_param($index) . "\"", $value, $string); } return json_unicode_to_utf8(json_format($string)); }
function writeFile($filename, $dir, $tweetData) { if (!file_exists($dir)) { mkdir($dir, 0777, true); } $filepath = "{$dir}/{$filename}"; $filtered_tweets = array_map(function ($tweet) { $user = $tweet->{'user'}; return (object) array('userId' => $user->{'id'}, 'user' => $user->{'name'}, 'location' => $user->{'location'}, 'text' => $tweet->{'text'}, 'date' => $tweet->{'created_at'}, 'retweetCount' => $tweet->{'retweet_count'}, 'favoriteCount' => $tweet->{'favorite_count'}); }, json_decode($tweetData)); $fh = fopen($filepath, 'w'); fwrite($fh, json_format($filtered_tweets)); fclose($fh); }
function api_output($obj, $callback) { $status = 404; // $obj may be array (e.g., for citeproc) if (is_array($obj)) { if (isset($obj['status'])) { $status = $obj['status']; } } // $obj may be object if (is_object($obj)) { if (isset($obj->status)) { $status = $obj->status; } } switch ($status) { case 303: header('HTTP/1.1 404 See Other'); break; case 404: header('HTTP/1.1 404 Not Found'); break; case 410: header('HTTP/1.1 410 Gone'); break; case 500: header('HTTP/1.1 500 Internal Server Error'); break; default: break; } header("Content-type: text/plain"); header("Cache-control: max-age=3600"); if ($callback != '') { echo $callback . '('; } //echo json_encode($obj, JSON_PRETTY_PRINT); echo json_format(json_encode($obj)); if ($callback != '') { echo ')'; } }
function find_clusters($text, $format = 'json') { $obj = new stdclass(); $obj->text = $text; $strings = explode("\n", trim($text)); $obj->result = cluster($strings); switch ($format) { case 'json': echo json_format(json_encode($obj)); break; case 'html': default: echo '<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <style type="text/css" title="text/css"> body { font-family: sans-serif; margin:20px; } </style> <a href="clusterstrings.php">Home</a> <title>Cluster strings</title> </head> <body> <h1>Cluster strings results</h1>'; echo '<pre>'; echo $obj->result->graph; echo '</pre>'; //echo str_replace("\n", '', $obj->result->graph); $s = urlencode(str_replace("\n", '', $obj->result->graph)); echo '<img src="http://chart.googleapis.com/chart?cht=gv&chl=' . $s . '" />'; echo '<pre>'; print_r($obj->result->clusters); echo '</pre>'; echo '</body> </html>'; break; } }
function dv_config_current() { global $com_name, $conf; $base = $conf['dir_base']; $db_id = Request::getString('db', false); require_once JPATH_COMPONENT_SITE . DS . 'dv_config.php'; $dv_conf_file = $base . DS . $db_id . DS . 'applications/dataviewer/config.json'; $db_dv_conf = array(); if (file_exists($dv_conf_file)) { $db_dv_conf = json_decode(file_get_contents($dv_conf_file), true); if (!is_array($db_dv_conf)) { $db_dv_conf = array(); } if (isset($db_dv_conf['settings'])) { $db_dv_conf['settings'] = array_merge($dv_conf['settings'], $db_dv_conf['settings']); } } $dv_conf = array_merge($dv_conf, $db_dv_conf); print json_format(json_encode($dv_conf)); exit; }
function find_specimens($text, $format = 'json') { $obj = new stdclass(); $obj->text = $text; $obj->codes = extract_specimen_codes($text); switch ($format) { case 'json': $obj->text = html_entity_decode($obj->text, ENT_QUOTES, 'UTF-8'); echo json_format(json_encode($obj)); break; case 'html': default: echo '<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <style type="text/css" title="text/css"> body { font-family: sans-serif; margin:20px; } </style> <a href="specimenparser.php">Home</a> <title>Specimen parser</title> </head> <body> <h1>Specimen parser results</h1> <h2>Specimen codes</h2> <ul>'; foreach ($obj->codes as $code) { echo '<li>' . $code . '</li>'; } echo '</ul> <h2>Input</h2> <p>' . htmlentities($obj->text, ENT_QUOTES, 'UTF-8') . '</p> </body> </html>'; break; } }
/** * filename, brief description, date of creation, by whom * @copyright (C) 2005-2010 University of Sydney Digital Innovation Unit. * @link: http://HeuristNetwork.org * @license http://www.gnu.org/licenses/gpl-3.0.txt * @package Heurist academic knowledge management system * @todo **/ header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past session_cache_limiter('no-cache'); define('SAVE_URI', 'disabled'); define('SEARCH_VERSION', 1); require_once dirname(__FILE__) . "/../../common/connect/applyCredentials.php"; require_once dirname(__FILE__) . "/../../common/php/dbMySqlWrappers.php"; require_once dirname(__FILE__) . "/../../records/disambig/findFuzzyRecordMatches.php"; $data = json_decode(@$_POST["data"] ? $_POST["data"] : base64_decode(@$_GET["data"]), true); $details = @$data["details"]; $types = @$data["types"]; $id = @$data["id"] ? $data["id"] : null; $fuzziness = @$data["fuzziness"] ? $data["fuzziness"] : null; if (!$details || !$types) { print json_format(array("error" => "invalid arguments")); return; } mysql_connection_select(DATABASE); $matches = findFuzzyMatches($details, $types, $id, $fuzziness); print json_format(array("matches" => $matches));
function toPrettyString() { return json_format($this->toString()); }
/** * save loaded data to plugin composer file * * @return void */ public function write() { $json = json_encode($this->data); if (function_exists('json_format')) { $json = json_format($json); } else { $json = \Composer\Json\JsonFormatter::format($json, true, true); } file_put_contents($this->path, $json); }
/** * @brief Handle OpenURL request * * We may have more than one parameter with same name, so need to access QUERY_STRING, not _GET * http://stackoverflow.com/questions/353379/how-to-get-multiple-parameters-with-same-name-from-a-url-in-php * */ function main() { global $config; global $debug; global $format; $id = 0; $callback = ''; // If no query parameters if (count($_GET) == 0) { display_form(); exit(0); } if (isset($_GET['format'])) { switch ($_GET['format']) { case 'html': $format = 'html'; break; case 'json': $format = 'json'; break; default: $format = 'html'; break; } } if (isset($_GET['callback'])) { $callback = $_GET['callback']; } $debug = false; if (isset($_GET['debug'])) { $debug = true; } // Handle query and display results. $query = explode('&', html_entity_decode($_SERVER['QUERY_STRING'])); $params = array(); foreach ($query as $param) { list($key, $value) = explode('=', $param); $key = preg_replace('/^\\?/', '', urldecode($key)); $params[$key][] = trim(urldecode($value)); } if ($debug) { echo '<h1>Params</h1>'; echo '<pre>'; print_r($params); echo '</pre>'; } // This is what we got from user $referent = new stdclass(); parse_openurl($params, $referent); // Flesh it out // If we are looking for an article we need an ISSN, or at least an OCLC // Ask whether have this in our database (assumes we have ISSN) if (!isset($referent->issn)) { // Try and get ISSN from bioGUID $issn = issn_from_title($referent->secondary_title); if ($issn != '') { $referent->issn = $issn; } else { // No luck with ISSN, look for OCLC if (!isset($referent->oclc)) { $oclc = oclc_for_title($referent->secondary_title); if ($oclc != 0) { $referent->oclc = $oclc; } } } } if ($debug) { echo '<h1>Referent</h1>'; echo '<pre>'; print_r($referent); echo '</pre>'; } // Handle identifiers if (isset($referent->url)) { // BHL URL, for example if we have already mapped article to BHL // in Zotero, if (preg_match('/^http:\\/\\/(www\\.)?biodiversitylibrary.org\\/page\\/(?<pageid>[0-9]+)/', $referent->url, $matches)) { //print_r($matches); $PageID = $matches['pageid']; $references = bhl_reference_from_pageid($PageID); //print_r($references); if (count($references) == 0) { // We don't have an article for this PageID $search_hit = bhl_score_page($PageID, $referent->title); // Store $id = db_store_article($referent, $PageID); } else { // Have a reference with this PageID already // Will need to handle case where > 1 article on same page, e.g. // http://www.biodiversitylibrary.org/page/3336598 $id = $references[0]; } // Did we get a hit? if ($id != 0) { // We have this reference in our database switch ($format) { case 'json': // Display object $reference = db_retrieve_reference($id); header("Content-type: text/plain; charset=utf-8\n\n"); if ($callback != '') { echo $callback . '('; } echo json_format(json_encode($reference)); if ($callback != '') { echo ')'; } break; case 'html': default: // Redirect to reference display header('Location: ' . $config['web_root'] . 'reference/' . $id . "\n\n"); break; } exit; } } } // OK, we're not forcing a match to BHL, so do we have this article? $id = db_find_article($referent); //echo "<b>id=$id</b><br/>"; if ($id != 0) { // We have this reference in our database switch ($format) { case 'json': // Display object $reference = db_retrieve_reference($id); header("Content-type: text/plain; charset=utf-8\n\n"); if ($callback != '') { echo $callback . '('; } echo json_format(json_encode($reference)); if ($callback != '') { echo ')'; } break; case 'html': default: // Twitter as log if ($config['twitter']) { $tweet_this = false; $tweet_this = isset($_GET['rfr_id']); if ($tweet_this) { $url = $config['web_root'] . 'reference/' . $id . ' '; // . '#openurl'; // url + hashtag $url = $id; $url_len = strlen($url); $status = ''; //$text = $_GET['rfr_id']; $text = '#openurl ' . $_SERVER["HTTP_REFERER"]; //$text .= ' @rdmpage'; if (isset($article->title)) { } $status = $text; $status_len = strlen($status); $extra = 140 - $status_len - $url_len - 1; if ($extra < 0) { $status_len += $extra; $status_len -= 1; $status = substr($status, 0, $status_len); $status .= '…'; } $status .= ' ' . $url; tweet($status); } } // Redirect to reference display header('Location: reference/' . $id . "\n\n"); break; } exit; } // OK, not found, so let's go look for it... // Search BHL $atitle = ''; if (isset($referent->title)) { $atitle = $referent->title; } $search_hits = bhl_find_article($atitle, $referent->secondary_title, $referent->volume, isset($referent->spage) ? $referent->spage : $referent->pages, isset($referent->series) ? $referent->series : '', isset($referent->date) ? $referent->date : '', isset($referent->issn) ? $referent->issn : ''); if (count($search_hits) == 0) { // try alternative way of searching using article title $search_hits = bhl_find_article_from_article_title($referent->title, $referent->secondary_title, $referent->volume, isset($referent->spage) ? $referent->spage : $referent->pages, isset($referent->series) ? $referent->series : '', isset($referent->issn) ? $referent->issn : ''); } // At this point if we haven't found it in BHL we could go elsewhere, e.g. bioGUID, // in which case we'd need to take this into account when displaying HTML and JSON if ($debug) { echo '<h3>Search hits</h3>'; echo '<pre>'; print_r($search_hits); echo '</pre>'; } if (1) { // Check whether we already have an article that starts on this foreach ($search_hits as $hit) { $references = bhl_reference_from_pageid($hit->PageID); //print_r($references); if (count($references) != 0) { // We have this reference in our database switch ($format) { case 'json': // Display object $reference = db_retrieve_reference($references[0]); header("Content-type: text/plain; charset=utf-8\n\n"); if ($callback != '') { echo $callback . '('; } echo json_format(json_encode($reference)); if ($callback != '') { echo ')'; } break; case 'html': default: // Redirect to reference display header('Location: reference/' . $references[0] . "\n\n"); break; } exit; } } } // Output search results in various formats... switch ($format) { case 'json': display_bhl_result_json($referent, $search_hits, $callback); break; case 'html': default: display_bhl_result_html($referent, $search_hits); break; } }
header("Location: ".HEURIST_BASE_URL."/#data=" . $val); return ""; } ob_start("outputAsRedirect"); if ($_POST["heurist-sessionid"] != $_COOKIE["heurist-sessionid"]) { // saw TODO: check that this is ok or should this be the database session? // saveFile is only available through dispatcher.php, or if heurist-sessionid is known (presumably only our scripts will know this) getError("unauthorised HAPI user"); } } */ if (@$_REQUEST['url']) { $sURL = $_REQUEST['url']; //url to be thumbnailed $res = generate_thumbnail($sURL, true); print json_format($res); exit; } // // main function // function generate_thumbnail($sURL, $needConnect) { if (!is_logged_in()) { return getError("no logged-in user"); } $res = array(); //get picture from service //"http://www.sitepoint.com/forums/image.php?u=106816&dateline=1312480118"; $remote_path = str_replace("[URL]", $sURL, WEBSITE_THUMBNAIL_SERVICE); $heurist_path = tempnam(HEURIST_UPLOAD_DIR, "_temp_");
/** * GET wrapper for oAuthRequest. */ function get($url, $parameters = array()) { $response = $this->oAuthRequest($url, 'GET', $parameters); if ($this->format === 'json' && $this->decode_json) { return json_decode($response); } return json_format($response); }
function jlog($json) { if (!is_string($json)) { $json = json_encode($json); } echo json_format($json) . "\n"; }
} if (!@$_REQUEST['q'] || @$_REQUEST['ver'] && intval(@$_REQUEST['ver']) < SEARCH_VERSION) { construct_legacy_search(); } // migration path if (!@$_REQUEST['q'] && !@$_REQUEST['s']) { return; } // wwgd if ($_REQUEST['w'] == 'B' || $_REQUEST['w'] == 'bookmark') { $search_type = BOOKMARK; } else { $search_type = BOTH; } // all records mysql_connection_select(DATABASE); if (preg_match('/\\b_BROKEN_\\b/', $_REQUEST['q'])) { $broken = 1; $_REQUEST['q'] = preg_replace('/\\b_BROKEN_\\b/', '', $_REQUEST['q']); } $query = REQUEST_to_query("select rec_ID, bkm_ID ", $search_type); if (@$broken) { $query = str_replace(' where ', ' where (to_days(now()) - to_days(rec_URLLastVerified) >= 8) and ', $query); } $res = mysql_query($query); $ids = array(); while ($row = mysql_fetch_assoc($res)) { array_push($ids, array("recID" => $row["rec_ID"], "bkmk_id" => $row["bkm_ID"])); } print json_format($ids);
/** * @brief Handle microcitation request * */ function main() { global $config; global $debug; // If no query parameters if (count($_GET) == 0) { //display_form(); exit(0); } $callback = ''; if (isset($_GET['callback'])) { $callback = $_GET['callback']; } $format = 'json'; $debug = false; if (isset($_GET['debug'])) { $debug = true; } $q = $_GET['q']; $result->pages = matching_pages($q); if (count($result->pages) == 0) { if ($format == 'json') { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $_SERVER['REDIRECT_STATUS'] = 404; echo 'Not found'; exit; } } else { // Do we have any references for the pages? $result->references = reference_from_page($result->pages); } // Candidate pages if ($format == 'json') { header("Content-type: text/plain; charset=utf-8\n\n"); if ($callback != '') { echo $callback . '('; } echo json_format(json_encode($result)); if ($callback != '') { echo ')'; } } }
if (array_key_exists($varNames[0], $_POST)) { $updates[$colName] = $_POST[$varNames[0]]; } } mysql__update("usrBookmarks", "bkm_ID={$bkm_ID} and bkm_UGrpID={$usrID}", $updates); $res = mysql_query("select " . join(", ", array_keys($updates)) . " from usrBookmarks where bkm_ID={$bkm_ID} and bkm_UGrpID={$usrID}"); if (mysql_num_rows($res) == 1) { $dbVals = mysql_fetch_assoc($res); $hVals = array(); foreach ($dbVals as $colName => $val) { $hVals[$updatable[$colName][1]] = $val; } if ($tagString !== NULL) { $hVals["tagString"] = $tagString; } print "(" . json_format($hVals) . ")"; } else { if ($tagString !== NULL) { print "({tagString: \"" . slash($tagString) . "\"})"; } } } function doTagInsertion($bkm_ID) { global $usrID; //translate bmkID to record IT $res = mysql_query("select bkm_recID from usrBookmarks where bkm_ID={$bkm_ID}"); $rec_id = mysql_fetch_row($res); $rec_id = $rec_id[0] ? $rec_id[0] : null; if (!$rec_id) { return "";
* @version 3.1.0 * @license http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0 * @package Heurist academic knowledge management system * @subpackage !!!subpackagename for file such as Administration, Search, Edit, Application, Library */ /** * filename, brief description, date of creation, by whom * @copyright (C) 2005-2010 University of Sydney Digital Innovation Unit. * @link: http://HeuristNetwork.org * @license http://www.gnu.org/licenses/gpl-3.0.txt * @package Heurist academic knowledge management system * @todo **/ header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past session_cache_limiter('no-cache'); define('SAVE_URI', 'disabled'); define('SEARCH_VERSION', 1); require_once dirname(__FILE__) . "/../../search/getSearchResults.php"; $args = json_decode(@$_POST["data"] ? $_POST["data"] : base64_decode(@$_GET["data"]), true); $result = loadSearch($args); if (array_key_exists("records", $result)) { // turn the associative array into the non-associative one HAPI expects foreach ($result["records"] as $i => $record) { $result["records"][$i] = array(@$record["rec_ID"], null, @$record["rec_RecTypeID"], @$record["rec_Title"], @$record["details"], @$record["rec_URL"], @$record["rec_ScratchPad"], @$record["rec_OwnerUGrpID"], @$record["rec_NonOwnerVisibility"], @$record["rec_URLLastVerified"], @$record["rec_URLErrorMessage"], @$record["rec_Added"], @$record["rec_Modified"], @$record["rec_AddedByUGrpID"], @$record["rec_Hash"], @$record["bkm_ID"], null, @$record["bkm_Rating"], null, null, @$record["tags"], @$record["wgTags"], @$record["notifies"], @$record["comments"]); } } print json_format($result);
<?php require "pretty_print_json.php"; $model = $_REQUEST["sg"]; //pre processing the json before writing to file //$modelTask["task"] = $task; /*if(version_compare(PHP_VERSION, '5.4.0', '>=')){ $model = json_encode($completeModel, JSON_PRETTY_PRINT); } else { $model = json_encode($completeModel, 128); }*/ try { $modelArray = json_decode($model, true); $completeModel = "{\"task\": {$model}}"; $model = json_format($completeModel); // convert messy JSON to pretty JSON } catch (Exception $e) { echo "{ \"error\":\"" . ($e->e = getMessage() . "\"}"); // we need to log the error to the server log file } try { $name = $modelArray["taskName"]; $name = str_replace(" ", "-", $name); $name = "problems/" . $name . ".json"; //checking if the file name already exists if (file_exists($name)) { throw new Exception("File with same name already exist"); } //writing to file $file = fopen($name, "w"); fwrite($file, stripslashes($model));
function format_as_json($output_dir, $corpus, $path_to_corpus, $file_path = FALSE) { global $test_meta_file; //The tests to perform in json format global $country_map; //Maps lanaguages to countries global $metadata; //Holds the data that will be saved to json. Declared as global so we can use it in the get_score function global $test_meta; //This is the data about the tests held in an accessible array. Declared as global so we can use it in the get_score function $output_file = $output_dir . $corpus . '_transparency.json'; //echo $output_file; //Get the existing data on this provider from a file //If file doesn't exist create the start of one if (!file_exists($output_file)) { $metadata_header = array("provider" => $corpus, "hierarchy" => 0, "activityCount" => 100); $json = json_encode($metadata_header); file_put_contents($output_file, $json); //die; } $json = file_get_contents($output_file); $metadata = json_decode($json, true); //print_r($metadata); //die; //Get the test metadata so we know what threasholds and scores to apply to this test $test_meta = file_get_contents($test_meta_file); $test_meta = json_decode($test_meta, true); //print_r($test_meta); die; //test the providers files and return the data for us if ($file_path) { $data = count_attributes($path_to_corpus, basename($file_path)); //echo "yes"; } else { $data = count_attributes($path_to_corpus); } //print_r($data) ; die; //Set the hierarcy that we're going to test one. the rule is the lowest i.e. highest number which should be the last value of $data["hierarchies"] $metadata["hierarchy"] = end($data["hierarchies"]); reset($data["hierarchies"]); //end moves the array pointer to the end of the array, so lets rest it // Number of activities $metadata["activityCount"] = $data["no-activities"][$metadata["hierarchy"]]; //number of activities tested at our hierarchy level //echo $metadata["activityCount"]; die; //get the results for the json file //sTet up some variables for activiy-date element first //$attribute_values = array("start-planned","start-actual","end-planned","end-actual"); $attribute_values = array("start", "end"); //$attribute_start_values = array("start-planned","start-actual"); //$attribute_end_values = array("end-planned","end-actual"); $start = $end = 0; //print_r($data["participating_org_implementing"]); die; foreach ($data["hierarchies"] as $hierarchy) { //The count attributes routine fetches data at all hierarchies, but we only need to test the lowest usually. if ($hierarchy == $metadata["hierarchy"]) { //Set for each provider in a metadata file //Elements $document_links = $result_element = $conditions = 0; if (isset($data["document_links"][$hierarchy])) { $document_links = count($data["document_links"][$hierarchy]); } if (isset($data["result_element"][$hierarchy])) { $result_element = count($data["result_element"][$hierarchy]); } if (isset($data["conditions"][$hierarchy])) { $conditions = count($data["conditions"][$hierarchy]); } //Participating org test $participating_org_accountable = $participating_org_implementing = 0; if (isset($data["participating_org_accountable"][$hierarchy])) { $participating_org_accountable = array_unique($data["participating_org_accountable"][$hierarchy]); $participating_org_accountable = count($participating_org_accountable); } if (isset($data["participating_org_implementing"][$hierarchy])) { $participating_org_implementing = array_unique($data["participating_org_implementing"][$hierarchy]); $participating_org_implementing = count($participating_org_implementing); } //echo $participating_org_implementing; die; //Budget/Planned Disbursement $budget = 0; if (isset($data["budget"][$hierarchy])) { $budget = count($data["budget"][$hierarchy]); } //Identifiers $unique_ids = array_unique($data["identifiers"][$hierarchy]["good"]); //In case identifiers are used more than once $good_ids = count($unique_ids); //Transactions $transaction_type_commitment = $transaction_type_disbursements = $transaction_type_expenditure = 0; $unique_commitments = $unique_disbursements = $unique_expenditure = array(); if (isset($data["transaction_type_commitment"][$hierarchy])) { $unique_commitments = array_unique($data["transaction_type_commitment"][$hierarchy]); //In case one activity has more than one commitment $transaction_type_commitment = count($unique_commitments); } if (isset($data["transaction_type_disbursement"][$hierarchy])) { $unique_disbursements = array_unique($data["transaction_type_disbursement"][$hierarchy]); //In case one activity has more than one commitment $transaction_type_disbursements = count($unique_disbursements); //echo $transaction_type_disbursements; //die; } if (isset($data["transaction_type_expenditure"][$hierarchy])) { $unique_expenditure = array_unique($data["transaction_type_expenditure"][$hierarchy]); //In case one activity has more than one commitment $transaction_type_expenditure = count($unique_expenditure); } //echo $transaction_type_expenditure; die; //Test to see if an activity has either //Both a disbursement and an expenditure /* This would mean looping through one array and seeing if iati-identifier values are in both. And getting a count * Or if one array is smaller than the treashold then it's a fail?? * Or an array diff would give us numbers of activites that don't have both (but not the numbers without any!! //OR //Either a disbursement or an expenditure * We could merge the arrays, and then array unique it to get our count */ $disbursements_expenditure = array_merge($unique_disbursements, $unique_expenditure); $unique_disbursements_expenditure = array_unique($disbursements_expenditure); $disbursements_expenditure_count = count($unique_disbursements_expenditure); //Tracable Transactions $no_disbursements = $data["no_disbursements"][$hierarchy]; //echo $no_disbursements . PHP_EOL; $no_incoming_funds = $data["no_incoming_funds"][$hierarchy]; //echo $no_incoming_funds . PHP_EOL; $transactions_that_should_be_traced = $no_disbursements + $no_incoming_funds; //echo $transactions_that_should_be_traced . PHP_EOL; $no_tracable_transactions = $data["no_tracable_transactions"][$hierarchy]; //echo $no_tracable_transactions . PHP_EOL; // die; if ($no_tracable_transactions > 0) { //avoid divide by zero $percent_tracable = 100 * round($no_tracable_transactions / $transactions_that_should_be_traced, 2); $tracable_threashold = $test_meta["test"]["Financial transaction recipient / Provider activity Id"]["threashold"]; //echo $test_meta["test"]["Financial transaction recipient / Provider activity Id"]["threashold"]; if ($percent_tracable >= $tracable_threashold) { //echo "yes"; die; $tracable_score = $test_meta["test"]["Financial transaction recipient / Provider activity Id"]["score"]; } else { $tracable_score = 0; } } else { $tracable_score = $percent_tracable = 0; } //Location //$activities_with_location = $activities_with_coordinates = $activities_with_adminstrative = 0; //Count activities with structured location data //This is either co-ordinates present or //administartive element and adm1 or adm2 attribute //This MUST be a subset of the location count (mustn't it?) $activities_with_coordinates = $activities_with_adminstrative = array(); //set up empty arrays first if (isset($data["activities_with_coordinates"][$hierarchy])) { $activities_with_coordinates = array_unique($data["activities_with_coordinates"][$hierarchy]); } if (isset($data["activities_with_adminstrative"][$hierarchy])) { $activities_with_adminstrative = array_unique($data["activities_with_coordinates"][$hierarchy]); } $activities_with_structure_locations = array_merge($activities_with_coordinates, $activities_with_adminstrative); //if arrays are empty this is ok! $activities_with_structure_locations = array_unique($activities_with_structure_locations); //need to unique them as activities can have both $activities_with_structure_locations_count = count($activities_with_structure_locations); //echo $activities_with_structure_locations_count . PHP_EOL; $activities_with_location_count = 0; $activities_with_location = array(); if (isset($data["activities_with_location"][$hierarchy])) { $activities_with_location = array_unique($data["activities_with_location"][$hierarchy]); } //$activities_with_location = array_merge($activities_with_location,$activities_with_structure_locations); $activities_with_location = array_unique($activities_with_location); $activities_with_location_count = count($activities_with_location); //echo $activities_with_location_count . PHP_EOL; // $location_level_1 = $activities_with_location_count; $location_level_2 = $activities_with_structure_locations_count; //die; //Sector $activities_sector_declared_dac = $activities_sector_assumed_dac = array(); if (isset($data["activities_sector_declared_dac"][$hierarchy])) { $activities_sector_declared_dac = $data["activities_sector_declared_dac"][$hierarchy]; $activities_sector_declared_dac = array_unique($activities_sector_declared_dac); } if (isset($data["activities_sector_assumed_dac"][$hierarchy])) { $activities_sector_assumed_dac = $data["activities_sector_assumed_dac"][$hierarchy]; $activities_sector_assumed_dac = array_unique($activities_sector_assumed_dac); } $activities_with_dac_sector = array_merge($activities_sector_declared_dac, $activities_sector_assumed_dac); //probably don't need to 'unique' this, but won't hurt $activities_with_dac_sector = array_unique($activities_with_dac_sector); $activities_with_dac_sector_count = count($activities_with_dac_sector); //echo $activities_with_dac_sector_count . PHP_EOL; // die; // die; //Last-updated-datetime //$most_recent = $data["most_recent"][$hierarchy]; //Activity Dates foreach ($attribute_values as $value) { //Loop through all possible results if (isset($data["activities_with_attribute"][$hierarchy][$value])) { //echo $value . PHP_EOL; $count = count(array_unique($data["activities_with_attribute"][$hierarchy][$value])); //if (in_array($value, $attribute_start_values)) { if ($value == "start") { $start = $start + $count; //} elseif (in_array($value, $attribute_end_values)) { } else { if ($value == "end") { $end = $end + $count; } } } } //Languages $activies_in_country_lang = array(); if (isset($data["activies_in_country_lang"][$hierarchy])) { $activies_in_country_lang = $data["activies_in_country_lang"][$hierarchy]; $activies_in_country_lang = array_unique($activies_in_country_lang); } $activies_in_country_lang_count = count($activies_in_country_lang); //echo $activies_in_country_lang_count; //die; } } //echo $start . PHP_EOL; //echo $end . PHP_EOL; //Work out the scores $start_score = get_score($start, "Activity Dates (Start Date)"); $end_score = get_score($end, "Activity Dates (End Date)"); $document_links_score = get_score($document_links, "Activity Documents"); $conditions_score = get_score($conditions, "Text of Conditions"); $result_element_score = get_score($result_element, "Results data"); $participating_org_accountable_score = get_score($participating_org_accountable, "Participating Organisation (Accountable)"); $participating_org_implementing_score = get_score($participating_org_implementing, "Participating Organisation (Implementing)"); $budget_score = get_score($budget, "Activity Budget / Planned Disbursement"); $good_ids_score = get_score($good_ids, "IATI activity identifier"); $transaction_type_commitment_score = get_score($transaction_type_commitment, "Financial transaction (Commitment)"); $transaction_type_disb_expend_score = get_score($disbursements_expenditure_count, "Financial transaction (Disbursement & Expenditure)"); $location_level_1_score = get_score($location_level_1, "Sub-national Geographic Location (text)"); $location_level_2_score = get_score($location_level_2, "Sub-national Geographic Location (structure)"); $activities_with_dac_sector_score = get_score($activities_with_dac_sector_count, "Sector (DAC CRS)"); $activies_in_country_lang_score = get_score($activies_in_country_lang_count, "Activity Title or Description (Recipient language)"); $metadata["tests"]["activityDateStart"]["count"] = $start; $metadata["tests"]["activityDateStart"]["score"] = $start_score["score"]; $metadata["tests"]["activityDateStart"]["percentage"] = $start_score["percentage"]; $metadata["tests"]["activityDateEnd"]["count"] = $end; $metadata["tests"]["activityDateEnd"]["score"] = $end_score["score"]; $metadata["tests"]["activityDateEnd"]["percentage"] = $end_score["percentage"]; $metadata["tests"]["documentLink"]["count"] = $document_links; $metadata["tests"]["documentLink"]["score"] = $document_links_score["score"]; $metadata["tests"]["documentLink"]["percentage"] = $document_links_score["percentage"]; $metadata["tests"]["result"]["count"] = $result_element; $metadata["tests"]["result"]["score"] = $result_element_score["score"]; $metadata["tests"]["result"]["percentage"] = $result_element_score["percentage"]; $metadata["tests"]["conditions"]["count"] = $conditions; $metadata["tests"]["conditions"]["score"] = $conditions_score["score"]; $metadata["tests"]["conditions"]["percentage"] = $conditions_score["percentage"]; $metadata["tests"]["participatingOrgImplementing"]["count"] = $participating_org_implementing; $metadata["tests"]["participatingOrgImplementing"]["score"] = $participating_org_implementing_score["score"]; $metadata["tests"]["participatingOrgImplementing"]["percentage"] = $participating_org_implementing_score["percentage"]; $metadata["tests"]["participatingOrgAccountable"]["count"] = $participating_org_accountable; $metadata["tests"]["participatingOrgAccountable"]["score"] = $participating_org_accountable_score["score"]; $metadata["tests"]["participatingOrgAccountable"]["percentage"] = $participating_org_accountable_score["percentage"]; $metadata["tests"]["budget"]["count"] = $budget; $metadata["tests"]["budget"]["score"] = $budget_score["score"]; $metadata["tests"]["budget"]["percentage"] = $budget_score["percentage"]; $metadata["tests"]["iatiIdentifier"]["count"] = $good_ids; $metadata["tests"]["iatiIdentifier"]["score"] = $good_ids_score["score"]; $metadata["tests"]["iatiIdentifier"]["percentage"] = $good_ids_score["percentage"]; $metadata["tests"]["transactionTypeCommitment"]["count"] = $transaction_type_commitment; $metadata["tests"]["transactionTypeCommitment"]["score"] = $transaction_type_commitment_score["score"]; $metadata["tests"]["transactionTypeCommitment"]["percentage"] = $transaction_type_commitment_score["percentage"]; $metadata["tests"]["transactionTypeDisbursementExpenditure"]["count"] = $disbursements_expenditure_count; $metadata["tests"]["transactionTypeDisbursementExpenditure"]["score"] = $transaction_type_disb_expend_score["score"]; $metadata["tests"]["transactionTypeDisbursementExpenditure"]["percentage"] = $transaction_type_disb_expend_score["percentage"]; $metadata["tests"]["transactionTracability"]["eligable"] = $transactions_that_should_be_traced; $metadata["tests"]["transactionTracability"]["count"] = $no_tracable_transactions; $metadata["tests"]["transactionTracability"]["score"] = $tracable_score; $metadata["tests"]["transactionTracability"]["percentage"] = $percent_tracable; $metadata["tests"]["locationText"]["count"] = $location_level_1; $metadata["tests"]["locationText"]["score"] = $location_level_1_score["score"]; $metadata["tests"]["locationText"]["percentage"] = $location_level_1_score["percentage"]; $metadata["tests"]["locationStructure"]["count"] = $location_level_2; $metadata["tests"]["locationStructure"]["score"] = $location_level_2_score["score"]; $metadata["tests"]["locationStructure"]["percentage"] = $location_level_2_score["percentage"]; $metadata["tests"]["sector"]["count"] = $activities_with_dac_sector_count; $metadata["tests"]["sector"]["score"] = $activities_with_dac_sector_score["score"]; $metadata["tests"]["sector"]["percentage"] = $activities_with_dac_sector_score["percentage"]; $metadata["tests"]["language"]["count"] = $activies_in_country_lang_count; $metadata["tests"]["language"]["score"] = $activies_in_country_lang_score["score"]; $metadata["tests"]["language"]["percentage"] = $activies_in_country_lang_score["percentage"]; $json = json_encode($metadata); $json = json_format($json); //pretty it up . Function from include functions/pretty_json.php file_put_contents($output_file, $json); //die; }
function error_exit($msg) { header('Content-type: text/javascript; charset=utf-8'); print json_format(array('error' => $msg)); exit; }
$callback = ''; $journal = ''; $volume = ''; $page = ''; $year = ''; if (isset($_GET['callback'])) { $callback = $_GET['callback']; } if (isset($_GET['journal'])) { $journal = $_GET['journal']; } if (isset($_GET['volume'])) { $volume = $_GET['volume']; } if (isset($_GET['page'])) { $page = $_GET['page']; } if (isset($_GET['year'])) { $year = $_GET['year']; } $search = new stdclass(); $search->results = find_reference($journal, $volume, $page, $year); $search->count = count($search->results); header("Content-type: text/plain; charset=utf-8\n\n"); if ($callback != '') { echo $callback . '('; } echo json_format(json_encode($search)); if ($callback != '') { echo ')'; }
* Use the resulting JSON export file in other languages * other than PHP. Always check for 'version' key because * new major versions can modify the structure of the JSON file. * * The result of running this script is the export.json file. * * @license Code and contributions have 'MIT License' * More details: https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt * */ // Included nicejson function to beautify the result JSON file. // This library is not mandatory. if (file_exists(dirname(__FILE__) . '/nicejson/nicejson.php')) { include_once dirname(__FILE__) . '/nicejson/nicejson.php'; } // Include Mobile Detect. require_once dirname(__FILE__) . '/../Mobile_Detect.php'; $detect = new Mobile_Detect(); $json = array('version' => $detect->getScriptVersion(), 'headerMatch' => $detect->getMobileHeaders(), 'uaHttpHeaders' => $detect->getUaHttpHeaders(), 'uaMatch' => array('phones' => $detect->getPhoneDevices(), 'tablets' => $detect->getTabletDevices(), 'browsers' => $detect->getBrowsers(), 'os' => $detect->getOperatingSystems(), 'utilities' => $detect->getUtilities())); $jsonString = function_exists('json_format') ? json_format($json) : json_encode($json); // Write the JSON file to disk. // You can import this file in your app. $fileName = dirname(__FILE__) . '/../Mobile_Detect.json'; $handle = fopen($fileName, 'w'); $fwrite = fwrite($handle, $jsonString); fclose($handle); if ($fwrite) { echo 'Done. Check ' . realpath($fileName) . ' file.'; } else { echo 'Failed to write ' . realpath($fileName) . ' to disk.'; }
while ($row = mysql_fetch_row($res)) { $userGrp['users'][$row[0]] = $row; } } if (!is_logged_in()) { $query = mysql_query("SELECT ugr_FirstName, ugr_LastName, ugr_eMail FROM sysUGrps WHERE ugr_ID=2"); $details = mysql_fetch_row($query); $fullName = $details[0] . " " . $details[1]; $eMail = $details[2]; $userGrp['adminName'] = $fullName; $userGrp['adminMail'] = $eMail; } // using ob_gzhandler makes this stuff up on IE6- //ini_set("zlib.output_compression_level", 5); //ob_start('ob_gzhandler'); print "top.HEURIST.userGrp = " . json_format($userGrp) . ";\n"; print "\n"; } ?> if (typeof top.HEURIST.fireEvent == "function") top.HEURIST.fireEvent(window, "heurist-obj-user-loaded"); <?php //ob_end_flush(); } } } } //search the particular user info } else { //logged in ?> top.document.body.className += " is-not-logged-in";
$has_descr = true; //(@$_REQUEST['has_descr']=="1"); if (!$parent_id) { return; } $success_msg = null; $failure_msg = null; $res_array = null; $res = upload_termsfile($parent_id, $domain, $has_codes, $has_descr); //$res = array(); if ($res != null) { if (array_key_exists('error', $res)) { $failure_msg = $res['error']; } else { $success_msg = "List of terms has been imported."; $res_array = json_format($res); } } ?> <html> <head> <title>Import list of terms into current branch</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <link rel="stylesheet" type="text/css" href="<?php echo HEURIST_BASE_URL; ?> common/css/global.css"> <link rel="stylesheet" type="text/css" href="<?php echo HEURIST_BASE_URL; ?>
if (!is_logged_in()) { jsonError("no logged-in user"); } if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && empty($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0) { jsonError("File is too large. " . $_SERVER['CONTENT_LENGTH'] . " bytes exceeds the limit of " . ini_get('post_max_size') . ". Please get system administrator to increase the file size limits or load your large files on a video server or other suitable web service and use the URL to reference the file here"); } else { $upload = @$_FILES["file"]; if ($upload) { mysql_connection_overwrite(DATABASE); mysql_query("start transaction"); //POST Content-Length of 103399974 bytes exceeds the limit of 29360128 bytes in Unknown on line //$upload["type"] $fileID = upload_file($upload["name"], null, $upload["tmp_name"], $upload["error"], $upload["size"], $_REQUEST["description"], false); if (is_numeric($fileID)) { $file = get_uploaded_file_info($fileID, false); print json_format($file); mysql_query("commit"); } else { if ($fileID) { jsonError($fileID); } else { if ($_FILES["file"]["error"]) { jsonError("uploaded file was too large"); } else { jsonError("file upload was interrupted"); } } } } else { jsonError("File data are not posted to server side"); }
$item = new stdclass(); $item->uri = $config['web_root'] . 'reference/' . $reference_id; $item->type = $reference->genre; $item->label = $reference->title; // Group journals if (!isset($journal_names[$reference->issn])) { $journal_names[$reference->issn] = $reference->secondary_title; } $item->journal = $journal_names[$reference->issn]; $item->citation = reference_authors_to_text_string($reference) . ' (' . $reference->year . ') ' . reference_to_citation_text_string($reference); $item->year = $reference->year; if ($reference->PageID != 0) { $image = bhl_fetch_page_image($reference->PageID); $item->imageURL = $image->thumbnail->url; } else { // if it's an article we could use journal image $item->imageURL = 'http://bioguid.info/issn/image.php?issn=' . $reference->issn; } $item->coauthors = array(); foreach ($reference->authors as $author) { if (in_array($author->id, $c)) { $item->coauthors[] = $author->forename . ' ' . $author->lastname; } } $exhibit->items[] = $item; } } echo json_format(json_encode($exhibit)); ?>
foreach ($data as $dt) { $dt_id = $dt[0]; $dt_mode = $dt[1]; $dt_val = $dt[2]; $query = "update defDetailTypes set "; if ($dt_mode == 0) { $query = $query . "dty_JsonTermIDTree"; } else { if ($dt_mode == 1) { $query = $query . "dty_TermIDTreeNonSelectableIDs"; } else { if ($dt_mode == 2) { $query = $query . "dty_PtrTargetRectypeIDs"; } else { continue; } } } $query = $query . "='" . $dt_val . "' where dty_ID=" . $dt_id; $k++; $res = mysql_query($query); if (mysql_error()) { $rv['error'] = "SQL error updating field type " . $dt_id . ": " . mysql_error(); print json_format($rv); return; } } //for $rv['result'] = $k . " field" . ($k > 1 ? "s have" : " has") . " been repaired. If you have unsaved data in an edit form, save your changes and reload the page to apply revised/corrected field definitions"; print json_format($rv);
$deletions = array(); $additions = array(); foreach ($actions as $action) { $kwd_id = intval(substr($action, 4)); if (!$kwd_id) { continue; } if (substr($action, 0, 3) == "del") { $deletions[$kwd_id] = $kwd_id; unset($additions[$kwd_id]); } else { if (substr($action, 0, 3) == "add") { $additions[$kwd_id] = $kwd_id; unset($deletions[$kwd_id]); } } } if (count($deletions) > 0) { mysql_query("delete from usrRecTagLinks where rtl_RecID={$rec_id} and rtl_TagID in (" . join($deletions, ",") . ")"); } if (count($additions) > 0) { $query = "insert into usrRecTagLinks (rtl_TagID, rtl_RecID) values (" . join(",{$rec_id}), (", $additions) . ",{$rec_id})"; mysql_query($query); } $res = mysql_query("select tag_ID from usrRecTagLinks, usrTags where rtl_TagID=tag_ID and rtl_RecID={$rec_id}"); $kwd_ids = array(); while ($row = mysql_fetch_row($res)) { array_push($kwd_ids, $row[0]); } print "(" . json_format($kwd_ids) . ")"; }