# repository connection parameters $url = 'localhost:8080/fedora'; $username = '******'; $password = '******'; # set up connection and repository variables $connection = new RepositoryConnection($url, $username, $password); $repository = new FedoraRepository(new FedoraApi($connection), new SimpleCache()); $root_pid = drush_shift(); $parent_obj = $repository->getObject($root_pid); $itql = 'select $page_itql from <#ri> where $page_itql <fedora-rels-ext:isMemberOf> <info:fedora/' . $root_pid . '> order by $page_itql'; $page_objects = $repository->ri->itqlQuery($itql, 'unlimited', '0'); foreach ($page_objects as $page) { $page_pid = $page['page_itql']['value']; $object = islandora_object_load($page_pid); if (!$object->getDataStream('JP2')) { echo "regenerating OBJ for {$page_pid}\n"; $obj_ds = $object['OBJ']; //url of image... http://fedora_repo_url:8080/objects/[pid]/datastreams/OBJ/content $file_url = $repo_url . '/objects/' . $page_pid . '/datastreams/OBJ/content'; $drupal_result = drupal_http_request($file_url); if (!empty($drupal_result->data)) { //create a temporary file $new_file = file_save_data($drupal_result->data, file_default_scheme() . '://'); $path = drupal_realpath($new_file->uri); //replace file... $obj_ds->setContentFromFile($path); //delete temporary file file_delete($new_file); echo "regenerating OBJ for {$page_pid} completed\n";
/** * Implements hook_CMODEL_PID_islandora_solr_object_result_alter(). * * Replaces the url for the search result to be the book's url, not the page. * The page is added as a fragment at the end of the book url. */ function barnard_theme_islandora_pageCModel_islandora_solr_object_result_alter(&$search_results, $query_processor) { // Grab the names of the appropriate solr fields from the db. $parent_book_field_name = variable_get('islandora_book_parent_book_solr_field', 'RELS_EXT_isMemberOf_uri_ms'); $page_number_field_name = variable_get('islandora_paged_content_page_number_solr_field', 'RELS_EXT_isSequenceNumber_literal_ms'); // If: // there's an object url AND // there's a solr doc AND // the solr doc contains the parent book AND // the solr doc contains the page number... if (isset($search_results['object_url']) && isset($search_results['solr_doc']) && isset($search_results['solr_doc'][$parent_book_field_name]) && count($search_results['solr_doc'][$parent_book_field_name]) && isset($search_results['solr_doc'][$page_number_field_name]) && count($search_results['solr_doc'][$page_number_field_name])) { // Replace the result url with that of the parent book and add the page // number as a fragment. $book_pid = preg_replace('/info\\:fedora\\//', '', $search_results['solr_doc'][$parent_book_field_name][0], 1); $page_number = $search_results['solr_doc'][$page_number_field_name][0]; if (islandora_object_access(ISLANDORA_VIEW_OBJECTS, islandora_object_load($book_pid))) { $search_results['object_url'] = "islandora/object/{$book_pid}"; $view_types = array("1" => "1up", "2" => "2up", "3" => "thumb"); $ia_view = variable_get('islandora_internet_archive_bookreader_default_page_view', "1"); $search_results['object_url_fragment'] = "page/{$page_number}/mode/{$view_types[$ia_view]}"; $field_match = array('catch_all_fields_mt', 'OCR_t', 'text_nodes_HOCR_hlt'); $field_term = ''; $fields = preg_split('/OR|AND|NOT/', $query_processor->solrQuery); foreach ($fields as $field) { if (preg_match('/^(.*):\\((.*)\\)/', $field, $matches)) { if (isset($matches[1]) && in_array($matches[1], $field_match)) { $field_term = isset($matches[2]) && $matches[2] ? $matches[2] : ''; break; } } } if ($field_term) { $search_term = trim($field_term); } elseif ($query_processor->solrDefType == 'dismax' || $query_processor->solrDefType == 'edismax') { $search_term = trim($query_processor->solrQuery); } if (!empty($search_term)) { $search_results['object_url_fragment'] .= "/search/" . rawurlencode($search_term); } } } }
/** * Theme the page selector. */ function UofM_2_islandora_newspaper_page_select(array $variables) { module_load_include('inc', 'islandora_custom_solr', 'includes/newspaper'); $path = drupal_get_path('module', 'islandora_newspaper'); drupal_add_js($path . '/js/islandora_newspaper.js'); $object = $variables['object']; $results = $object->relationships->get(ISLANDORA_RELS_EXT_URI, 'isPageOf'); $result = reset($results); $parent = $result ? islandora_object_load($result['object']['value']) : FALSE; $pages = $parent ? islandora_custom_solr_newspaper_get_pages($parent) : FALSE; if (!$pages) { return; } $variables = array('#options' => array(), '#attributes' => array('class' => array('page-select')), '#value' => $object->id); foreach ($pages as $pid => $page) { $variables['#options'][$pid] = $page['page']; } $prefix = '<strong>' . t('Page') . ':</strong> '; return $prefix . t('!page_selector of @total', array('!page_selector' => theme('select', array('element' => $variables)), '@total' => count($pages))); }