Example #1
0
 /**
  * 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);
     }
 }
Example #2
0
 /**
  * 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);
     }
 }
Example #3
0
    <?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 
 /**
  * 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);
     }
 }