Skip to content

Commit

Permalink
ADD SHORTCODES AND DISPLAY THEM INTO ARTICLE
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bubi-luka committed Jun 13, 2017
1 parent 3ba9429 commit 6377584
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
7 changes: 7 additions & 0 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

8 changes: 7 additions & 1 deletion mod_custom_fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

18 changes: 16 additions & 2 deletions mod_custom_fields.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<extension type="module" version="3.1.0" client="site" method="upgrade">
<name>Custom Fields Module</name>
<author>Luka Oman</author>
<version>0.2.0</version>
<version>0.3.0</version>
<description>A module that will display content of selected custom fields of the displayed article.</description>

<files>
Expand All @@ -14,4 +14,18 @@
<filename>tmpl/index.html</filename>
</files>

<config>
<fields name="params">
<fieldset name="basic">
<field
name="editorFields"
type="editor"
label="Insert and edit custom fields"
description="Click on the button and select the desired custom field to be inserted in the editor and in the module."
width="300"
filter="safehtml" />
</fieldset>
</fields>
</config>

</extension>
29 changes: 25 additions & 4 deletions tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,31 @@
}
}

// display the fields in the module
echo "<div style='border 1px solid black'>";
// display the content of the editor in the module
$strContent = $sendParamsToHelper;
$strNewContent = $strContent;
$len = 0;

print_r($arrArticleFields);
echo "</div>";
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;

?>

0 comments on commit 6377584

Please sign in to comment.