Commit 51ee23cf authored by Son Nguyen's avatar Son Nguyen Committed by Gerrit Code Review
Browse files

Merge changes Ibc87e7ae,If5665396

* changes:
  Allow the pdf viewer to display menu items in user's lang (Bug 1423435)
  Allowing the pdf block file upload field to filter by pdf
parents b6957fba fafc48fb
......@@ -104,6 +104,7 @@ class PluginBlocktypeImage extends PluginBlocktype {
$element = ArtefactTypeFileBase::blockconfig_filebrowser_element($instance, $default);
$element['title'] = get_string('image');
$element['name'] = 'artefactid';
$element['accept'] = 'image/*';
$element['config']['selectone'] = true;
$element['filters'] = array(
'artefacttype' => array('image', 'profileicon'),
......
......@@ -6236,7 +6236,7 @@ function webViewerInitialized() {
document.getElementById('fileInput').value = null;
}
var locale = PDFJS.locale || navigator.language;
var locale = params.lang || PDFJS.locale || navigator.language;
if (PDFViewerApplication.preferencePdfBugEnabled) {
// Special debugging flags in the hash section of the URL.
......
......@@ -30,6 +30,7 @@ class PluginBlocktypePdf extends PluginBlocktype {
}
public static function render_instance(BlockInstance $instance, $editing=false) {
global $USER;
require_once(get_config('docroot') . 'lib/view.php');
$configdata = $instance->get('configdata'); // this will make sure to unserialize it for us
$configdata['viewid'] = $instance->get('view');
......@@ -55,8 +56,21 @@ class PluginBlocktypePdf extends PluginBlocktype {
$urlbase = profile_url($viewauthor) . '/';
}
}
$result = '<iframe src="' . $urlbase . 'artefact/file/blocktype/pdf/viewer.php?editing=' . $editing . '&ingroup=' . !empty($group) . '&file=' . $artefactid . '&view=' . $instance->get('view')
// Send the current language to the pdf viewer
$language = current_language();
$language = str_replace('_', '-', substr($language, 0, ((substr_count($language, '_') > 0) ? 5 : 2)));
if ($language != 'en' && !file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) {
// In case the language file exists as a string with both lower and upper case, eg fr_FR we test for this
$language = substr($language, 0, 2) . '-' . strtoupper(substr($language, 0, 2));
if (!file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) {
// In case we fail to find a language of 5 chars, eg pt_BR (Portugese, Brazil) we try the 'parent' pt (Portugese)
$language = substr($language, 0, 2);
if ($language != 'en' && !file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) {
$language = 'en-GB';
}
}
}
$result = '<iframe src="' . $urlbase . 'artefact/file/blocktype/pdf/viewer.php?editing=' . $editing . '&ingroup=' . !empty($group) . '&file=' . $artefactid . '&lang=' . $language . '&view=' . $instance->get('view')
. '" width="100%" height="500" frameborder="0"></iframe>';
require_once(get_config('docroot') . 'artefact/comment/lib.php');
......@@ -98,6 +112,7 @@ class PluginBlocktypePdf extends PluginBlocktype {
$element = ArtefactTypeFileBase::blockconfig_filebrowser_element($instance, $default);
$element['title'] = get_string('file', 'artefact.file');
$element['name'] = 'artefactid';
$element['accept'] = 'application/pdf';
$element['config']['selectone'] = true;
$element['filters'] = array(
'artefacttype' => array('file'),
......
......@@ -152,6 +152,8 @@ function pieform_element_filebrowser(Pieform $form, $element) {
$fileliststr = json_encode($filedata);
$smarty->assign('prefix', $prefix);
$accepts = isset($element['accept']) ? 'accept="' . Pieform::hsc($element['accept']) . '"' : '';
$smarty->assign('accepts', $accepts);
$initjs = "{$prefix} = new FileBrowser('{$prefix}', {$folder}, {$configstr}, config);
{$prefix}.filedata = {$fileliststr};";
......
......@@ -18,7 +18,6 @@
document.body.className = 'js';
document.body.style.display = 'block';
document.getElementById('nojsdownload').style.display = 'none';
document.getElementById('outerContainer').className = 'loadingInProgress';
}
</script>
......@@ -31,9 +30,9 @@
</head>
<body class="no-js">
<body class="no-js loadingInProgress" tabindex="1">
<div id="nojsdownload" class="no-js"><a href="{$url|safe}&download=1">{$title}</a></div>
<div id="outerContainer" class="loadingInProgress js">
<div id="outerContainer">
<div id="sidebarContainer">
<div id="toolbarSidebar">
......@@ -204,14 +203,14 @@
<option id="pageFitOption" title="" value="page-fit" data-l10n-id="page_scale_fit">Fit Page</option>
<option id="pageWidthOption" title="" value="page-width" data-l10n-id="page_scale_width">Full Width</option>
<option id="customScaleOption" title="" value="custom"></option>
<option title="" value="0.5">50%</option>
<option title="" value="0.75">75%</option>
<option title="" value="1">100%</option>
<option title="" value="1.25">125%</option>
<option title="" value="1.5">150%</option>
<option title="" value="2">200%</option>
<option title="" value="3">300%</option>
<option title="" value="4">400%</option>
<option title="" value="0.5" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 50 }'>50%</option>
<option title="" value="0.75" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 75 }'>75%</option>
<option title="" value="1" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 100 }'>100%</option>
<option title="" value="1.25" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 125 }'>125%</option>
<option title="" value="1.5" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 150 }'>150%</option>
<option title="" value="2" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 200 }'>200%</option>
<option title="" value="3" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 300 }'>300%</option>
<option title="" value="4" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 400 }'>400%</option>
</select>
</span>
</div>
......
......@@ -54,7 +54,7 @@
{$licenseform|safe}
<div class="uploadform">
<label for="{$prefix}_userfile">{if $config.simpleupload}{str tag='uploadfile' section='artefact.file'}{else}{str tag='File' section='artefact.file'}{/if}</label>
<span id="{$prefix}_userfile_container"><input type="file" class="file" id="{$prefix}_userfile" name="userfile[]" multiple size="20" /></span>
<span id="{$prefix}_userfile_container"><input type="file" class="file" {$accepts|safe} id="{$prefix}_userfile" name="userfile[]" multiple size="20" /></span>
<span id="{$prefix}_userfile_maxuploadsize">({str tag=maxuploadsize section=artefact.file} {$maxuploadsize})</span>
{if $config.uploadagreement}<script>setNodeAttribute('{$prefix}_userfile', 'disabled', true);</script>{/if}
</div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment