Commit 00768be5 authored by Gregor Anzelj's avatar Gregor Anzelj Committed by Gerrit Code Review
Browse files

Adding page skin functionality. (Bug #1168213)

see also https://mahara.org/interaction/forum/topic.php?id=4404



Change-Id: Iab8524b3f1f86ceacb9854d57cdd00e62aa5e32f
Signed-off-by: default avatarGregor Anzelj <gregor.anzelj@gmail.com>
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
Signed-off-by: Aaron Wells's avatarAaron Wells <aaronw@catalyst.net.nz>
parent e664af68
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2010 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage skin
* @author Gregor Anzelj
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2010-2013 Gregor Anzelj <gregor.anzelj@gmail.com>
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configsite/sitefonts');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'addfontvariant');
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once('pieforms/pieform.php');
require_once(get_config('libroot') . 'skin.php');
define('TITLE', get_string('addfontvariant', 'skin'));
$font = param_alphanum('font');
$fonttitle = get_field('skin_fonts', 'title', 'name', $font);
$form = pieform(array(
'name' => 'addvariantform',
//'jsform' => true,
'plugintype' => 'artefact',
'pluginname' => 'skin',
'elements' => array(
'fontname' => array(
'type' => 'hidden',
'value' => $font,
),
'fonttitle' => array(
'type' => 'html',
'labelhtml' => get_string('fontname', 'skin'),
'value' => $fonttitle,
),
'fontstyle' => array(
'type' => 'select',
'labelhtml' => get_string('fontstyle', 'skin'),
'defaultvalue' => 'regular',
'options' => array(
'regular' => get_string('regular', 'skin'),
'bold' => get_string('bold', 'skin'),
'italic' => get_string('italic', 'skin'),
'bolditalic' => get_string('bolditalic', 'skin'),
),
'rules' => array('required' => true),
),
'fontfiles' => array(
'type' => 'fieldset',
'legend' => get_string('fontfiles', 'skin'),
'elements' => array(
'fontfileEOT' => array(
'type' => 'file',
'labelhtml' => get_string('fontfileeot', 'skin'),
'description' => get_string('eotdescription', 'skin'),
'rules' => array('required' => true),
),
'fontfileSVG' => array(
'type' => 'file',
'labelhtml' => get_string('fontfilesvg', 'skin'),
'description' => get_string('svgdescription', 'skin'),
'rules' => array('required' => true),
),
'fontfileTTF' => array(
'type' => 'file',
'labelhtml' => get_string('fontfilettf', 'skin'),
'description' => get_string('ttfdescription', 'skin'),
'rules' => array('required' => true),
),
'fontfileWOFF' => array(
'type' => 'file',
'labelhtml' => get_string('fontfilewoff', 'skin'),
'description' => get_string('woffdescription', 'skin'),
'rules' => array('required' => true),
),
)
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('save', 'mahara'), get_string('cancel', 'mahara')),
'goto' => get_config('wwwroot') . 'admin/site/fonts.php',
),
),
));
$smarty = smarty(array('tablerenderer'));
$smarty->assign('form', $form);
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->display('form.tpl');
// TODO: Consolidate portions of this with addfontform_validate in install.php, to reduce
// code duplication.
function addvariantform_validate(Pieform $form, $values) {
global $USER, $SESSION;
require_once('file.php');
require_once('uploadmanager.php');
// Make sure they didn't hack the hidden variable to have the name of
// a font that doesn't exist
if (!record_exists('skin_fonts', 'name', $values['fontname'])) {
$form->set_error('fontname', get_string('nosuchfont', 'skin'));
}
$uploadfiles = array(
'fontfileEOT' => array(
'required' => true,
'suffix' => 'eot'
),
'fontfileSVG' => array(
'required' => true,
'suffix' => 'svg',
),
'fontfileTTF' => array(
'required' => true,
'suffix' => 'ttf',
),
'fontfileWOFF' => array(
'required' => true,
'suffix' => 'woff',
),
);
foreach ($uploadfiles as $inputname => $details) {
$um = new upload_manager($inputname, false, null, $details['required']);
if ($error = $um->preprocess_file()) {
$form->set_error($inputname, $error);
}
if ($details['suffix']) {
$reqext = ".{$details['suffix']}";
$fileext = substr($values[$inputname]['name'], (-1 * strlen($reqext)));
if ($fileext <> $reqext) {
$form->set_error($inputname, get_string('notvalidfontfile', 'skin', strtoupper($details['suffix'])));
}
}
}
}
// TODO: Consolidate this with addfontform_submit() in font/install.php to reduce
// code duplication. It's just different enough that it's non-trivial to combine them.
function addvariantform_submit(Pieform $form, $values) {
global $USER, $SESSION;
// We know the font name is valid (and therefore a directory for it exists) because of the
// previous validation that there's a record with that font name
// But just to be extra careful...
$foldername = preg_replace(Skin::FONTNAME_FILTER_CHARACTERS, "", $values['fontname']);
$fontpath = get_config('dataroot') . 'skins/fonts/' . $foldername . '/';
check_dir_exists($fontpath, true, true);
// Get SVG id from SVG font file...
$tempname = $values['fontfileSVG']['tmp_name'];
$filename = $values['fontfileSVG']['name'];
$xmlDoc = simplexml_load_string(file_get_contents($tempname));
$svg_id = (string) $xmlDoc->defs->font->attributes()->id;
// Update variants column in database record...
switch ($values['fontstyle']) {
case 'regular':
$font_variant = 'regular';
$font_weight = 'normal';
$font_style = 'normal';
break;
case 'bold':
$font_variant = 'bold';
$font_weight = 'bold';
$font_style = 'normal';
break;
case 'italic':
$font_variant = 'italic';
$font_weight = 'normal';
$font_style = 'italic';
break;
case 'bolditalic':
$font_variant = 'bolditalic';
$font_weight = 'bold';
$font_style = 'italic';
break;
}
$variantdata = array(
'variant' => $font_variant,
'EOT' => $values['fontfileEOT']['name'],
'SVG' => $values['fontfileSVG']['name'],
'SVGid' => $svg_id,
'TTF' => $values['fontfileTTF']['name'],
'WOFF' => $values['fontfileWOFF']['name'],
'font-weight' => $font_weight,
'font-style' => $font_style,
);
$fontvariants = unserialize(get_field('skin_fonts', 'variants', 'name', $values['fontname']));
$fontvariants[$font_variant] = array($variantdata);
// Copy SVG font file to folder...
$tempname = $values['fontfileSVG']['tmp_name'];
$filename = $values['fontfileSVG']['name'];
move_uploaded_file($tempname, $fontpath.$filename);
// Copy EOT font file.
$tempname = $values['fontfileEOT']['tmp_name'];
$filename = $values['fontfileEOT']['name'];
move_uploaded_file($tempname, $fontpath.$filename);
// Copy TTF font file to folder...
$tempname = $values['fontfileTTF']['tmp_name'];
$filename = $values['fontfileTTF']['name'];
move_uploaded_file($tempname, $fontpath.$filename);
// Copy WOFF font file to folder...
$tempname = $values['fontfileWOFF']['tmp_name'];
$filename = $values['fontfileWOFF']['name'];
move_uploaded_file($tempname, $fontpath.$filename);
// Hold off on updating the DB until we've successfully uploaded all the files
update_record('skin_fonts', array('variants' => serialize($fontvariants)), array('name' => $values['fontname']));
$SESSION->add_ok_msg(get_string('fontvariantadded', 'skin'));
redirect('/admin/site/fonts.php');
}
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage skin
* @author Gregor Anzelj
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2010-2013 Gregor Anzelj <gregor.anzelj@gmail.com>
*
*/
define('INTERNAL', 1);
define('PUBLIC', 1);
define('NOCHECKPASSWORDCHANGE', 1);
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once(get_config('libroot') . 'skin.php');
// We use the font title as the "family" name for the font
$family = param_variable('family', false);
if (!empty($family)) {
$stylesheet = '';
$fonts = explode('|', $family);
foreach ($fonts as $font) {
$fontname = get_field('skin_fonts', 'name', 'title', $font);
$stylesheet .= Skin::get_css_font_face_from_font_name($fontname) . "\n";
}
}
else {
$stylesheet = <<< EOF
/* table with gap between rows */
#fontlist td {
border-bottom: 2px solid #FFF;
font-size: .9167em;
}
#fontlist ul.actionlist {
margin: 0 0 0 10px;
float: right;
width: 180px;
font-size: 1em;
}
#fontlist ul.actionlist li {
list-style: none;
margin: 0;
border-top: 1px solid #d1d1d1;
padding: 2px 3px;
line-height: 1.2em;
}
#fontlist ul.actionlist li:first-child {
border-top: none;
}
EOF;
}
header('Content-type: text/css');
echo $stylesheet;
exit;
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2010 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage skin
* @author Gregor Anzelj
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2010-2013 Gregor Anzelj <gregor.anzelj@gmail.com>
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configsite/sitefonts');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'deletefont');
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once('pieforms/pieform.php');
$font = param_alphanum('font');
$fontdata = null;
$fontdata = get_record('skin_fonts', 'name', $font);
if ($fontdata == false) {
throw new AccessDeniedException("Font not found");
}
if ($fontdata->fonttype != 'site') {
throw new AccessDeniedException("Cannot delete this font");
}
define('TITLE', get_string('deletespecifiedfont', 'skin', $fontdata->title));
$form = pieform(array(
'name' => 'deletefontform',
'autofocus' => false,
'method' => 'post',
'elements' => array(
'font' => array(
'type' => 'hidden',
'value' => $font,
),
'submit' => array(
'type' => 'submitcancel',
'title' => get_string('deletefontconfirm', 'skin'),
'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . 'admin/site/fonts.php',
)
),
));
$smarty = smarty();
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->assign('form', $form);
$smarty->display('form.tpl');
function deletefontform_submit(Pieform $form, $values) {
global $SESSION;
$fontname = $values['font'];
$result = delete_records('skin_fonts', 'name', $fontname);
if ($result == false) {
$SESSION->add_error_msg(get_string('cantdeletefont', 'skin'));
}
else {
// Also delete all the files in the appropriate folder and the folder itself...
$fontpath = get_config('dataroot') . 'skins/fonts/' . $fontname . '/';
if ($handle = opendir($fontpath)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
unlink($fontpath . $file);
}
}
closedir($handle);
}
rmdir($fontpath);
$SESSION->add_ok_msg(get_string('fontdeleted', 'skin'));
}
redirect('/admin/site/fonts.php');
}
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2010 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage skin
* @author Gregor Anzelj
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2010-2013 Gregor Anzelj <gregor.anzelj@gmail.com>
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configsite/sitefonts');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'editfont');
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('editfont', 'skin'));
$font = param_alphanum('font');
$fontdata = get_record('skin_fonts', 'name', $font);
if ($fontdata == false) {
throw new AccessDeniedException("Font not found");
}
$form = pieform(array(
'name' => 'editfontform',
//'jsform' => true,
'plugintype' => 'artefact',
'pluginname' => 'skin',
'elements' => array(
'fontname' => array(
'type' => 'hidden',
'value' => $font,
),
'fonttitle' => array(
'type' => 'text',
'labelhtml' => get_string('fontname', 'skin'),
'defaultvalue' => (!empty($fontdata->title) ? $fontdata->title : null),
),
'fontnotice' => array(
'type' => 'text',
'labelhtml' => get_string('fontnotice', 'skin'),
'description' => get_string('fontnoticedescription', 'skin'),
'defaultvalue' => (!empty($fontdata->notice) ? $fontdata->notice : null),
),
'fonttype' => array(
'type' => 'radio',
'labelhtml' => get_string('fonttype', 'skin'),
'defaultvalue' => (!empty($fontdata->onlyheading) && ($fontdata->onlyheading == 1) ? 'heading' : 'text'),
'options' => array(
'text' => get_string('headingandtext', 'skin'),
'heading' => get_string('headingonly', 'skin'),
),
'separator' => '<br />',
),
'genericfont' => array(
'type' => 'select',
'labelhtml' => get_string('genericfontfamily', 'skin'),
'defaultvalue' => (!empty($fontdata->genericfont) ? $fontdata->genericfont : 'sans-serif'),
'options' => array(
'serif' => 'serif',
'sans-serif' => 'sans-serif',
'monospace' => 'monospace',
'cursive' => 'cursive',
'fantasy' => 'fantasy',
),
'separator' => '<br />',
'rules' => array('required' => true),
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('save', 'mahara'), get_string('cancel', 'mahara')),
'goto' => get_config('wwwroot') . 'admin/site/fonts.php',
),
),
));
$smarty = smarty(array('tablerenderer'));
$smarty->assign('form', $form);
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->display('form.tpl');
function editfontform_submit(Pieform $form, $values) {
global $USER, $SESSION;
update_record('skin_fonts', array(
'title' => $values['fonttitle'],
'notice' => $values['fontnotice'],
'onlyheading' => ($values['fonttype'] == 'heading' ? 1 : 0),
'fontstack' => '\'' . escape_css_string($values['fonttitle']) . '\'',
'genericfont' => $values['genericfont']
), array('name' => $values['fontname']));
$SESSION->add_ok_msg(get_string('fontedited', 'skin'));
redirect('/admin/site/fonts.php');
}
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2010 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage skin
* @author Gregor Anzelj
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2010-2013 Gregor Anzelj <gregor.anzelj@gmail.com>
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configsite/sitefonts');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'install');
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once('pieforms/pieform.php');
require_once(get_config('libroot') . 'skin.php');
define('TITLE', get_string('installfont', 'skin'));
$form = pieform(array(
'name' => 'addfontform',
// 'jsform' => true,
'plugintype' => 'artefact',
'pluginname' => 'skin',
'elements' => array(
'fontinstructions' => array(
'type' => 'html',
'title' => '',
'value' => get_string('installfontinstructions', 'skin'),
),
'fonttitle' => array(
'type' => 'text',
'labelhtml' => get_string('fontname', 'skin'),
'rules' => array('required' => true),
),
'fontnotice' => array(
'type' => 'text',
'labelhtml' => get_string('fontnotice', 'skin'),
'description' => get_string('fontnoticedescription', 'skin'),
),
'fontstyle' => array(
'type' => 'select',
'labelhtml' => get_string('fontstyle', 'skin'),
'defaultvalue' =>