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>
                      <!--
	<td><a href="{$baseUrl}/search/fedora_repository/dc.{$FIELD}:{$DATA}"><img title="Find Similar by {$FIELD}" src="{$PATH}/images/view.gif" alt="Find Similar by {$FIELD}" /></a></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="http://fc1.to.cnr.it:8080/fedora/objects/{$PID}/datastreams/PDF/content">PDF</a></td> -->
                  <td>
                    <a href="{$OBJECTSPAGE}fedora/repository/{$PID}/PDF/{$COLLEZIONEID}_{$RECORDID}.pdf">PDF</a>
                  </td>
                </tr>
              </xsl:if>
              <xsl:if test="$MODELLO = 'info:fedora/islandora:pageCModel'">
                <tr>
                  <td>
                    <strong>HD TIFF</strong>
                  </td>
                  <td>
                    <a href="{$OBJECTSPAGE}fedora/repository/{$PID}/TIFF/{$COLLEZIONEID}_{$RECORDID}.tif">TIFF</a>
                  </td>
                </tr>
                <tr>
                  <td>
                    <strong>TEXT</strong>
                  </td>
                  <td>
                    <a href="{$OBJECTSPAGE}fedora/repository/{$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;
}
...
 
 
frontend/bookpagetabs.txt ยท Last modified: 2012/07/13 12:36 by giancarlo

Developers: CNR IRCrES IT Office and Library
Giancarlo Birello (giancarlo.birello _@_ ircres.cnr.it) and Anna Perin (anna.perin _@_ ircres.cnr.it)
ASA@TO.CNR 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