This is an old revision of the document!


Custom Book and Page TABS

  • Edit sites/all/modules/islandora_solution_pack_book/tocnr_book.inc
tocnr_book.inc
<?php
// $Id$
class IslandoraBook
{
    function __construct($pid = '')
    {
        module_load_include('inc', 'fedora_repository', 'api/fedora_item');
        if (!empty($pid)) {
            $this->pid = $pid;
            $this->item = new Fedora_Item($pid);
        }
    }
    public function showFieldSets()
    {
        module_load_include('inc', 'fedora_repository', 'plugins/tagging_form');
        module_load_include('inc', 'fedora_repository', 'plugins/DarwinCore');
        module_load_include('module', 'islandora_book');
        global $base_url;
        $show_purge_tab = (!empty($_POST['form_id']) && ($_POST['form_id'] == 'islandora_book_purge_pages_form'));
        $first_page = new Fedora_Item($this->pid . '-0001');
        $hasPage = $first_page->exists();
        $tabset = array();
        global $user;
        $qs = '';
        if ($user->uid != 0) {
            $qs = '?uid=' . base64_encode($user->name . ':' . $user->pass);
        }
        $viewer_url = variable_get('fedora_base_url', '') . '/get/' . $this->pid . '/islandora:viewerSdef/getViewer' . $qs;
        $html = '<iframe src="' . $viewer_url . '" scrolling="no" frameborder="0" style="width: 100%; height: 802px;">Errors: unable to load viewer</iframe>';
        $pages_selected = FALSE;
        $pagina_selected = FALSE;
        $libro_selected = FALSE;
        if ($hasPage) {
            $libropid = $this->pid;
            $paginapid = $this->pid . '-0001';
            $numeropagina = '0001';
            $libro_selected = TRUE;
        } else {
            $libropid = substr($this->pid, 0, -5);
            $paginapid = $this->pid;
            $numeropagina = substr($this->pid, -4);
            $pagina_selected = TRUE;
        }
        $size = 20;
        $page_number = floor(($numeropagina - 1) / $size) + 1;
        $qstring = $_GET['q'];
        $qparts = explode('/', $qstring);
        $tail = end($qparts);
        if (is_numeric($tail)) {
            $pages_selected = TRUE;
            $pagina_selected = FALSE;
            $libro_selected = FALSE;
            $page_number = $tail;
        }
        $class = new CollectionClass();
        // grow default (1000) risearch limit to 2000  
        $results = $class->getRelatedItems($libropid,NULL,2000);
        $page_items = $class->renderCollection($results, $paginapid, NULL, NULL, $page_number);
        $book_contenuto = islandora_book_create_book_view($libropid);
        $titololibro = substr(strstr(strstr($book_contenuto, "<strong>title</strong></td><td>"), "<strong>creator</strong>", TRUE), 31);
        drupal_set_title("$titololibro");
        $stringhe = islandora_book_create_book_index($libropid);
        $indice_html = $stringhe[0];
        $colleinfo_html = $stringhe[1];
        $tabset['1'] = array(
        // #type and #title are the minimum requirements.
        '#type' => 'tabpage', '#title' => 'BOOK', '#content' => $book_contenuto, '#selected' => $libro_selected, '#weight' => '1',);
        $tabset['2'] = array('#type' => 'tabpage', '#title' => t('Read'), '#content' => $html, '#weight' => '2',);
        $tabset['3'] = array(
        // #type and #title are the minimum requirements.
        '#type' => 'tabpage', '#title' => 'Index',
        //      '#content' => islandora_book_create_book_index($libropid),
        '#content' => $indice_html, '#weight' => '3',);
        $tabset['4'] = array('#type' => 'tabpage', '#title' => t('Pages'), '#selected' => $pages_selected, '#content' => $page_items, '#weight' => '4',);
        $tabset['5'] = array('#type' => 'tabpage', '#title' => 'PAGE ' . substr($paginapid, -4), '#content' => islandora_book_create_book_view($paginapid), '#selected' => $pagina_selected, '#weight' => '5',);
        $tabset['6'] = array('#type' => 'tabpage', '#title' => 'Collection info', '#content' => $colleinfo_html, '#weight' => '6',);
        return $tabset;
    }
}
  • Edit sites/all/modules/islandora_solution_pack_book/xsl/tocnr_book_view.xsl
