Commit ca95adda authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge changes Ieea9522a,I0fd69b28

* changes:
  Bug 1907019: Fix adding licence via zipfile
  Bug 1890357: Update Google Fonts installation information
parents be6ed201 cc89e680
......@@ -34,7 +34,7 @@ $form = pieform(array(
'fontinstructions' => array(
'type' => 'html',
'title' => '',
'value' => get_string('installfontinstructions', 'skin'),
'value' => get_string('installfontinstructions1', 'skin'),
),
'fonttitle' => array(
'type' => 'text',
......@@ -266,6 +266,9 @@ function addfontform_submit(Pieform $form, $values) {
}
}
}
if (isset($values['fontfileTXT']['name'])) {
$values['fontfilelicence']['name'] = $values['fontfileTXT']['name'];
}
}
}
......@@ -323,7 +326,7 @@ function addfontform_submit(Pieform $form, $values) {
(object) array(
'name' => $foldername,
'title' => $values['fonttitle'],
'licence' => $values['fontfilelicence']['name'],
'licence' => ($values['fontfilelicence']['name'] ? $values['fontfilelicence']['name'] : ''),
'notice' => $values['fontnotice'],
'previewfont' => $values['fontfileTTF']['name'],
'variants' => serialize(array($font_variant => $variantdata)),
......
<?php
/**
*
* @package mahara
* @subpackage skin
* @author Gregor Anzelj
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
* @copyright (C) 2010-2013 Gregor Anzelj <gregor.anzelj@gmail.com>
*
*/
// TODO: The *only* reason we require the admin to upload a Google Fonts archive, is so we can use
// it to generate the skin preview images. For actually displaying pages that use the skins, we do
// not need to download anything. So, if we could figure out a way to generate those skin previews
// without requiring the download, that'd be great.
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configsite/sitefonts');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'installgwf');
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once(get_config('libroot') . 'skin.php');
define('TITLE', get_string('installgwfont', 'skin'));
if (!get_config('skins')) {
throw new FeatureNotEnabledException();
}
$form = pieform(array(
'name' => 'gwfontform',
//'jsform' => true,
'plugintype' => 'artefact',
'pluginname' => 'skin',
'elements' => array(
'gwfinstructions' => array(
'type' => 'markup',
'value' => get_string('gwfinstructions', 'skin'),
),
'gwfzipfile' => array(
'type' => 'file',
'labelhtml' => get_string('gwfzipfile', 'skin'),
'description' => get_string('gwfzipdescription', 'skin'),
'rules' => array('required' => true),
),
'submit' => array(
'type' => 'submitcancel',
'subclass'=> array('btn-primary'),
'value' => array(get_string('installgwfont', 'skin'), get_string('cancel', 'mahara')),
'goto' => get_config('wwwroot') . 'admin/site/fonts.php',
),
),
));
$smarty = smarty(array('tablerenderer'));
setpageicon($smarty, 'icon-text-width');
$smarty->assign('form', $form);
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->display('form.tpl');
function gwfontform_validate(Pieform $form, $values) {
global $USER, $SESSION;
require_once('file.php');
require_once('uploadmanager.php');
$valid = false;
if ($values['gwfzipfile'] <> null) {
$filetype = $values['gwfzipfile']['type'];
// Ensures that the correct file was chosen
$accepted = array('application/zip',
'application/x-zip-compressed',
'multipart/x-zip',
'application/s-compressed');
foreach($accepted as $mimetype) {
if ($mimetype == $filetype) {
$valid = true;
break;
}
}
// Safari and Chrome don't register zip mime types. Something better could be used here.
// Check if file extension, that is the last 4 characters in file name, equals '.zip'...
$valid = substr($values['gwfzipfile']['name'], -4) == '.zip' ? true : false;
if (!$valid) {
$form->set_error('gwfzipfile', get_string('notvalidzipfile', 'skin'));
}
// pass it through the virus checker
$um = new upload_manager('gwfzipfile');
if ($error = $um->preprocess_file()) {
$form->set_error($inputname, $error);
}
}
}
function gwfontform_submit(Pieform $form, $values) {
global $USER, $SESSION;
require_once('file.php');
require_once('uploadmanager.php');
$fontpath = get_config('dataroot') . 'skins/fonts/';
check_dir_exists($fontpath, true, true);
$currentfont = null;
$licence = null;
$previewfont = null;
$variants = array();
$variants['regular'] = array(
"variant" => "regular",
"font-weight" => "normal",
"font-style" => "normal"
);
$zip = new ZipArchive();
if ($zip->open($values['gwfzipfile']['tmp_name'])) {
$currentfont = dirname($zip->getNameIndex(0));
for ($i = 0; $i < $zip->numFiles; $i++) {
$extractfiles = array();
$fontname = dirname($zip->getNameIndex($i));
$filename = basename($zip->getNameIndex($i));
$makefolder = false;
if (empty($fontname) || $fontname == '.') {
$fontname = substr($values['gwfzipfile']['name'], 0, -1 * strlen('.zip'));
$makefolder = true;
}
// Find correct licence file...
if (substr($zip->getNameIndex($i), -3) == 'txt') {
$licence = $filename;
$extractfiles[] = $zip->getNameIndex($i);
}
// Find correct TTF font file for generating skin previews...
$possiblenames = array(
str_replace("_", "", $fontname) . ".ttf",
str_replace("_", "", $fontname) . "-Regular.ttf",
str_replace("_", "", $fontname) . "-Normal.ttf",
);
if (in_array($filename, $possiblenames)) {
$previewfont = $filename;
$extractfiles[] = $zip->getNameIndex($i);
}
// Reset settings for each new font...
if (!is_null($licence) && !is_null($previewfont)) {
$foldername = preg_replace(Skin::FONTNAME_FILTER_CHARACTERS, '', $fontname);
// Assign a new name, if the font with the same name already exists...
$foldername = Skin::new_font_name($foldername);
if ($makefolder == true) {
$fontpath .= $foldername . '/';
check_dir_exists($fontpath, true, true);
}
$installfont = array(
"name" => $foldername,
"title" => str_replace("_", " ", $fontname),
"licence" => $licence,
"notice" => "", // null ???
"previewfont" => $previewfont,
"variants" => serialize($variants),
"fonttype" => "google",
"onlyheading" => 0,
"fontstack" => "'" . escape_css_string(str_replace("_", " ", $fontname)) . "'",
"genericfont" => "sans-serif",
);
// Install fonts (write data into database). Check if the record doesn't exist!!!
ensure_record_exists('skin_fonts',
(object) array('name' => $installfont['name']),
(object) $installfont
);
// Extract installed fonts
foreach ($extractfiles as $extractfile) {
$fullfontpath = $fontpath . $foldername . '/';
check_dir_exists($fullfontpath, true, true);
copy("zip://" . $values['gwfzipfile']['tmp_name'] . "#" . $extractfile, $fullfontpath . $previewfont);
}
$currentfont = $fontname;
$licence = null;
$previewfont = null;
}
}
$SESSION->add_ok_msg(get_string('gwfontadded', 'skin'));
}
else {
$SESSION->add_error_msg(get_string('archivereadingerror', 'skin'));
}
redirect('/admin/site/fonts.php');
}
......@@ -33,12 +33,19 @@ if (!empty($font)) {
$fonttitle = $fontdata->title;
if (!empty($fontdata->licence) && !is_null($fontdata->licence)) {
if (preg_match('/^t_(.*)/', $fontdata->fonttype, $matches)) {
$fontpath = get_config('wwwroot') . 'theme/' . $matches[1] . '/fonts/' . strtolower($fontdata->name) . '/';
$fontpath = 'theme/' . $matches[1] . '/fonts/' . strtolower($fontdata->name) . '/' . $fontdata->licence;
}
else {
$fontpath = get_config('wwwroot') . 'skins/fonts/' . $fontdata->name . '/';
$fontpath = 'skins/fonts/' . $fontdata->name . '/' . $fontdata->licence;
}
$fontlicence = '<a href="' . $fontpath . $fontdata->licence . '">' . get_string('fontlicence', 'skin') . '</a>';
if (!file_exists(get_config('docroot') . $fontpath)) {
// Try the dataroot
if (file_exists(get_config('dataroot') . 'skins/fonts/' . $fontdata->name . '/' . $fontdata->licence)) {
$fontpath = 'skin/licence.php?family=' . $fontdata->title;
}
}
$fontlicence = '<a href="' . get_config('wwwroot') . $fontpath . '">' . get_string('fontlicence', 'skin') . '</a>';
}
else {
$fontlicence = get_string('fontlicencenotfound', 'skin');
......
......@@ -180,7 +180,7 @@ $string['manageskins'] = 'Manage skins';
$string['sitefontsmenu'] = 'Fonts';
$string['sitefonts'] = 'Fonts';
$string['sitefontsdescription'] = 'The following fonts have been installed on your site for use in skins.';
$string['installfontinstructions'] = '<p>
$string['installfontinstructions1'] = '<p>
Add fonts, which allow font embedding into web pages, via the CSS @font-face rule. Remember that not all authors / foundries allow this.
</p>
<p>
......@@ -189,6 +189,17 @@ When you find an appropriate free font that you are allowed to embed into a web
</p>
<p>
You can use <a href="https://www.fontsquirrel.com/tools/webfont-generator/">FontSquirrel Online Generator</a> for the conversion.
</p>
<p>
Or you can install a Google font via the following steps:
<ol>
<li>Visit <a href="https://google-webfonts-helper.herokuapp.com">Google webfonts helper</a>. Do this at your own risk. This service is not provided by Google Fonts.</li>
<li>Select the font for which you are looking.</li>
<li>Select the character sets you require.</li>
<li>Select the styles you want to have available.</li>
<li>Download the resulting ZIP file in step 4 on the page.</li>
<li>Upload that ZIP file in this form.</li>
</ol>
</p>';
$string['nofonts'] = 'There are no fonts.';
$string['font'] = 'font';
......@@ -290,21 +301,7 @@ $string['sampletext21'] = 'Grumpy wizards make toxic brew for the evil Queen and
$string['sampletitle22'] = 'The quick brown fox...';
$string['sampletext22'] = 'The quick brown fox jumps over the lazy dog.';
/* SKINS - GOOGLE WEB FONTS */
$string['installgwfont'] = 'Install Google font(s)';
$string['archivereadingerror'] = 'Error reading ZIP archive.';
$string['gwfontadded'] = 'Google font(s) installed successfully';
$string['gwfontsnotavailable'] = 'Google fonts are currently not available.';
$string['gwfinstructions'] = '<ol>
<li>Visit <a href="https://fonts.google.com">Google fonts</a></li>
<li>Select fonts and add them to your collection</li>
<li>Download fonts in a collection as a ZIP file</li>
<li>Upload that ZIP file in this form</li>
<li>Install Google font(s)</li>
</ol>';
$string['gwfzipfile'] = 'Valid ZIP file';
$string['gwfzipdescription'] = 'A valid ZIP file that contains all selected Google fonts to be installed.';
$string['notvalidzipfile'] = 'This is not a valid ZIP file.';
$string['fontlicence'] = 'Font license';
......
<?php
/**
*
* @package mahara
* @subpackage skin
* @author Gregor Anzelj
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
* @copyright (C) 2010-2013 Gregor Anzelj <gregor.anzelj@gmail.com>
*
*/
define('INTERNAL', 1);
define('PUBLIC', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('file.php');
if (!get_config('skins')) {
throw new FeatureNotEnabledException();
}
$family = param_variable('family');
$fontrec = get_record('skin_fonts', 'title', $family);
if (
!$fontrec
|| !$fontrec->licence
) {
throw new NotFoundException();
}
$licencepath = get_config('dataroot') . 'skins/fonts/' . $fontrec->name . '/' . $fontrec->licence;
$options = array('forcedownload' => true);
serve_file($licencepath, $fontrec->licence, pathinfo($licencepath, PATHINFO_EXTENSION), $options);
......@@ -4,9 +4,6 @@
<form method="post" action="{$WWWROOT}admin/site/font/install.php" class="btn-group">
<input class="submit btn btn-secondary" type="submit" value="{str tag=installfont section=skin}">
</form>
<form method="post" action="{$WWWROOT}admin/site/font/installgwf.php" class="btn-group">
<input class="submit btn btn-secondary" type="submit" value="{str tag=installgwfont section=skin}">
</form>
</div>
{$form|safe}
<p class="lead">{str tag=sitefontsdescription section=skin}</p>
......
Markdown is supported
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