/** * Handle AJAX requests to fill transcription of an item from source * element. */ public function fillPagesAction() { if (!$this->_checkAjax('fill-pages')) { return; } // Handle action. try { $id = (int) $this->_getParam('id'); $scripto = ScriptoPlugin::getScripto(); if (!$scripto->documentExists($id)) { $this->getResponse()->setHttpResponseCode(400); return; } // Get some variables. list($elementSetName, $elementName) = explode(':', get_option('scripto_source_element')); $type = get_option('scripto_import_type'); $doc = $scripto->getDocument($id); // Check all pages, created or not. foreach ($doc->getPages() as $pageId => $pageName) { // If the page doesn't exist, it is created automatically with // text from source element. $doc->setPage($pageId); // Else, edit the transcription if the page is already created. if ($doc->isCreatedPage()) { $file = get_record_by_id('File', $pageId); $transcription = $file->getElementTexts($elementSetName, $elementName); $transcription = empty($transcription) ? '' : $transcription[0]->text; $flagProtect = $doc->isProtectedTranscriptionPage(); if ($flagProtect) { $doc->unprotectTranscriptionPage(); } $doc->editTranscriptionPage($transcription); // Automatic update of metadata. $doc->setPageTranscriptionStatus(); $doc->setDocumentTranscriptionProgress(); $doc->setItemSortWeight(); $doc->exportPage($type); if ($flagProtect) { $doc->protectTranscriptionPage(); } } } $this->getResponse()->setBody('success'); } catch (Exception $e) { $this->getResponse()->setHttpResponseCode(500); } }
/** * Handle AJAX requests from the transcribe action. * * 400 Bad Request * 403 Forbidden * 500 Internal Server Error */ public function pageActionAction() { // Don't render the view script. $this->_helper->viewRenderer->setNoRender(true); // Only allow AJAX requests. if (!$this->getRequest()->isXmlHttpRequest()) { $this->getResponse()->setHttpResponseCode(403); return; } // Allow only valid pages. $pages = array('transcription', 'talk'); if (!in_array($this->_getParam('page'), $pages)) { $this->getResponse()->setHttpResponseCode(400); return; } // Only allow valid page actions. $pageActions = array('edit', 'watch', 'unwatch', 'protect', 'unprotect', 'import-page', 'import-document'); if (!in_array($this->_getParam('page_action'), $pageActions)) { $this->getResponse()->setHttpResponseCode(400); return; } // Handle the page action. try { $scripto = ScriptoPlugin::getScripto(); $doc = $scripto->getDocument($this->_getParam('item_id')); $doc->setPage($this->_getParam('file_id')); $body = null; switch ($this->_getParam('page_action')) { case 'edit': $text = $this->_getParam('wikitext'); // Because creating new, empty pages is not allowed by // MediaWiki, a check is done. if ('talk' == $this->_getParam('page')) { if (!$doc->isProtectedTalkPage()) { if (trim($text) != '' || $doc->isCreatedTalkPage()) { $doc->editTalkPage($text); } } $body = $doc->getTalkPageHtml(); } else { $type = get_option('scripto_import_type'); if (!$doc->isProtectedTranscriptionPage()) { if (trim($text) != '' || $doc->isCreatedPage()) { $doc->editTranscriptionPage($text); $body = $doc->getTranscriptionPage($type); // Automatic update of metadata. $doc->setPageTranscriptionStatus(); $doc->setDocumentTranscriptionProgress(); $doc->setItemSortWeight(); $doc->exportPage($type); } } if (is_null($body)) { $body = $doc->getTranscriptionPage($type); } } break; case 'watch': $doc->watchPage(); break; case 'unwatch': $doc->unwatchPage(); break; case 'protect': // Protect page uses current edit text, even if edit button // was not pressed. $text = $this->_getParam('wikitext'); if ('talk' == $this->_getParam('page')) { // Because creating new, empty pages is not allowed by // MediaWiki, a check is done. if (trim($text) != '' || $doc->isCreatedTalkPage()) { $doc->editTalkPage($text); } $body = $doc->getTalkPageHtml(); // Set protection. $doc->protectTalkPage(); } else { $type = get_option('scripto_import_type'); // Because creating new, empty pages is not allowed by // MediaWiki, a check is done. if (trim($text) != '' || $doc->isCreatedPage()) { $doc->editTranscriptionPage($text); } $body = $doc->getTranscriptionPage($type); $doc->protectTranscriptionPage(); // Automatic update of metadata. $doc->setPageTranscriptionStatus(); $doc->setDocumentTranscriptionProgress(); $doc->setItemSortWeight(); $doc->exportPage($type); } break; case 'unprotect': if ('talk' == $this->_getParam('page')) { $doc->unprotectTalkPage(); } else { $doc->unprotectTranscriptionPage(); $doc->setPageTranscriptionStatus(); $doc->setDocumentTranscriptionProgress(); $doc->setItemSortWeight(); } break; case 'import-page': $doc->exportPage(get_option('scripto_import_type')); break; case 'import-document': $doc->export(get_option('scripto_import_type')); break; default: $this->getResponse()->setHttpResponseCode(400); return; } $this->getResponse()->setBody($body); } catch (Scripto_Exception $e) { $this->getResponse()->setHttpResponseCode(500); } }
</thead> <tbody> <?php foreach ($this->documentPages as $documentPage) { ?> <?php // document page name $documentPageName = ScriptoPlugin::truncate($documentPage['document_page_name'], 60); $urlTranscribe = url(array('action' => 'transcribe', 'item-id' => $documentPage['document_id'], 'file-id' => $documentPage['document_page_id']), 'scripto_action_item_file'); if (1 == $documentPage['namespace_index']) { $urlTranscribe .= '#discussion'; } else { $urlTranscribe .= '#transcription'; } // document title $documentTitle = ScriptoPlugin::truncate($documentPage['document_title'], 60, __('Untitled')); $urlItem = url(array('controller' => 'items', 'action' => 'show', 'id' => $documentPage['document_id']), 'id'); ?> <tr> <td><a href="<?php echo html_escape($urlTranscribe); ?> "><?php if (1 == $documentPage['namespace_index']) { echo __('Talk'); ?> : <?php } echo $documentPageName; ?> </a></td>
?> <?php // changes $changes = __($revision['action']); $urlHistory = url(array('item-id' => $revision['document_id'], 'file-id' => $revision['document_page_id'], 'namespace-index' => $revision['namespace_index']), 'scripto_history'); $changes .= ' (<a href="' . html_escape($urlHistory) . '">' . __('hist') . '</a>)'; // document page name $documentPageName = ScriptoPlugin::truncate($revision['document_page_name'], 30); $urlTranscribe = url(array('action' => 'transcribe', 'item-id' => $revision['document_id'], 'file-id' => $revision['document_page_id']), 'scripto_action_item_file'); if (1 == $revision['namespace_index']) { $urlTranscribe .= '#discussion'; } else { $urlTranscribe .= '#transcription'; } // document title $documentTitle = ScriptoPlugin::truncate($revision['document_title'], 30, __('Untitled')); $urlItem = url(array('controller' => 'items', 'action' => 'show', 'id' => $revision['document_id']), 'id'); // length changed $lengthChanged = $revision['new_length'] - $revision['old_length']; if (0 <= $lengthChanged) { $lengthChanged = "+{$lengthChanged}"; } ?> <tr> <td><?php echo $changes; ?> </td> <td><a href="<?php echo html_escape($urlTranscribe); ?>
<?php // jQuery is enabled by default in Omeka and in most themes. // queue_js_url('https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'); // queue_js_url('https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js'); queue_js_file(array('jquery.bxSlider.min')); echo head_js(); ?> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"> <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> </head> <?php echo body_tag(array('id' => @$bodyid, 'class' => @$bodyclass)); require_once getcwd() . '/plugins/Scripto/libraries/Scripto.php'; $scripto = ScriptoPlugin::getScripto(); ?> <nav class="navbar navbar-default"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="<?php echo WEB_ROOT; ?> /collections/show/1"><img src="<?php
$urlHistory = url(array('item-id' => $recentChange['document_id'], 'file-id' => $recentChange['document_page_id'], 'namespace-index' => $recentChange['namespace_index']), 'scripto_history'); if ($recentChange['new'] || in_array($recentChange['action'], array('protected', 'unprotected'))) { $changes .= ' (' . __('diff') . ' | <a href="' . html_escape($urlHistory) . '">' . __('hist') . '</a>)'; } else { $changes .= ' (<a href="' . html_escape($urlDiff) . '">' . __('diff') . '</a> | <a href="' . html_escape($urlHistory) . '">' . __('hist') . '</a>)'; } // document page name $documentPageName = ScriptoPlugin::truncate($recentChange['document_page_name'], 30); $urlTranscribe = url(array('action' => 'transcribe', 'item-id' => $recentChange['document_id'], 'file-id' => $recentChange['document_page_id']), 'scripto_action_item_file'); if (1 == $recentChange['namespace_index']) { $urlTranscribe .= '#discussion'; } else { $urlTranscribe .= '#transcription'; } // document title $documentTitle = ScriptoPlugin::truncate($recentChange['document_title'], 30, __('Untitled')); $urlItem = url(array('controller' => 'items', 'action' => 'show', 'id' => $recentChange['document_id']), 'id'); // length changed $lengthChanged = $recentChange['new_length'] - $recentChange['old_length']; if (0 <= $lengthChanged) { $lengthChanged = "+{$lengthChanged}"; } ?> <tr> <td><?php echo $changes; ?> </td> <td><a href="<?php echo html_escape($urlTranscribe); ?>
/** * add_file_display_callback() callback for OpenLayers. * * @see Scripto_IndexController::init() * @param File $file */ public static function openLayers($file) { // Check size via local path to avoid to use the server. $imagePath = realpath(FILES_DIR . DIRECTORY_SEPARATOR . get_option('scripto_file_source_path') . DIRECTORY_SEPARATOR . $file->filename); $imageSize = ScriptoPlugin::getImageSize($imagePath, 250); // Image to send. $imageUrl = $file->getWebPath(get_option('scripto_file_source')); ?> <script type="text/javascript"> jQuery(document).ready(function() { var scriptoMap = new OpenLayers.Map('scripto-openlayers', { controls: [ new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoom(), new OpenLayers.Control.KeyboardDefaults() ] }); var graphic = new OpenLayers.Layer.Image( 'Document Page', <?php echo js_escape($imageUrl); ?> , new OpenLayers.Bounds(-<?php echo $imageSize['width']; ?> , -<?php echo $imageSize['height']; ?> , <?php echo $imageSize['width']; ?> , <?php echo $imageSize['height']; ?> ), new OpenLayers.Size(<?php echo $imageSize['width']; ?> , <?php echo $imageSize['height']; ?> ) ); scriptoMap.addLayers([graphic]); scriptoMap.zoomToMaxExtent(); }); </script> <div id="scripto-openlayers" class="<?php echo get_option('scripto_viewer_class'); ?> "></div> <?php }
/** * add_file_display_callback() callback for OpenLayers. * * @see Scripto_IndexController::init() * @param File $file */ public static function openLayers($file) { // Check size via local path to avoid to use the server. $imagePath = realpath(FILES_DIR . DIRECTORY_SEPARATOR . get_option('scripto_file_source_path') . DIRECTORY_SEPARATOR . $file->filename); $imageSize = ScriptoPlugin::getImageSize($imagePath); // Image to send. $imageUrl = $file->getWebPath(get_option('scripto_file_source')); ?> <div id="map" class="map"></div> <script type="text/javascript"> var target = 'map'; var imgWidth = <?php echo $imageSize['width']; ?> ; var imgHeight = <?php echo $imageSize['height']; ?> ; var url = <?php echo json_encode($imageUrl); ?> ; // The zoom is set to extent after map initialization. var zoom = 2; var extent = [0, 0, imgWidth, imgHeight]; var source = new ol.source.ImageStatic({ url: url, projection: projection, imageExtent: extent }); // Map views always need a projection. Here we just want to map image // coordinates directly to map coordinates, so we create a projection that uses // the image extent in pixels. var projection = new ol.proj.Projection({ code: 'pixel', units: 'pixels', extent: extent }); var map = new ol.Map({ layers: [ new ol.layer.Image({ source: source }) ], logo: false, controls: ol.control.defaults({attribution: false}).extend([ new ol.control.FullScreen() ]), interactions: ol.interaction.defaults().extend([ new ol.interaction.DragRotateAndZoom() ]), target: target, view: new ol.View({ projection: projection, center: ol.extent.getCenter(extent), zoom: zoom }) }); // Initialize zoom to extent. map.getView().fit(extent, map.getSize()); </script> <?php }
/** * Handle AJAX requests from the transcribe action. * * 403 Forbidden * 400 Bad Request * 500 Internal Server Error */ public function pageActionAction() { // Don't render the view script. $this->_helper->viewRenderer->setNoRender(true); // Only allow AJAX requests. if (!$this->getRequest()->isXmlHttpRequest()) { $this->getResponse()->setHttpResponseCode(403); return; } // Allow only valid pages. $pages = array('transcription', 'talk'); if (!in_array($this->_getParam('page'), $pages)) { $this->getResponse()->setHttpResponseCode(400); return; } // Only allow valid page actions. $pageActions = array('edit', 'watch', 'unwatch', 'protect', 'unprotect', 'import-page', 'import-document'); if (!in_array($this->_getParam('page_action'), $pageActions)) { $this->getResponse()->setHttpResponseCode(400); return; } // Handle the page action. try { $scripto = ScriptoPlugin::getScripto(); $doc = $scripto->getDocument($this->_getParam('item_id')); $doc->setPage($this->_getParam('file_id')); $body = null; switch ($this->_getParam('page_action')) { case 'edit': if ('talk' == $this->_getParam('page')) { $doc->editTalkPage($this->_getParam('wikitext')); $body = $doc->getTalkPageHtml(); } else { $doc->editTranscriptionPage($this->_getParam('wikitext')); $body = $doc->getTranscriptionPageHtml(); } break; case 'watch': $doc->watchPage(); break; case 'unwatch': $doc->unwatchPage(); break; case 'protect': if ('talk' == $this->_getParam('page')) { $doc->protectTalkPage(); } else { $doc->protectTranscriptionPage(); } break; case 'unprotect': if ('talk' == $this->_getParam('page')) { $doc->unprotectTalkPage(); } else { $doc->unprotectTranscriptionPage(); } break; case 'import-page': $doc->exportPage(get_option('scripto_import_type')); break; case 'import-document': $doc->export(get_option('scripto_import_type')); break; default: $this->getResponse()->setHttpResponseCode(400); return; } $this->getResponse()->setBody($body); } catch (Scripto_Exception $e) { $this->getResponse()->setHttpResponseCode(500); } }
/** * add_file_display_callback() callback for OpenLayers. * * @see Scripto_IndexController::init() * @param File $file */ public static function openLayers($file) { $imageUrl = $file->getWebPath('original'); $imageSize = ScriptoPlugin::getImageSize($imageUrl, 250); ?> <script type="text/javascript"> jQuery(document).ready(function() { var scriptoMap = new OpenLayers.Map('scripto-openlayers'); var graphic = new OpenLayers.Layer.Image( 'Document Page', <?php echo js_escape($imageUrl); ?> , new OpenLayers.Bounds(-<?php echo $imageSize['width']; ?> , -<?php echo $imageSize['height']; ?> , <?php echo $imageSize['width']; ?> , <?php echo $imageSize['height']; ?> ), new OpenLayers.Size(<?php echo $imageSize['width']; ?> , <?php echo $imageSize['height']; ?> ) ); scriptoMap.addLayers([graphic]); scriptoMap.zoomToMaxExtent(); }); </script> <div id="scripto-openlayers" style="height: 400px; border: 1px grey solid; margin-bottom: 12px;"></div> <?php }