This is an old revision of the document! Custom Book and Page TABS
<?php // $Id$ ... Tip function islandora_book_create_book_index($pid, $query = NULL) { global $user; module_load_include('inc', 'fedora_repository', 'ObjectHelper'); $path = drupal_get_path('module', 'islandora_book'); $objectHelper = new ObjectHelper; $rels_xml = $objectHelper->getStream($pid, 'RELS-EXT'); $simpleRELSxml = simplexml_load_string($rels_xml); $modello = $simpleRELSxml->xpath('//rdf:RDF/rdf:Description/fedora-model:hasModel/@rdf:resource'); $parentcolle = $simpleRELSxml->xpath('//rdf:RDF/rdf:Description/fedora:isMemberOfCollection/@rdf:resource'); $modello = $modello[0]; $parentcolle = explode('/', $parentcolle[0]); $parentcolle = $parentcolle[1]; if ($modello == 'info:fedora/islandora:bookCModel') { $index_html = $objectHelper->getStream($pid, 'INDEX'); $ix_html = $objectHelper->getStream($pid, 'INDEX'); $piddelbook = $pid; if (!$index_html) { drupal_set_message(t('Object does not exist.'), 'error'); return ''; } } else { $piddelbook = substr($pid, 0, -5); $index_html = $objectHelper->getStream($piddelbook, 'INDEX'); $ix_html = $objectHelper->getStream($piddelbook, 'INDEX'); if (!$index_html) { drupal_set_message(t('Object does not exist.'), 'error'); return ''; } } $str_html = "<table cellpadding=\"3\" cellspacing=\"2\" valign=\"top\" >"; $str_html = $str_html . "<tr><td valign=\"top\">"; $str_html = $str_html . "<img src=\"" . base_path() . "fedora/repository/" . $pid . "/TN\"></img>"; $str_html = $str_html . "</td><td><div style=\"align:left\"><table cellpadding=\"3\" cellspacing=\"2\" width=\"90\%\">"; $str_html = $str_html . "<tbody><tr><td colspan=\"3\"><h3>Index</h3></td></tr>"; $elenco = explode("||", $ix_html); $nvoci = sizeof($elenco); $voce = explode("|", $elenco[0]); $str_html = $str_html . "<tr><td><a href=\"" . base_path() . "fedora/repository/" . $voce[0] . "\"><h5>" . $voce[1] . "</h5>"; $str_html = $str_html . "</a></td><td></td></tr>"; $i = 1; while ($i < $nvoci) { $voce = explode("|", $elenco[$i]); $str_html = $str_html . "<tr><td><a href=\"" . base_path() . "fedora/repository/" . $voce[0] . "\">" . $voce[1]; $numpa = substr($voce[0], -4); $str_html = $str_html . "</a></td><td>page " . intval($numpa) . "</td></tr>"; $i++; } $str_html = $str_html . "</tbody></table></div></td></tr></table>"; $strs[0] = $str_html; $colleinfo_html = $objectHelper->getStream($parentcolle, 'INFO'); $strs[1] = $colleinfo_html; return $strs; } ...
<?php // $Id$ ... Tip /** * Grabs a stream from fedora sets the mimetype and returns it. $dsID is the * datastream id. If $forceSoap is set, the function will always buffer the datastream from fedora. Otherwise, it will * try and use a redirect if possible. * * @global type $user * @param type $pid * @param type $dsID * @param type $asAttachment * @param type $label * @param type $filePath * @param type $version * @param type $forceSoap * @return type */ function makeObject($pid, $dsID, $asAttachment = FALSE, $label = NULL, $filePath=FALSE, $version=NULL, $forceSoap = TRUE) { global $user; module_load_include('inc', 'fedora_repository', 'ContentModel'); if ($pid == NULL || $dsID == NULL) { drupal_set_message(t("no pid or dsid given to create an object with"), 'error'); return ' '; } $headers = module_invoke_all('file_download', "/fedora/repository/$pid/$dsID"); if (in_array(-1, $headers)) { drupal_set_message(t('hello')); drupal_access_denied(); return ' '; } if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { drupal_set_message(t("You do not have access Fedora objects within the attempted namespace."), 'error'); drupal_access_denied(); return ' '; } if (variable_get('fedora_object_restrict_datastreams', FALSE) == TRUE) { if (($cm = ContentModel::loadFromObject($pid)) == FALSE) { drupal_set_message(t("You do not have access to objects without an Islandora Content Model."), 'error'); drupal_access_denied(); return ' '; } $cmDatastreams = $cm->listDatastreams(); if (!((isset($user) && in_array('administrator', $user->roles)) || in_array($dsID, $cmDatastreams))) { drupal_set_message(t("You do not have access to the specified datastream."), 'error'); drupal_access_denied(); return ' '; } } module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($pid); if (isset($item->datastreams[$dsID])) { $mimeType = $item->datastreams[$dsID]['MIMEType']; if ($label == NULL) { $label = $item->datastreams[$dsID]['label']; } } else if ($dsID == "openbess:jpgldSdef") { $mimeType = "image/jpeg"; } else { drupal_not_found(); exit(); } if ((!isset($user)) || $user->uid == 0) { $fedoraUser = 'anonymous'; $fedoraPass = 'anonymous'; $contentSize = 0; } else { $fedoraUser = $user->name; $fedoraPass = $user->pass; $dataStreamInfo = $item->get_datastream_info($dsID); $contentSize = $dataStreamInfo->datastream->size; } if (function_exists("curl_init")) { if (!isset($mimeType)) { $pid = variable_get('fedora_default_display_pid', 'demo:10'); $dsID = variable_get('fedora_default_display_dsid', 'TN'); $mimeType = 'image/jpeg'; } if ($dsID == "openbess:jpgldSdef") { $url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/get/' . $pid . '/openbess:jpgldSdef/getJpgLD'; } else { $url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/get/' . $pid . '/' . $dsID; } if ($version) { $url .= '/' . $version; //drupal_urlencode($version); } $ch = curl_init(); $user_agent = "Mozilla/4.0 pp(compatible; MSIE 5.01; Windows NT 5.0)"; curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects //curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, "$fedoraUser:$fedoraPass"); // There seems to be a bug in Fedora 3.1's REST authentication, removing this line fixes the authorization denied error. // curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); // return into a variable curl_setopt($ch, CURLOPT_URL, $url); if ($filePath !== FALSE) { $fp = fopen($filePath, 'w'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); fclose($fp); } else { header("Content-type: $mimeType"); if (($contentSize > 0) && ($dsID != "openbess:jpgldSdef")) { header("Content-length: $contentSize"); } if ($asAttachment) { $suggestedFileName = "$label"; $pos = strpos($suggestedFileName, '.'); /* * Here we used to take an object of, say, type application/pdf with label, say, "My Document" * and we assemble the output filename extension based on the post-slash portion of the mimetype. * (If the label has a period anywhere in it, we leave it alone.) * * This is great for simple mimetypes like application/pdf, text/html, image/jpeg, etc. * but it's terrible for, say, application/vnd.oasis.opendocument.text (.odt). * * Instead we'll use the get_extension function in MimeClass.inc to discover a valid extension * for the mimetype in question. */ if ($pos === FALSE) { module_load_include('inc', 'fedora_repository', 'MimeClass'); $mimeclass = new MimeClass(); $ext = $mimeclass->get_extension($mimeType); $suggestedFileName = "$label.$ext"; } header('Content-Disposition: attachment; filename="' . $suggestedFileName . '"'); } if ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { curl_exec($ch); } else { header('Location: ' . $url); } } curl_close($ch); } else { drupal_set_message(t('No curl support.'), 'error'); } } ...
|