Grima  2018-08
Whispering into Alma's ear
Functions
grima-util.php File Reference

Go to the source code of this file.

Functions

 XMLtoWeb ( $DOM)
 
 importXML ( $DOM, $xmlString)
 
 appendInnerXML ( $elt, $xmlString)
 
 setInnerXML ( $elt, $xmlString)
 
 pauseAndAsk ()
 
 do_redirect ($url)
 
 bib_get ($mms_id)
 
 mfhd_get ($mms_id, $holding_id)
 
 join_paths (... $paths)
 

Function Documentation

◆ appendInnerXML()

appendInnerXML (   $elt,
  $xmlString 
)

Definition at line 20 of file grima-util.php.

References importXML().

Referenced by AlmaObjectWithMARC\appendField(), Holding\setCallNumber(), and setInnerXML().

20  {
21  $DOM = $elt->ownerDocument;
22  $frag = importXML( $DOM, $xmlString );
23  $elt->appendChild( $frag );
24 }
importXML( $DOM, $xmlString)
Definition: grima-util.php:14

◆ bib_get()

bib_get (   $mms_id)

Definition at line 56 of file grima-util.php.

56  {
57  require_once("grima-config.php");
58  $url = $hostname . '/almaws/v1/bibs/{mms_id}';
59  $ch = curl_init();
60  $templateParamNames = array('{mms_id}');
61  $templateParamValues = array(urlencode($mms_id));
62  $url = str_replace($templateParamNames, $templateParamValues, $url);
63  $queryParams = '?view=full&expand=None&apikey=' . urlencode($apikey);
64  curl_setopt($ch, CURLOPT_URL, $url . $queryParams);
65  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
66  curl_setopt($ch, CURLOPT_HEADER, FALSE);
67  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
68  $response = curl_exec($ch);
69  curl_close($ch);
70  return $response;
71 }

◆ do_redirect()

do_redirect (   $url)

Definition at line 45 of file grima-util.php.

Referenced by GrimaTask\call(), and GrimaTask\check_login().

45  {
46  if(!headers_sent()) header("Location: $url");
47  $url_html = htmlspecialchars($url);
48 echo "<!DOCTYPE html><html><head><title>Redirect</title><meta http-equiv=refresh content='1; url=$url'></head><body><a href='$url_html'>Go here: $url_html</a></body></html>\n";
49  exit;
50 }

◆ importXML()

importXML (   $DOM,
  $xmlString 
)

Definition at line 14 of file grima-util.php.

Referenced by appendInnerXML().

14  {
15  $frag = $DOM->createDocumentFragment();
16  $frag->appendXML($xmlString);
17  return $frag;
18 }

◆ join_paths()

join_paths (   $paths)

Definition at line 114 of file grima-util.php.

Referenced by GrimaTask\__construct(), GrimaDB\getDb(), and Grima\session_init().

114  {
115  return preg_replace('~[/\\\\]+~', DIRECTORY_SEPARATOR, implode(DIRECTORY_SEPARATOR, $paths));
116 }

◆ mfhd_get()

mfhd_get (   $mms_id,
  $holding_id 
)

Definition at line 73 of file grima-util.php.

73  {
74  require_once("grima-config.php");
75  $url = $hostname . '/almaws/v1/bibs/{mms_id}/holdings/{holding_id}';
76  $ch = curl_init();
77  $templateParamNames = array('{mms_id}','{holding_id}');
78  $templateParamValues = array(urlencode($mms_id,$holding_id));
79  $url = str_replace($templateParamNames, $templateParamValues, $url);
80  $queryParams = '?view=full&expand=None&apikey=' . urlencode($apikey);
81  curl_setopt($ch, CURLOPT_URL, $url . $queryParams);
82  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
83  curl_setopt($ch, CURLOPT_HEADER, FALSE);
84  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
85  $response = curl_exec($ch);
86  curl_close($ch);
87  return $response;
88 }

◆ pauseAndAsk()

pauseAndAsk ( )

Definition at line 32 of file grima-util.php.

32  {
33  echo "Are you sure you want to do this? Type 'yes' to continue: ";
34  $handle = fopen ("php://stdin","r");
35  $line = fgets($handle);
36  if(trim($line) != 'yes'){
37  echo "ABORTING!\n";
38  exit;
39  }
40  fclose($handle);
41  echo "\n";
42  echo "Thank you, continuing...\n";
43 }

◆ setInnerXML()

setInnerXML (   $elt,
  $xmlString 
)

Definition at line 26 of file grima-util.php.

References appendInnerXML().

26  {
27  while( $elt->hasChildNodes() )
28  $elt->removeChild( $elt->lastChild );
29  appendInnerXML( $elt, $xmlString );
30 }
appendInnerXML( $elt, $xmlString)
Definition: grima-util.php:20

◆ XMLtoWeb()

XMLtoWeb (   $DOM)

Definition at line 7 of file grima-util.php.

7  {
8  header('Content-Type: text/plain');
9  $DOM->preserveWhiteSpace = false;
10  $DOM->formatOutput = true;
11  print $DOM->saveXML();
12 }