From 637758412c31183b52ed9e26296a8f009933efa1 Mon Sep 17 00:00:00 2001 From: Luka Oman Date: Tue, 13 Jun 2017 13:27:46 +0200 Subject: [PATCH] ADD SHORTCODES AND DISPLAY THEM INTO ARTICLE Changes: + add editor field to the backend, + user can insert text, + user can insert shortcodes, + shortcodes are converted to the custom field data, + data is displayed on the frontend. --- helper.php | 7 +++++++ mod_custom_fields.php | 8 +++++++- mod_custom_fields.xml | 18 ++++++++++++++++-- tmpl/default.php | 29 +++++++++++++++++++++++++---- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/helper.php b/helper.php index f494f69..bf9b301 100644 --- a/helper.php +++ b/helper.php @@ -55,6 +55,13 @@ public static function getFields() { // Paste results to the tmpl return $result; } + + // Use input from settings to display and design the selected fields on the module + public static function getParams($getFieldsParams) { + + $result = $getFieldsParams; + return $result; + } } diff --git a/mod_custom_fields.php b/mod_custom_fields.php index 3dec536..96e67ae 100644 --- a/mod_custom_fields.php +++ b/mod_custom_fields.php @@ -22,9 +22,15 @@ $input = JFactory::getApplication()->input; $articleId = $input->getInt('id'); -// Send the id to helper for processing +// Send the id to helper for processing article related custom fields $sendIdToHelper = modCustomFieldsHelper::getId($articleId); + +// Get all the custom fields on the page $sendFieldsToHelper = modCustomFieldsHelper::getFields(); +// Use input from settings to display and design the selected fields on the module +$getFieldsParams = $params->get('editorFields'); +$sendParamsToHelper = modCustomFieldsHelper::getParams($getFieldsParams); + require JModuleHelper::getLayoutPath('mod_custom_fields'); diff --git a/mod_custom_fields.xml b/mod_custom_fields.xml index 4a12c0e..97ddde4 100644 --- a/mod_custom_fields.xml +++ b/mod_custom_fields.xml @@ -1,8 +1,8 @@ - + Custom Fields Module Luka Oman - 0.2.0 + 0.3.0 A module that will display content of selected custom fields of the displayed article. @@ -14,4 +14,18 @@ tmpl/index.html + + +
+ +
+
+
+
diff --git a/tmpl/default.php b/tmpl/default.php index 4c8f5a1..1a7a2f3 100644 --- a/tmpl/default.php +++ b/tmpl/default.php @@ -72,10 +72,31 @@ } } - // display the fields in the module - echo "
"; + // display the content of the editor in the module + $strContent = $sendParamsToHelper; + $strNewContent = $strContent; + $len = 0; - print_r($arrArticleFields); - echo "
"; + for ( $i=0; $i < substr_count($strContent, "{field "); $i++ ) { + // Get field ID from the shortcodes + $fieldId = substr($strContent, strpos($strContent, "{field ", $len) + 7, strpos($strContent, "}", $len) - strpos($strContent, "{field ", $len) - 7); + + // Get custom field label and values for this shortcode + $strFieldValue = $arrArticleFields[$arrLabels[$fieldId]]; + $strFieldName = $arrLabels[$fieldId]; + + // Check if field actually exists + if ( array_key_exists($fieldId, $arrLabels) ) { + // replace shortcode with field value + $strNewContent = str_replace("{field " . $fieldId . "}", $strFieldValue . " ", $strNewContent); + } + + // Let's move to the next field + $len = strpos($strContent, "}", $len) + 1; + + } + + // Display content without shortcodes + echo $strNewContent; ?>