Commit 6e5724e2 authored by Son Nguyen's avatar Son Nguyen Committed by Robert Lyon
Browse files

Allow HTML in Résumé Achievements and Ed/Emp sections (Bug #989195)



Enable tinyMCE editing for
- Resume -> Achievements -> Books and publications
- Resume -> Achievements -> Certifications ...
- Resume -> Achievements -> Professional memberships
- Resume -> Education and Employment -> Education history
- Resume -> Education and Employment -> Employment history

Make links within description text clickable.

Escape HTML tags of description field for old (before upgrade) values
as we are now allowing 'safe' display of description content

Escape other field content before displaying it

behatnotneeded

Change-Id: I8e601b3eb67bef07bb67ea38a630d22d4c597538
Signed-off-by: default avatarSon Nguyen <ngson2000@yahoo.com>
parent 879687fd
......@@ -36,6 +36,21 @@ if (!$data = get_records_sql_array($sql, array($owner, $type))) {
$data = array();
}
$classname = generate_artefact_class_name($type);
$iswysiwyg = false;
if (is_callable($classname . '::is_wysiwyg')) {
$iswysiwyg = call_static_method($classname, 'is_wysiwyg');
}
foreach ($data as &$row) {
foreach ($row as $key => $value) {
if ($iswysiwyg && preg_match('/description$/', $key)) {
$row->{$key} = clean_html($row->{$key});
}
else {
$row->{$key} = hsc($row->{$key});
}
}
}
// Add artefact attachments it there are any
$datawithattachments = array();
foreach ($data as $record) {
......
......@@ -50,5 +50,37 @@ function xmldb_artefact_resume_upgrade($oldversion=0) {
execute_sql("UPDATE {blocktype_installed_category} SET category = 'internal' WHERE category = 'resume'");
}
if ($oldversion < 2017030600) {
log_debug("Allow WYSIWYG HTML for the field 'description' of Resume Book, Certification, and Membership fields");
// Escape all HTML tags in the old database
$types = array('book', 'membership', 'certification', 'employmenthistory', 'educationhistory');
foreach ($types as $type) {
log_debug("Cleaning up data for " . $type);
$total = count_records('artefact_resume_' . $type);
$count = 0;
$limit = 1000;
for ($i = 0; $i <= $total; $i += $limit) {
$sql = "
SELECT r.id, r.description
FROM {artefact_resume_" . $type . "} r
ORDER BY r.id";
$resumes = get_records_sql_array($sql, array(), $i, $limit);
foreach ($resumes as $item) {
// Escape HTML tags in "description"
$item->description = hsc($item->description);
set_field('artefact_resume_' . $type, 'description', $item->description, 'id', $item->id);
$count += $limit;
}
if (($count % $limit) == 0 || $count >= $total) {
if ($count > $total) {
$count = $total;
}
log_debug("$count/$total");
set_time_limit(30);
}
}
}
}
return $status;
}
......@@ -577,6 +577,10 @@ abstract class ArtefactTypeResumeComposite extends ArtefactTypeResume implements
return true;
}
public static function is_wysiwyg() {
return false;
}
public function can_have_attachments() {
return true;
}
......@@ -1248,6 +1252,10 @@ class ArtefactTypeEmploymenthistory extends ArtefactTypeResumeComposite {
";
}
public static function is_wysiwyg() {
return true;
}
public static function get_tablerenderer_title_js_string() {
return " row.jobtitle + ': ' + row.employer";
}
......@@ -1303,10 +1311,10 @@ class ArtefactTypeEmploymenthistory extends ArtefactTypeResumeComposite {
'size' => 50,
),
'positiondescription' => array(
'type' => 'textarea',
'type' => 'wysiwyg',
'rows' => 10,
'cols' => 50,
'resizable' => false,
'rules' => array('maxlength' => 65536),
'title' => get_string('positiondescription', 'artefact.resume'),
),
'attachments' => array(
......@@ -1386,6 +1394,10 @@ class ArtefactTypeEducationhistory extends ArtefactTypeResumeComposite {
";
}
public static function is_wysiwyg() {
return true;
}
public static function get_tablerenderer_title_js_string() {
return " formatQualification(row.qualname, row.qualtype, row.institution)";
}
......@@ -1461,10 +1473,10 @@ class ArtefactTypeEducationhistory extends ArtefactTypeResumeComposite {
'size' => 50,
),
'qualdescription' => array(
'type' => 'textarea',
'type' => 'wysiwyg',
'rows' => 10,
'cols' => 50,
'resizable' => false,
'rules' => array('maxlength' => 65536),
'title' => get_string('qualdescription', 'artefact.resume'),
),
'attachments' => array(
......@@ -1566,6 +1578,10 @@ class ArtefactTypeCertification extends ArtefactTypeResumeComposite {
";
}
public static function is_wysiwyg() {
return true;
}
public static function get_tablerenderer_title_js_string() {
return "row.title";
}
......@@ -1603,10 +1619,10 @@ class ArtefactTypeCertification extends ArtefactTypeResumeComposite {
'size' => 20,
),
'description' => array(
'type' => 'textarea',
'type' => 'wysiwyg',
'rows' => 10,
'cols' => 50,
'resizable' => false,
'rules' => array('maxlength' => 65536),
'title' => get_string('description'),
),
'attachments' => array(
......@@ -1681,6 +1697,10 @@ class ArtefactTypeBook extends ArtefactTypeResumeComposite {
";
}
public static function is_wysiwyg() {
return true;
}
public static function get_tablerenderer_title_js_string() {
return "row.title + ' (' + row.contribution + ')'";
}
......@@ -1733,10 +1753,10 @@ EOF;
'size' => 50,
),
'description' => array(
'type' => 'textarea',
'type' => 'wysiwyg',
'rows' => 10,
'cols' => 50,
'resizable' => false,
'rules' => array('maxlength' => 65536),
'title' => get_string('detailsofyourcontribution', 'artefact.resume'),
),
'attachments' => array(
......@@ -1817,6 +1837,10 @@ class ArtefactTypeMembership extends ArtefactTypeResumeComposite {
";
}
public static function is_wysiwyg() {
return true;
}
public static function get_tablerenderer_title_js_string() {
return "row.title";
}
......@@ -1859,10 +1883,10 @@ class ArtefactTypeMembership extends ArtefactTypeResumeComposite {
'size' => 50,
),
'description' => array(
'type' => 'textarea',
'type' => 'wysiwyg',
'rows' => 10,
'cols' => 50,
'resizable' => false,
'rules' => array('maxlength' => 65536),
'title' => get_string('description', 'artefact.resume'),
),
'attachments' => array(
......
......@@ -12,5 +12,5 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2013072900;
$config->release = '1.0.2';
$config->version = 2017030600;
$config->release = '1.0.3';
......@@ -78,7 +78,7 @@
<div id="book-content-{$row->id}{if $artefactid}-{$artefactid}{/if}" class="collapse resume-content">
{if $row->description}
<p class="content-text">
{$row->description}
{$row->description|safe}
</p>
{/if}
......
......@@ -79,7 +79,7 @@
<div id="certification-content-{$row->id}{if $artefactid}-{$artefactid}{/if}" class="collapse resume-content">
{if $row->description}
<p class="content-text">
{$row->description}
{$row->description|safe}
</p>
{/if}
......
......@@ -79,7 +79,7 @@
<div id="education-content-{$row->id}{if $artefactid}-{$artefactid}{/if}" class="collapse resume-content">
{if $row->qualdescription}
<p class="content-text">
{$row->qualdescription}
{$row->qualdescription|safe}
</p>
{/if}
......
......@@ -78,7 +78,7 @@
<div id="employment-content-{$row->id}{if $artefactid}-{$artefactid}{/if}" class="collapse resume-content">
{if $row->positiondescription}
<p class="content-text">
{$row->positiondescription}
{$row->positiondescription|safe}
</p>
{/if}
......
......@@ -82,7 +82,7 @@
<div id="membership-content-{$row->id}{if $artefactid}-{$artefactid}{/if}" class="collapse resume-content">
{if $row->description}
<p class="content-text">
{$row->description}
{$row->description|safe}
</p>
{/if}
......
......@@ -34,7 +34,7 @@ Scenario: Editing admin resume page (Bug 1426983)
And I follow "Education and employment"
# Adding Education history
And I press "addeducationhistorybutton"
And I fill in the following:
And I set the following fields to these values:
| addeducationhistory_startdate | 1 Jan 2009 |
| addeducationhistory_enddate | 2 Dec 2010 |
| addeducationhistory_institution | something |
......@@ -48,7 +48,7 @@ Scenario: Editing admin resume page (Bug 1426983)
And I click on "addeducationhistory_submit"
And I should see "Saved successfully"
And I press "addeducationhistorybutton"
And I fill in the following:
And I set the following fields to these values:
| addeducationhistory_startdate | 1 Jan 2009 |
| addeducationhistory_enddate | 2 Dec 2010 |
| addeducationhistory_institution | this is an institution |
......@@ -64,7 +64,7 @@ Scenario: Editing admin resume page (Bug 1426983)
And I click on "Move up" in "something" row
# Adding an Employment history
And I press "addemploymenthistorybutton"
And I fill in the following:
And I set the following fields to these values:
| addemploymenthistory_startdate | 1 Jan 2009 |
| addemploymenthistory_enddate | 02 Dec 2010 |
| addemploymenthistory_employer | Test |
......@@ -77,7 +77,7 @@ Scenario: Editing admin resume page (Bug 1426983)
And I click on "addemploymenthistory_submit"
Then I should see "Saved successfully"
And I press "addemploymenthistorybutton"
And I fill in the following:
And I set the following fields to these values:
| addemploymenthistory_startdate | 1 Jan 2009 |
| addemploymenthistory_enddate | 02 Dec 2010 |
| addemploymenthistory_employer | asdhgol |
......
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