Commit 743a57d5 authored by Robert Lyon's avatar Robert Lyon

Placing google web fonts into their own subdir (Bug 1292301)

Allowing for them to be deleted correctly

Change-Id: Ie2c9b38e5f77eb3b4dcc2d3fe93e68134f964d9f
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 0dab95a5
......@@ -104,8 +104,6 @@ function gwfontform_submit(Pieform $form, $values) {
$fontpath = get_config('dataroot') . 'skins/fonts/';
check_dir_exists($fontpath, true, true);
$extractfiles = array();
$installfonts = array();
$currentfont = null;
$licence = null;
$previewfont = null;
......@@ -121,10 +119,13 @@ function gwfontform_submit(Pieform $form, $values) {
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') {
......@@ -145,8 +146,16 @@ function gwfontform_submit(Pieform $form, $values) {
// Reset settings for each new font...
if (!is_null($licence) && !is_null($previewfont)) {
$installfonts[] = array(
"name" => $fontname,
$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 ???
......@@ -157,22 +166,23 @@ function gwfontform_submit(Pieform $form, $values) {
"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;
}
}
// Install fonts (write data into database)
foreach ($installfonts as $installfont) {
// Add check if the record doesn't exist!!!
ensure_record_exists('skin_fonts',
(object) array('name' => $installfont['name']),
(object) $installfont
);
}
// Extract installed fonts
$zip->extractTo($fontpath, $extractfiles);
$SESSION->add_ok_msg(get_string('gwfontadded', 'skin'));
}
else {
......
......@@ -3699,5 +3699,50 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2014101500) {
if ($fonts = get_records_assoc('skin_fonts', 'fonttype', 'google')) {
$fontpath = get_config('dataroot') . 'skins/fonts/';
foreach ($fonts as $font) {
// if google font is not already in subdir
if (!is_dir($fontpath . $font->name)) {
if (file_exists($fontpath . $font->previewfont)) {
// we need to create the subdir and move the file into it
$newfontpath = $fontpath . $font->name . '/';
check_dir_exists($newfontpath, true, true);
rename ($fontpath . $font->previewfont, $newfontpath . $font->previewfont);
// and move the license file if it exists also
if (file_exists($fontpath . $font->licence)) {
rename ($fontpath . $font->licence, $newfontpath . $font->licence);
}
}
else {
// the file is not there for some reason so we might as well delete the font from the db
$result = delete_records('skin_fonts', 'name', $font->name);
if ($result !== false) {
// Check to see if the font is being used in a skin. If it is remove it from
// the skin's viewskin data
$skins = get_records_array('skin');
if (is_array($skins)) {
foreach ($skins as $skin) {
$options = unserialize($skin->viewskin);
foreach ($options as $key => $option) {
if (preg_match('/font_family/', $key) && $option == $font->name) {
require_once(get_config('docroot') . 'lib/skin.php');
$skinobj = new Skin($skin->id);
$viewskin = $skinobj->get('viewskin');
$viewskin[$key] = false;
$skinobj->set('viewskin', $viewskin);
$skinobj->commit();
}
}
}
}
}
}
}
}
}
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2014101300;
$config->version = 2014101500;
$config->release = '1.11.0dev';
$config->minupgradefrom = 2009022600;
$config->minupgraderelease = '1.1.0 (release tag 1.1.0_RELEASE)';
......
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