Commit 68facdda authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge changes from topic 'WR 314864'

* changes:
  Bug 1835869: Remove obsolete skin options
  Bug 1835869: Add skin background image to page header area
  Bug 1844953: Make the font specimens appear in modal
  Bug 1843202: Allow theme fonts to be included in skin_fonts table
parents e8475a33 0e0ef413
......@@ -32,7 +32,12 @@ if (!empty($font)) {
$fontdata = get_record('skin_fonts', 'name', $font);
$fonttitle = $fontdata->title;
if (!empty($fontdata->licence) && !is_null($fontdata->licence)) {
$fontpath = get_config('wwwroot') . 'skins/fonts/' . $fontdata->name . '/';
if (preg_match('/^t_(.*)/', $fontdata->fonttype, $matches)) {
$fontpath = get_config('wwwroot') . 'theme/' . $matches[1] . '/fonts/' . strtolower($fontdata->name) . '/';
}
else {
$fontpath = get_config('wwwroot') . 'skins/fonts/' . $fontdata->name . '/';
}
$fontlicence = '<a href="' . $fontpath . $fontdata->licence . '">' . get_string('fontlicence', 'skin') . '</a>';
}
else {
......@@ -49,7 +54,10 @@ $smarty->assign('fonttitle', $fonttitle);
$smarty->assign('fontlicence', $fontlicence);
$specimen = $smarty->fetch('skin/specimen.tpl');
header('Content-type: text/html');
echo $specimen;
exit;
json_reply(false, array(
'message' => null,
'data' => array(
'font' => $font,
'html' => $specimen
)
));
......@@ -48,7 +48,6 @@ $pagination = build_pagination(array(
'count' => $data->count,
'limit' => $limit,
'offset' => $offset,
'setlimit' => true,
'datatable' => 'fontlist',
'jsonscript' => 'admin/site/fonts.json.php',
'resultcounttextsingular' => get_string('font', 'skin'),
......
......@@ -83,6 +83,7 @@ $previewform = pieform(array(
'all' => get_string('fonttypes.all', 'skin'),
'site' => get_string('fonttypes.site', 'skin'),
'google' => get_string('fonttypes.google', 'skin'),
'theme' => get_string('fonttypes.theme', 'skin'),
),
'defaultvalue' => $fonttype,
),
......@@ -96,7 +97,7 @@ $previewform = pieform(array(
),
'submit' => array(
'type' => 'submit',
'class' => 'btn-secondary',
'class' => 'btn-secondary btn-sm',
'value' => get_string('preview', 'skin')
)
)
......@@ -105,7 +106,7 @@ $data = Skin::get_sitefonts_data($limit, $offset, $fonttype);
$sitefonts = '';
$googlefonts = '';
foreach ($data->data as $font) {
if ($font['fonttype'] == 'site') {
if ($font['fonttype'] == 'site' || preg_match('/^t_/', $font['fonttype'])) {
$sitefonts .= $font['title'] . '|';
}
if ($font['fonttype'] == 'google') {
......@@ -130,7 +131,6 @@ $pagination = build_pagination(array(
'count' => $data->count,
'limit' => $limit,
'offset' => $offset,
'setlimit' => true,
'datatable' => 'fontlist',
'jsonscript' => 'admin/site/fonts.json.php',
'resultcounttextsingular' => get_string('font', 'skin'),
......@@ -138,8 +138,23 @@ $pagination = build_pagination(array(
));
$js = <<< EOF
function wire_specimens() {
$('.btn-display').each(function() {
var btn = $(this);
$(btn).off('click');
$(btn).on('click', function(e) {
e.preventDefault();
e.stopPropagation();
var url = $(this).prop('href');
sendjsonrequest(url, {}, 'GET', function(data) {
$('#page-modal .modal-body').html(data.data.html);
$('#page-modal').modal('show');
});
});
});
}
jQuery(function ($) {
p = {$pagination['javascript']}
EOF;
if ($offset > 0) {
$js .= <<< EOF
......
......@@ -565,7 +565,7 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
LEFT OUTER JOIN {artefact} api ON api.parent = a.id AND api.artefacttype = \'profileicon\'
LEFT OUTER JOIN {view_artefact} va ON va.artefact = a.id
LEFT OUTER JOIN {artefact_attachment} aa ON aa.attachment = a.id
LEFT OUTER JOIN {skin} s ON (s.bodybgimg = a.id OR s.viewbgimg = a.id)
LEFT OUTER JOIN {skin} s ON (s.bodybgimg = a.id OR s.headingbgimg = a.id)
LEFT OUTER JOIN {interaction_forum_post_attachment} fpa ON fpa.attachment = a.id
LEFT OUTER JOIN {usr} u ON a.id = u.profileicon AND a.owner = u.id';
......
......@@ -18,7 +18,7 @@ $result = get_records_sql_array('SELECT a.id, a.title, a.note, (u.profileicon =
FROM {artefact} a
LEFT OUTER JOIN {view_artefact} va ON va.artefact = a.id
LEFT OUTER JOIN {artefact_attachment} aa ON aa.attachment = a.id
LEFT OUTER JOIN {skin} s ON (s.bodybgimg = a.id OR s.viewbgimg = a.id)
LEFT OUTER JOIN {skin} s ON (s.bodybgimg = a.id OR s.headingbgimg = a.id)
LEFT OUTER JOIN {interaction_forum_post_attachment} fpa ON fpa.attachment = a.id
LEFT OUTER JOIN {usr} u ON (u.id = a.owner)
WHERE artefacttype = \'profileicon\'
......
......@@ -74,6 +74,7 @@ $string['element.select.other'] = 'Other';
$string['element.select.remove'] = 'Remove "%s"';
$string['element.color.transparent'] = 'Default or ';
$string['element.font.themedefault'] = 'Use Theme font';
$string['rule.before.before'] = 'This cannot be after the field "%s"';
......
......@@ -16,6 +16,15 @@ $string['pluginname'] = 'Skin';
$string['myskins'] = 'Skins';
$string['siteskinmenu'] = 'Skins';
$string['themedefault'] = 'Theme default';
$string['headerbackgroundcolor'] = 'Header background colour';
$string['headerbackgroundcolordescription'] = 'Background color for page header - this will not show if a header image has been selected';
$string['headerbackgroundimage'] = 'Header background image';
$string['headerbackgroundimagedescription'] = 'Minimum ideal width: 1832px. Minimum ideal height: 232px.';
$string['bodybackgroundcolour'] = 'Page background colour';
$string['bodybackgroundimage'] = 'Page background image';
$string['deletethisskin'] = 'Delete this skin';
$string['skindeleted'] = 'Skin deleted';
$string['cantdeleteskin'] = 'You cannot delete this skin.';
......@@ -243,6 +252,11 @@ $string['fonttype.site'] = 'Local font';
$string['fonttypes.site'] = 'Local fonts';
$string['fonttype.google'] = 'Google web font';
$string['fonttypes.google'] = 'Google web fonts';
$string['fonttypes.theme'] = 'Theme fonts';
$string['fonttype.t_raw'] = 'Theme font: Raw';
$string['fonttype.t_ocean'] = 'Theme font: Ocean';
$string['fonttype.t_modern'] = 'Theme font: Modern';
$string['fonttype.t_primaryschool'] = 'Theme font: Primary school';
// For examples of pangrams, see: http://en.wikipedia.org/wiki/List_of_pangrams
$string['preview'] = 'Preview';
......
......@@ -1140,7 +1140,7 @@
<FIELD NAME="type" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="private" />
<FIELD NAME="viewskin" TYPE="text" LENGTH="big" NOTNULL="true" />
<FIELD NAME="bodybgimg" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="viewbgimg" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="headingbgimg" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="mtime" TYPE="datetime" NOTNULL="false" />
</FIELDS>
......@@ -1169,7 +1169,7 @@
<FIELD NAME="notice" TYPE="text" NOTNULL="false" />
<FIELD NAME="previewfont" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="variants" TYPE="text" LENGTH="big" NOTNULL="true" />
<FIELD NAME="fonttype" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="site" />
<FIELD NAME="fonttype" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="site" />
<FIELD NAME="onlyheading" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="fontstack" TYPE="text" NOTNULL="true" />
<FIELD NAME="genericfont" TYPE="char" LENGTH="10" NOTNULL="true" ENUM="true" ENUMVALUES="'cursive', 'fantasy', 'monospace', 'sans-serif', 'serif'" />
......
......@@ -1447,5 +1447,43 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2019090900) {
log_debug('Update the skin_fonts to know about the theme fonts also');
require_once(get_config('libroot') . 'skin.php');
$table = new XMLDBTable('skin_fonts');
if (table_exists($table)) {
$field = new XMLDBField('fonttype');
$field->setAttributes(XMLDB_TYPE_CHAR, 30, null, XMLDB_NOTNULL, null, null, null, 'site');
change_field_precision($table, $field);
install_skins_default();
}
}
if ($oldversion < 2019090901) {
log_debug('Update the "skin" table to change where we record background images');
$table = new XMLDBTable('skin');
if (table_exists($table)) {
log_debug('Adding headingbgimg');
$field = new XMLDBField('headingbgimg');
if (!field_exists($table, $field)) {
$field->setAttributes(XMLDB_TYPE_INTEGER, 10);
add_field($table, $field);
}
$field = new XMLDBField('viewbgimg');
if (field_exists($table, $field)) {
log_debug('Removing viewbgimg');
if ($records = get_records_sql_array("SELECT viewbgimg AS aid FROM {skin} WHERE viewbgimg > 0")) {
foreach ($records as $record) {
// Need to remove the view bg image
require_once(get_config('libroot') . 'skin.php');
Skin::remove_background($record->aid);
}
}
drop_field($table, $field);
}
}
}
return $status;
}
......@@ -3484,7 +3484,7 @@ function artefact_in_view($artefact, $view) {
SELECT s.id
FROM {view} v INNER JOIN {skin} s
ON v.skin = s.id
WHERE v.id = ? AND ? in (s.bodybgimg, s.viewbgimg)
WHERE v.id = ? AND ? in (s.bodybgimg, s.headingbgimg)
";
$params = array_merge($params, array($view, $artefact->get('id')));
......
......@@ -66,20 +66,8 @@ class Skin {
'body_background_attachment' => 'scroll',
'body_background_position' => 1,
'header_background_color' => '#DDDDDD', // TODO remove this
'header_text_font_color' => '#000000', // TODO remove this
'header_link_normal_color' => '#000000', // TODO remove this
'header_link_normal_underline' => true, // TODO remove this
'header_link_hover_color' => '#808080', // TODO remove this
'header_link_hover_underline' => true, // TODO remove this
'header_logo_image' => 'normal', // TODO remove this
'view_background_color' => '#FFFFFF', // TODO remove this
'view_background_image' => 0, // TODO remove this
'view_background_repeat' => 4, // TODO remove this
'view_background_attachment' => 'scroll', // TODO remove this
'view_background_position' => 1, // TODO remove this
'view_background_width' => 80, // TODO remove this
'header_background_color' => '#DDDDDD',
'header_background_image' => 0,
'view_text_font_family' => 'Arial',
'view_heading_font_family' => 'Arial',
......@@ -93,16 +81,6 @@ class Skin {
'view_link_hover_color' => '##551A8B',
'view_link_hover_underline' => true,
'view_table_border_color' => '#CCCCCC', // TODO remove this
'view_table_header_color' => '#CCCCCC', // TODO remove this
'view_table_header_text_color' => '#000000', // TODO remove this
'view_table_odd_row_color' => '#EEEEEE', // TODO remove this
'view_table_even_row_color' => '#FFFFFF', // TODO remove this
'view_button_normal_color' => '#DDDDDD', // TODO remove this
'view_button_hover_color' => '#CCCCCC', // TODO remove this
'view_button_text_color' => '#000000', // TODO remove this
'view_custom_css' => '',
);
......@@ -260,11 +238,11 @@ class Skin {
else {
$fordb->bodybgimg = null;
}
if (isset($this->viewskin['view_background_image'])) {
$fordb->viewbgimg = $this->viewskin['view_background_image'];
if (isset($this->viewskin['header_background_image'])) {
$fordb->headingbgimg = $this->viewskin['header_background_image'];
}
else {
$fordb->viewbgimg = null;
$fordb->headingbgimg = null;
}
db_begin();
......@@ -598,7 +576,12 @@ class Skin {
* - Complete Guide to Pre-Installed Fonts in Linux, Mac, and Windows @ http://www.apaddedcell.com/ ...
* - Better CSS Font Stacks @ http://unitinteractive.com/blog/2008/06/26/better-css-font-stacks/
*/
public static function get_css_font_family_from_font_name($font) {
public static function get_css_font_family_from_font_name($font, $type='text') {
if ($font === '') {
global $THEME;
$font = Skin::get_all_theme_fonts($type)[$THEME->basename];
}
$fontdata = get_record('skin_fonts', 'name', $font);
return $fontdata->fontstack . ', ' . $fontdata->genericfont;
}
......@@ -615,8 +598,22 @@ class Skin {
return '';
}
$fontface = '';
if ($fontdata->fonttype == 'site') {
if (preg_match('/^t_(.*)/', $fontdata->fonttype, $matches)) {
$theme = $matches[1];
$fontfamily = urlencode($fontdata->title);
// We need to create @font-face css rule for each variant of the font
$variants = unserialize($fontdata->variants);
foreach ($variants as $variant) {
$baseurl = get_config('wwwroot') . 'theme/' . $theme . '/fonts/' . strtolower($fontdata->name) . '/';
$fontface .= '@font-face {';
$fontface .= 'font-family: \'' . escape_css_string($fontdata->title) . '\'; ';
$fontface .= 'src: url(\'' . $baseurl . $variant['WOFF'] . '\') format(\'woff\'); '; // The only type that is crossbrowser compatible
$fontface .= 'font-weight: ' . $variant['font-weight'] . '; ';
$fontface .= 'font-style: ' . $variant['font-style'] . '; ';
$fontface .= '}';
}
}
else if ($fontdata->fonttype == 'site') {
$fontfamily = urlencode($fontdata->title);
// We need to create @font-face css rule for each variant of the font
$variants = unserialize($fontdata->variants);
......@@ -707,7 +704,13 @@ class Skin {
* @param string $font The name of the font
* @return string|false The path to the font, or false if not found
*/
public static function get_path_to_previewfile($fontname) {
public static function get_path_to_previewfile($fontname, $type='text') {
$font = false;
$theme = '';
if ($fontname === '') {
global $THEME;
$fontname = Skin::get_all_theme_fonts($type)[$THEME->basename];
}
$fontdata = get_record('skin_fonts', 'name', $fontname);
if (!$fontdata) {
$font = false;
......@@ -715,6 +718,15 @@ class Skin {
else if ($fontdata->fonttype == 'common') {
$font = get_config('docroot') . 'lib/fonts/' . $fontdata->previewfont;
}
else if (preg_match('/^t_(.*)/', $fontdata->fonttype, $matches)) {
if ($matches[1]) {
$theme = $matches[1];
$fontfile = get_config('docroot') . 'theme/' . $theme . '/fonts/' . strtolower($fontdata->name) . '/' . $fontdata->previewfont;
if (file_exists($fontfile) && is_readable($fontfile)) {
$font = $fontfile;
}
}
}
else {
$fontfile = get_config('dataroot') . 'skins/fonts/' . $fontdata->name . '/' . $fontdata->previewfont;
if (file_exists($fontfile)) {
......@@ -729,7 +741,6 @@ class Skin {
return $font;
}
/**
* Converts 6-digit hex color #RRGGBB to rgb(RRR, GGG, BBB)
* @param unknown_type $color_hex
......@@ -742,31 +753,33 @@ class Skin {
/**
* Gets font sizes for heading, sub-heading and normal text from given relative size (as in CSS).
* Relative size can be one of following: xx-small, x-small, small, medium, large, x-large or xx-large
* The font size of a page header is not affected by user chosen font size
*
* @param string $font_size
* @return array
*/
private static function get_font_sizes($font_size) {
switch ($font_size) {
case 'xx-small':
return array(7, 5, 3);
return array(9, 5, 3);
break;
case 'x-small':
return array(8, 6, 4);
return array(9, 6, 4);
break;
case 'small':
return array(9, 7, 5);
break;
case 'medium':
return array(10, 8, 6);
return array(9, 8, 6);
break;
case 'large':
return array(12, 10, 8);
return array(9, 10, 8);
break;
case 'x-large':
return array(14, 12, 10);
return array(9, 12, 10);
break;
case 'xx-large':
return array(16, 14, 12);
return array(9, 14, 12);
break;
default:
return array(9, 7, 5);
......@@ -826,6 +839,19 @@ class Skin {
return array('x' => $tilepositionx, 'y' => $tilepositiony);
}
private static function imageheaderfill(&$dst_im, $src_fill, $zoom_fill, $align_fill=1, $header_width, $header_height, $xoffset = 0) {
$layer = imagecreatetruecolor(imagesx($dst_im), imagesy($dst_im));
// Turn off alpha blending and set alpha flag
imagealphablending($layer, false);
imagesavealpha($layer, true);
// Create resized (zoomed) version of the tile image, used for filling...
$tile = imagecreatetruecolor(imagesx($src_fill) * $zoom_fill, imagesy($src_fill) * $zoom_fill);
imagealphablending($tile, false);
imagesavealpha($tile, true);
imagecopyresampled($tile, $src_fill, $xoffset, 0, 0, 0, imagesx($src_fill) * $zoom_fill, imagesy($src_fill) * $zoom_fill, imagesx($src_fill), imagesy($src_fill));
imagecopyresampled($dst_im, $tile, 0, 0, 0, 0, $header_width, $header_height, $header_width, $header_height); // black
}
/**
* Fill in the backgrounds in the thumbnail image
......@@ -927,7 +953,7 @@ class Skin {
}
// ========== BODY BACKGROUND IMAGE ==========
if ($skin['body_background_image'] <> null) {
if (!empty($skin['body_background_image'])) {
require_once(get_config('docroot') . 'artefact/file/lib.php');
$fileid = $skin['body_background_image'];
$fileobj = artefact_instance_from_id($fileid);
......@@ -951,97 +977,123 @@ class Skin {
self::imagebackgroundfill($img, $bodybackgroundfill, Skin::PREVIEW_THUMBNAIL_ZOOM, intval($skin['body_background_repeat']), intval($skin['body_background_position']));
}
// ========== VIEW BACKGROUND COLOR ========== // TODO remove this
$viewwidth = Skin::PREVIEW_WIDTH-intval(((100 - $skin['view_background_width']) / 100) * Skin::PREVIEW_WIDTH);
// ========== VIEW BACKGROUND COLOR ==========
$viewwidth = Skin::PREVIEW_WIDTH - intval(0.2 * Skin::PREVIEW_WIDTH);
$viewheight = Skin::PREVIEW_HEIGHT;
$img2 = imagecreatetruecolor($viewwidth*Skin::PREVIEW_THUMBNAIL_ZOOM+1, $viewheight*Skin::PREVIEW_THUMBNAIL_ZOOM);
$img2 = imagecreatetruecolor($viewwidth * Skin::PREVIEW_THUMBNAIL_ZOOM + 1, $viewheight * Skin::PREVIEW_THUMBNAIL_ZOOM);
// Turn off alpha blending and set alpha flag
imagealphablending($img2, true);
imagesavealpha($img2, true);
if ($skin['view_background_color'] <> 'transparent') {
list($r, $g, $b) = self::get_rgb_from_hex($skin['view_background_color']);
$viewbackgroundcolor = imagecolorallocate($img2, $r, $g, $b);
imagefill($img2, 0, 0, $viewbackgroundcolor);
}
else {
$transparentcolor = imagecolorallocatealpha($img2, 255, 255, 255, 127);
imagefill($img2, 0, 0, $transparentcolor);
}
list($r, $g, $b) = self::get_rgb_from_hex('#FFFFFF');
$viewbackgroundcolor1 = imagecolorallocatealpha($img2, $r, $g, $b, 127);
imagefill($img2, 0, 0, $viewbackgroundcolor1);
// ========== SAMPLE HEADING BACKGROUND IMAGE/COLOUR AND TEXT ==========
// The text in the page header is not affected by the font size chosen by the user
$header_font_size = self::get_font_sizes($skin['view_text_font_size'])[0];
// Allocate heading sizes, text size and emphasized size
list($heading_size, $emphasized_size, $text_size) = self::get_font_sizes($skin['view_text_font_size']);
list($r, $g, $b) = self::get_rgb_from_hex($skin['view_text_heading_color']);
// Allocate heading_text_color
list($r, $g, $b) = self::get_rgb_from_hex($skin['view_text_heading_color']);
$heading_text_color = imagecolorallocate($img, $r, $g, $b);
// Allocate heading_background_color
list($r, $g, $b) = self::get_rgb_from_hex($skin['header_background_color']);
$heading_background_color = imagecolorallocate($img, $r, $g, $b);
/* ========== VIEW BACKGROUND IMAGE ========== */ // TODO remove this
if ($skin['view_background_image'] <> null) {
$headerwidth = Skin::PREVIEW_WIDTH - intval(0.2 * Skin::PREVIEW_WIDTH);
$headerheight = $heading_size;
list($r, $g, $b) = self::get_rgb_from_hex('#FFFFFF');
$viewbackgroundcolor2 = imagecolorallocate($img2, $r, $g, $b);
imagefilledrectangle($img2, 0, $headerheight + ($header_font_size * 2.5) + 1, $viewwidth, $viewheight, $viewbackgroundcolor2);
// Draw header background colour block on the VIEW and BODY
imagefilledrectangle($img, 0, 0, $headerwidth, $headerheight + ($header_font_size * 2.5), $heading_background_color);
// Replace header colour with sample header image if there is one allocated
if (!empty($skin['header_background_image'])) {
require_once(get_config('docroot') . 'artefact/file/lib.php');
$fileid = $skin['view_background_image'];
$fileid = $skin['header_background_image'];
$fileobj = artefact_instance_from_id($fileid);
$filetype = $fileobj->get('filetype');
switch ($filetype) {
case "image/gif":
$viewbackgroundfill = imagecreatefromgif($fileobj->get_path());
break;
case "image/jpeg":
$viewbackgroundfill = imagecreatefromjpeg($fileobj->get_path());
break;
case "image/png":
default:
$viewbackgroundfill = imagecreatefrompng($fileobj->get_path());
break;
case "image/gif":
$headerimage = imagecreatefromgif($fileobj->get_path());
break;
case "image/jpeg":
$headerimage = imagecreatefromjpeg($fileobj->get_path());
break;
case "image/png":
default:
$headerimage = imagecreatefrompng($fileobj->get_path());
break;
}
imagealphablending($viewbackgroundfill, false);
imagesavealpha($viewbackgroundfill, true);
self::imagebackgroundfill($img2, $viewbackgroundfill, Skin::PREVIEW_THUMBNAIL_ZOOM, intval($skin['view_background_repeat']), intval($skin['view_background_position']));
$headerimage = imagescale($headerimage, Skin::PREVIEW_WIDTH);
// Draw header image on the VIEW and BODY
self::imageheaderfill($img, $headerimage, Skin::PREVIEW_THUMBNAIL_ZOOM*1.2, 1, $headerwidth, $headerheight + ($header_font_size * 2.6));
}
// ========== SAMPLE HEADING AND TEXT ==========
list($heading_size, $emphasized_size, $text_size) = self::get_font_sizes($skin['view_text_font_size']);
list($r, $g, $b) = self::get_rgb_from_hex($skin['view_text_heading_color']);
$heading_color = imagecolorallocate($img, $r, $g, $b);
// Even though this text is only used in preview images, it's possible the site might want to change
// it for localization purposes, for instance if they're primarily using a non-Latin alphabet
$heading_text = get_string('previewheading', 'skin');
$heading_font = self::get_path_to_previewfile($skin['view_heading_font_family']);
// Add the sample heading
imagettftext($img2, $heading_size, 0, 10, $heading_size+8, $heading_color, $heading_font, $heading_text);
$heading_font = self::get_path_to_previewfile($skin['view_heading_font_family'], 'heading');
// Add the sample heading title - the font size does not affect the text within page header
imagettftext($img2, $heading_size, 0, 10, $header_font_size+10, $heading_text_color, $heading_font, $heading_text);
list($r, $g, $b) = self::get_rgb_from_hex($skin['view_text_emphasized_color']);
$emphasized_color = imagecolorallocate($img, $r, $g, $b);
list($r, $g, $b) = self::get_rgb_from_hex($skin['view_table_border_color']);
list($r, $g, $b) = self::get_rgb_from_hex('#CCCCCC');
$line_color = imagecolorallocate($img, $r, $g, $b);
$emphasized_text1 = get_string('previewsubhead1', 'skin'); // Latin for text
$emphasized_text2 = get_string('previewsubhead2', 'skin'); // Latin for image
$emphasized_font = self::get_path_to_previewfile($skin['view_heading_font_family']);
$emphasized_font = self::get_path_to_previewfile($skin['view_heading_font_family'], 'heading');
// Calculate y positions for drawing
$subheading_y_pos = $header_font_size*4 + $emphasized_size + $emphasized_size;
$underline_y_pos = $subheading_y_pos + ($heading_size/2) ;
$sampleimage_y_pos = $underline_y_pos + $text_size;
// Add the sample sub-heading 10000
imagettftext($img2, $emphasized_size, 0, 10, $subheading_y_pos, $emphasized_color, $emphasized_font, $emphasized_text1);
// Add the sample sub-heading 1
imagettftext($img2, $emphasized_size, 0, 10, $heading_size+$emphasized_size+16, $emphasized_color, $emphasized_font, $emphasized_text1);
// Add second column to the preview thumbnail, if the width of the view is greater or equal 70%
// or the size of regular text is less than 8...
if (intval($skin['view_background_width']) >= 70 && $text_size < 8) {
if ($text_size < 8) {
// Add sample picture
$sample_img = imagecreatefrompng($THEME->get_path('images/skin_preview_img.png'));
imagefilledrectangle($img2, 5, $heading_size + $emphasized_size + 18, imagesx($img2) - imagesx($sample_img) - 20, $heading_size + $emphasized_size + 18, $line_color);
// Add the sample sub-heading 2
imagettftext($img2, $emphasized_size, 0, imagesx($img2) - imagesx($sample_img) - 10, $heading_size + $emphasized_size + 16, $emphasized_color, $emphasized_font, $emphasized_text2);
imagefilledrectangle($img2, imagesx($img2) - imagesx($sample_img) - 15, $heading_size + $emphasized_size + 18, imagesx($img2) - 5, $heading_size + $emphasized_size + 18, $line_color);
imagecopyresampled($img2, $sample_img, imagesx($img2) - imagesx($sample_img) - 10, $heading_size + $emphasized_size + $text_size + 21, 0, 0, imagesx($sample_img), imagesy($sample_img), imagesx($sample_img), imagesy($sample_img));
// Add the sample sub-heading 2 and underline, then merge $sample_img into $img2
imagettftext($img2, $emphasized_size, 0, imagesx($img2) - imagesx($sample_img) - 10, $subheading_y_pos, $emphasized_color, $emphasized_font, $emphasized_text2);
imagefilledrectangle($img2, imagesx($img2) - imagesx($sample_img) - 15, $underline_y_pos, imagesx($img2) - 5, $underline_y_pos, $line_color);
// Add underline for sub-heading 1 where x pos stops at second column break
imagefilledrectangle($img2, 5, $underline_y_pos, imagesx($img2) - imagesx($sample_img) - 20, $underline_y_pos, $line_color);
imagecopyresampled($img2, $sample_img, imagesx($img2) - imagesx($sample_img) - 10, $sampleimage_y_pos, 0, 0, imagesx($sample_img), imagesy($sample_img), imagesx($sample_img), imagesy($sample_img));
}
else {
imagefilledrectangle($img2, 5, $heading_size + $emphasized_size + 18, imagesx($img2) - 10, $heading_size + $emphasized_size + 18, $line_color);
imagefilledrectangle($img2, 5, $underline_y_pos, imagesx($img2) - 10, $underline_y_pos, $line_color);
}
// Add some sample lines of text
list($r, $g, $b) = self::get_rgb_from_hex($skin['view_text_font_color']);
$text_color = imagecolorallocate($img, $r, $g, $b);
$text_font = self::get_path_to_previewfile($skin['view_text_font_family']);
$text_font = self::get_path_to_previewfile($skin['view_text_font_family'], 'text');
for ($i = 1; $i <= 9; $i++) {
imagettftext($img2, $text_size, 0, 10, $heading_size+$emphasized_size+$text_size+15+$i*(2*$text_size), $text_color, $text_font, get_string("previewtextline{$i}", 'skin'));
imagettftext($img2, $text_size, 0, 10, $underline_y_pos + $i*(2*$text_size), $text_color, $text_font, get_string("previewtextline{$i}", 'skin'));
}
// ========== COPY VIEW PART OVER BODY PART OF THE THUMBNAIL ==========
$viewbackgroundmargin = intval(((Skin::PREVIEW_WIDTH - intval(($skin['view_background_width'] / 100) * Skin::PREVIEW_WIDTH)) / 2) * Skin::PREVIEW_THUMBNAIL_ZOOM);
$viewbackgroundmargin = intval(((Skin::PREVIEW_WIDTH - intval(0.8 * Skin::PREVIEW_WIDTH)) / 2) * Skin::PREVIEW_THUMBNAIL_ZOOM);
$VIEWOFFSETX = $viewbackgroundmargin - 1;
$VIEWOFFSETY = 0;
......@@ -1065,7 +1117,7 @@ class Skin {
* @param int $aid Artefact id of the background image to remove from skins
*/
public static function remove_background($aid) {
$skinstoupdate = get_records_select_array('skin', 'bodybgimg = ? OR viewbgimg = ?', array($aid, $aid), 'id');
$skinstoupdate = get_records_select_array('skin', 'bodybgimg = ? OR headingbgimg = ?', array($aid, $aid), 'id');
if (!empty($skinstoupdate) && is_array($skinstoupdate)) {
foreach ($skinstoupdate as $skin) {
$skin = new Skin($skin->id);
......@@ -1073,8 +1125,8 @@ class Skin {
if (isset($viewskin['body_background_image']) && $viewskin['body_background_image'] == $aid) {
$viewskin['body_background_image'] = 0;
}
if (isset($viewskin['view_background_image']) && $viewskin['view_background_image'] == $aid) { // TODO remove this