|
@@ -93,7 +93,7 @@ function fgcf_odt_replace_term_1st_level($segment, $term) {
|
|
$term_nodes = nat_get_nids(array($term->tid), TRUE);
|
|
$term_nodes = nat_get_nids(array($term->tid), TRUE);
|
|
if ($term_node = current($term_nodes)) {
|
|
if ($term_node = current($term_nodes)) {
|
|
$file = $term_node->field_fgcf_thematique_logo[0]['filepath'];
|
|
$file = $term_node->field_fgcf_thematique_logo[0]['filepath'];
|
|
-// $segment->setImage('thematique_1_image', $file);
|
|
|
|
|
|
+ $segment->setImage('thematique_1_image', $file);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -134,15 +134,12 @@ function fgcf_odt_replace_node_formation($segment, $node) {
|
|
|
|
|
|
// formation_objectif
|
|
// formation_objectif
|
|
if (!empty($node->field_fgcf_fiche_objectif[0]['value'])) {
|
|
if (!empty($node->field_fgcf_fiche_objectif[0]['value'])) {
|
|
- $replace['formation_objectif'] = check_markup($node->field_fgcf_fiche_objectif[0]['value'], $node->field_fgcf_fiche_objectif[0]['format']);
|
|
|
|
|
|
+ $replace['formation_objectif'] = _fgcf_odt_handle_markdown($node->field_fgcf_fiche_objectif[0]['value']);
|
|
}
|
|
}
|
|
|
|
|
|
// formation_contenu
|
|
// formation_contenu
|
|
- // @todo bug sur certains nodes 220
|
|
|
|
if (!empty($node->field_fgcf_fiche_contenu[0]['value'])) {
|
|
if (!empty($node->field_fgcf_fiche_contenu[0]['value'])) {
|
|
- // @todo Do not translate markdown syntax - only replace bullet points
|
|
|
|
- $replace['formation_contenu'] = $node->field_fgcf_fiche_contenu[0]['value'];
|
|
|
|
- //$replace['formation_contenu'] = check_markup($node->field_fgcf_fiche_contenu[0]['value'], $node->field_fgcf_fiche_contenu[0]['format']);
|
|
|
|
|
|
+ $replace['formation_contenu'] = _fgcf_odt_handle_markdown($node->field_fgcf_fiche_contenu[0]['value']);
|
|
}
|
|
}
|
|
|
|
|
|
// formation_organisme
|
|
// formation_organisme
|
|
@@ -192,54 +189,26 @@ function fgcf_odt_replace_node_formation($segment, $node) {
|
|
}
|
|
}
|
|
|
|
|
|
// formation_format
|
|
// formation_format
|
|
- $values = array();
|
|
|
|
- foreach ((array) $node->field_fgcf_fiche_format as $item) {
|
|
|
|
- $tid = $item['value'];
|
|
|
|
- if ($term = taxonomy_get_term($tid)) {
|
|
|
|
- $values[] = check_plain($term->name);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ $values = _fgcf_odt_handle_taxonomy_field((array) $node->field_fgcf_fiche_format);
|
|
if ($values) {
|
|
if ($values) {
|
|
- // @todo : liste en items ?
|
|
|
|
$replace['formation_format'] = implode(', ', $values);
|
|
$replace['formation_format'] = implode(', ', $values);
|
|
}
|
|
}
|
|
|
|
|
|
// formation_support
|
|
// formation_support
|
|
- $values = array();
|
|
|
|
- foreach ((array) $node->field_fgcf_fiche_supports as $item) {
|
|
|
|
- $tid = $item['value'];
|
|
|
|
- if ($term = taxonomy_get_term($tid)) {
|
|
|
|
- $values[] = check_plain($term->name);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ $values = _fgcf_odt_handle_taxonomy_field((array) $node->field_fgcf_fiche_supports);
|
|
if ($values) {
|
|
if ($values) {
|
|
- // @todo : liste en items ?
|
|
|
|
$replace['formation_support'] = implode(', ', $values);
|
|
$replace['formation_support'] = implode(', ', $values);
|
|
}
|
|
}
|
|
|
|
|
|
// formation_sanction
|
|
// formation_sanction
|
|
- $values = array();
|
|
|
|
- foreach ((array) $node->field_fgcf_fiche_sanction as $item) {
|
|
|
|
- $tid = $item['value'];
|
|
|
|
- if ($term = taxonomy_get_term($tid)) {
|
|
|
|
- $values[] = check_plain($term->name);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ $values = _fgcf_odt_handle_taxonomy_field((array) $node->field_fgcf_fiche_sanction);
|
|
if ($values) {
|
|
if ($values) {
|
|
- // @todo : liste en items ?
|
|
|
|
$replace['formation_sanction'] = implode(', ', $values);
|
|
$replace['formation_sanction'] = implode(', ', $values);
|
|
}
|
|
}
|
|
|
|
|
|
// formation_public
|
|
// formation_public
|
|
- $values = array();
|
|
|
|
- foreach ((array) $node->field_fgcf_fiche_public as $item) {
|
|
|
|
- $tid = $item['value'];
|
|
|
|
- if ($term = taxonomy_get_term($tid)) {
|
|
|
|
- $values[] = check_plain($term->name);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ $values = _fgcf_odt_handle_taxonomy_field((array) $node->field_fgcf_fiche_public);
|
|
if ($values) {
|
|
if ($values) {
|
|
- // @todo : liste en items ?
|
|
|
|
$replace['formation_public'] = implode(', ', $values);
|
|
$replace['formation_public'] = implode(', ', $values);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -261,6 +230,9 @@ function fgcf_odt_replace_node_formation($segment, $node) {
|
|
_fgcf_odt_replace_segment($segment, $replace);
|
|
_fgcf_odt_replace_segment($segment, $replace);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Helper function : perform pattern replacements in the template.
|
|
|
|
+ */
|
|
function _fgcf_odt_replace_segment($segment, $replace) {
|
|
function _fgcf_odt_replace_segment($segment, $replace) {
|
|
foreach ($replace as $key => $value) {
|
|
foreach ($replace as $key => $value) {
|
|
try {
|
|
try {
|
|
@@ -273,86 +245,30 @@ function _fgcf_odt_replace_segment($segment, $replace) {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Stolen and adapted from markdown.php :
|
|
|
|
- * Form HTML ordered (numbered) and unordered (bulleted) lists.
|
|
|
|
|
|
+ * Helper function : handle formatted text with markdown syntax.
|
|
|
|
+ *
|
|
|
|
+ * Do not translate markdown syntax - only replace bullet lists.
|
|
*/
|
|
*/
|
|
-function doLists($text) {
|
|
|
|
- $less_than_tab = $this->tab_width - 1;
|
|
|
|
-
|
|
|
|
- # Re-usable patterns to match list item bullets and number markers:
|
|
|
|
- $marker_ul_re = '[*+-]';
|
|
|
|
- $marker_ol_re = '\d+[.]';
|
|
|
|
- $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)";
|
|
|
|
-
|
|
|
|
- $markers_relist = array(
|
|
|
|
- $marker_ul_re => $marker_ol_re,
|
|
|
|
- $marker_ol_re => $marker_ul_re,
|
|
|
|
- );
|
|
|
|
|
|
+function _fgcf_odt_handle_markdown($value) {
|
|
|
|
+ // Remove trailing linefeeds.
|
|
|
|
+ $value = trim($value);
|
|
|
|
+ $value = check_plain($value);
|
|
|
|
+ // Simple whitespace chars are munged together in the final doc, so we insert an explicit spacing tag.
|
|
|
|
+ $value = preg_replace('|^(\s*)\*|em', '"<text:s text:c=\"" . ( 2 * strlen("$1") ) . "\"/>" . "-"', $value);
|
|
|
|
+
|
|
|
|
+ return $value;
|
|
|
|
+}
|
|
|
|
|
|
- foreach ($markers_relist as $marker_re => $other_marker_re) {
|
|
|
|
- # Re-usable pattern to match any entirel ul or ol list:
|
|
|
|
- $whole_list_re = '
|
|
|
|
- ( # $1 = whole list
|
|
|
|
- ( # $2
|
|
|
|
- ([ ]{0,'.$less_than_tab.'}) # $3 = number of spaces
|
|
|
|
- ('.$marker_re.') # $4 = first list item marker
|
|
|
|
- [ ]+
|
|
|
|
- )
|
|
|
|
- (?s:.+?)
|
|
|
|
- ( # $5
|
|
|
|
- \z
|
|
|
|
- |
|
|
|
|
- \n{2,}
|
|
|
|
- (?=\S)
|
|
|
|
- (?! # Negative lookahead for another list item marker
|
|
|
|
- [ ]*
|
|
|
|
- '.$marker_re.'[ ]+
|
|
|
|
- )
|
|
|
|
- |
|
|
|
|
- (?= # Lookahead for another kind of list
|
|
|
|
- \n
|
|
|
|
- \3 # Must have the same indentation
|
|
|
|
- '.$other_marker_re.'[ ]+
|
|
|
|
- )
|
|
|
|
- )
|
|
|
|
- )
|
|
|
|
- '; // mx
|
|
|
|
-
|
|
|
|
- # We use a different prefix before nested lists than top-level lists.
|
|
|
|
- # See extended comment in _ProcessListItems().
|
|
|
|
-
|
|
|
|
- if ($this->list_level) {
|
|
|
|
- $text = preg_replace_callback('{
|
|
|
|
- ^
|
|
|
|
- '.$whole_list_re.'
|
|
|
|
- }mx',
|
|
|
|
- array(&$this, '_doLists_callback'), $text);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $text = preg_replace_callback('{
|
|
|
|
- (?:(?<=\n)\n|\A\n?) # Must eat the newline
|
|
|
|
- '.$whole_list_re.'
|
|
|
|
- }mx',
|
|
|
|
- array(&$this, '_doLists_callback'), $text);
|
|
|
|
|
|
+/**
|
|
|
|
+ * Helper function : handle values in taxonomy fields.
|
|
|
|
+ */
|
|
|
|
+function _fgcf_odt_handle_taxonomy_field($items) {
|
|
|
|
+ $values = array();
|
|
|
|
+ foreach ($items as $item) {
|
|
|
|
+ $tid = $item['value'];
|
|
|
|
+ if ($term = taxonomy_get_term($tid)) {
|
|
|
|
+ $values[] = check_plain($term->name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- return $text;
|
|
|
|
-}
|
|
|
|
-function _doLists_callback($matches) {
|
|
|
|
- # Re-usable patterns to match list item bullets and number markers:
|
|
|
|
- $marker_ul_re = '[*+-]';
|
|
|
|
- $marker_ol_re = '\d+[.]';
|
|
|
|
- $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)";
|
|
|
|
-
|
|
|
|
- $list = $matches[1];
|
|
|
|
- $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol";
|
|
|
|
-
|
|
|
|
- $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re );
|
|
|
|
-
|
|
|
|
- $list .= "\n";
|
|
|
|
- $result = $this->processListItems($list, $marker_any_re);
|
|
|
|
-
|
|
|
|
- $result = $this->hashBlock("<$list_type>\n" . $result . "</$list_type>");
|
|
|
|
- return "\n". $result ."\n\n";
|
|
|
|
|
|
+ return $values;
|
|
}
|
|
}
|