tocnr_book_view.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:variable name="OBJECTSPAGE">
    <xsl:value-of select="$objectsPage"/>
  </xsl:variable>
  <xsl:variable name="PID">
    <xsl:value-of select="$pid"/>
  </xsl:variable>
  <xsl:variable name="MODELLO">
    <xsl:value-of select="$modello"/>
  </xsl:variable>
  <xsl:variable name="RECORDID">
    <xsl:value-of select="substring-after($PID,&quot;:&quot;)"/>
  </xsl:variable>
  <xsl:variable name="COLLEZIONEID">
    <xsl:value-of select="substring-before($PID,&quot;:&quot;)"/>
  </xsl:variable>
  <xsl:template match="/">
    <table class="libromd" cellpadding="3" cellspacing="2" valign="top">
      <tr>
        <td valign="top">
          <img>
            <xsl:attribute name="src"><xsl:copy-of select="$OBJECTSPAGE"/>fedora/repository/<xsl:copy-of select="$PID"/>/TN
                                </xsl:attribute>
          </img>
        </td>
        <td>
          <div style="align:left">
            <table cellpadding="3" cellspacing="2" width="90%">
              <tbody>
                <tr>
                  <td colspan="3">
                    <h3>Dublin Core - MetaData </h3>
                  </td>
                </tr>
                <xsl:for-each select="/*/*">
                  <xsl:variable name="FULLFIELD" select="name()"/>
                  <xsl:variable name="FIELD" select="substring-after(name(),':')"/>
                  <xsl:variable name="DATA" select="text()"/>
                  <xsl:if test="$DATA != ' '">
                    <tr>
                      <td valign="top">
                        <strong>
                          <xsl:value-of select="substring-after(name(),':')"/>
                        </strong>
                      </td>
                      <td>
                        <xsl:value-of select="text()"/>
                        <xsl:for-each select="*">
                          <div><xsl:value-of select="substring-after(name(),':')"/> =  <xsl:value-of select="text()"/>
                </div>
                        </xsl:for-each>
                      </td>
                    </tr>
                  </xsl:if>                  
                </xsl:for-each>
              </tbody>
              <tr>
                <td colspan="3">
                  <h3/>
                </td>
              </tr>
              <tr>
                <td colspan="3">
                  <h3>Download</h3>
                </td>
              </tr>
              <xsl:if test="$MODELLO = 'info:fedora/islandora:bookCModel'">
                <tr>
                  <td>
                    <strong>Full PDF</strong>
                  </td>
                  <td>
                    <a href="{$OBJECTSPAGE}fedora/repository/object_download/{$PID}/PDF/{$COLLEZIONEID}_{$RECORDID}.pdf">PDF</a>
                  </td>
                </tr>
              </xsl:if>
              <xsl:if test="$MODELLO = 'info:fedora/islandora:pageCModel'">
                <xsl:if test="not($COLLEZIONEID = 'asfiat')">
                  <tr>
                    <td>
                      <strong>Hi-Res IMAGE</strong>
                    </td>
                    <td>
                      <a href="{$OBJECTSPAGE}fedora/repository/object_download/{$PID}/TIFF/{$COLLEZIONEID}_{$RECORDID}.tif">TIFF</a>
                    </td>
                  </tr>
                </xsl:if>
                <xsl:if test="$COLLEZIONEID = 'asfiat'">
                  <tr>
                    <td>
                      <em>Only Low-Res available due to restricted rights</em>
                    </td>
                  </tr>
                </xsl:if>
                <tr>
                  <td>
                    <strong>Low-Res IMAGE</strong>
                  </td>
                  <td>
                    <a href="{$OBJECTSPAGE}fedora/repository/object_download/{$PID}/openbess:jpgldSdef/{$COLLEZIONEID}_{$RECORDID}.jpg">JPEG</a>
                  </td>
                </tr>
                <tr>
                  <td>
                    <strong>TEXT</strong>
                  </td>
                  <td>
                    <a href="{$OBJECTSPAGE}fedora/repository/object_download/{$PID}/OCR/{$COLLEZIONEID}_{$RECORDID}.txt">TXT</a>
                  </td>
                </tr>
              </xsl:if>
            </table>
          </div>
        </td>
      </tr>
    </table>
  </xsl:template>
</xsl:stylesheet>
  • Edit sites/all/modules/islandora_solution_pack_book/islandora_book.module
<?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;
}
...
  • Edit sites/all/modules/islandora-github/ObjectHelper.inc to allow object_download of dissemination methods
<?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');
    }
  }
...
 
 
frontend/bookpagetabs.1375862990.txt.gz · Last modified: 2013/08/07 10:09 by giancarlo

Developers: CNR IRCrES IT Office and Library
Giancarlo Birello (giancarlo.birello _@_ ircres.cnr.it) and Anna Perin (anna.perin _@_ ircres.cnr.it)
DigiBess is licensed under: Creative Commons License
Recent changes RSS feed Creative Commons License Valid XHTML 1.0 Valid CSS Driven by DokuWiki
Drupal Garland Theme for Dokuwiki