displaytype = table by default * $parameter->cols = 1 by default */ public function getFormattedResult(array $elements, object $parameter): string { //We do not add an extra table or whatever when there is a single element... if (count($elements) < 2) { return implode('', $elements); } $beforeAll = []; $beforeAll['table'] = '
| '."\n";
$beforeOne['ul'] = ' | '."\n";
$afterOne['ul'] = ''."\n";
$afterOne['br'] = '
',
$text
);
$text = preg_replace(
'##i',
'
',
$text
);
$text = preg_replace(
'#{JoooidContent[^}]*youtube[^}]*id"[^"]*"([^}"]*)"[^}]*}#i',
'
',
$text
);
$text = preg_replace(
'##Uis',
'
',
$text
);
$text = preg_replace(
'#{youtube}[^{]+v=([^{&]+)(&[^{]*)?{/youtube}#Uis',
'
',
$text
);
$text = preg_replace('#{vimeo}(https://vimeo.com/[^{]+){/vimeo}#Uis', '', $text);
$text = preg_replace('#{vimeo}([^{]+){/vimeo}#Uis', '', $text);
// Vimeo iframes
if (preg_match_all('##Uis', $text, $matches)) {
foreach ($matches[1] as $key => $match) {
$hash = acym_fileGetContent('https://vimeo.com/api/v2/video/'.$match.'.php');
// @ on purpose, the unserialize returns false if $hash isn't a serialized data, but it also throws a notice...
$hash = @unserialize($hash);
if (empty($hash)) continue;
if (strpos($matches[0][$key], ' width="') !== false) {
$extension = substr($hash[0]['thumbnail_large'], strrpos($hash[0]['thumbnail_large'], '.'));
preg_match('#width="([^"]*)"#Uis', $matches[0][$key], $width);
$replace = strpos($hash[0]['thumbnail_large'], '_') === false ? '.' : '_';
$hash[0]['thumbnail_large'] = substr($hash[0]['thumbnail_large'], 0, strrpos($hash[0]['thumbnail_large'], $replace)).'_'.$width[1].$extension;
}
$thumbnail = 'https://i.vimeocdn.com/filter/overlay?src='.urlencode($hash[0]['thumbnail_large']);
$thumbnail .= '&src='.urlencode('https://f.vimeocdn.com/p/images/crawler_play.png');
$text = str_replace(
$matches[0][$key],
'
', $text);
$text = preg_replace('##i', '
', $text);
}
/**
* Convert pictures base64 code into a real picture
*/
private function convertbase64pictures(string &$html): void
{
if (!preg_match_all('#]*>)#Uis'] = '$1'; $newbody = preg_replace(array_keys($pregreplace), $pregreplace, $html); //we do it in two steps as this regex can break the page if (!empty($newbody)) { $html = $newbody; } $body = preg_replace_callback('/src="([^"]* [^"]*)"/Ui', [$this, 'convertSpaces'], $html); if (!empty($body)) $html = $body; $html = acym_cmsCleanHtml($html); } public function convertSpaces(array $matches): string { return "src='".str_replace(' ', '%20', $matches[1])."'"; } /* * Replace tags in all the email variables where it is possible, in text version or html version */ public function replaceTags(object &$email, array $tags, bool $html = false): void { if (empty($tags)) return; $htmlVars = ['body']; $textVars = [ 'subject', 'AltBody', 'From', 'FromName', 'ReplyTo', 'ReplyName', 'bcc', 'cc', 'fromname', 'fromemail', 'replyname', 'replyemail', 'params', 'preheader', ]; $variables = array_merge($htmlVars, $textVars); if ($html) { if (empty($this->mailerHelper)) { $this->mailerHelper = new MailerHelper(); } $textreplace = []; foreach ($tags as $i => $replacement) { if (isset($textreplace[$i])) continue; $textreplace[$i] = $this->mailerHelper->textVersion($replacement); } } else { $textreplace = $tags; } foreach ($variables as $var) { if (empty($email->$var)) continue; $email->$var = $this->replaceDText($email->$var, in_array($var, $htmlVars) ? $tags : $textreplace); } } public function replaceDText($text, $replacement) { if (is_array($text)) { foreach ($text as &$oneCell) { if (empty($oneCell)) continue; $oneCell = $this->replaceDText($oneCell, $replacement); } } elseif (is_string($text) && !empty($text)) { foreach ($replacement as $code => $value) { $codes = [$code, urlencode($code)]; if (is_null($value)) { $value = ''; } $safePregValue = str_replace('$', '\$', $value); foreach ($codes as $oneCode) { // Dtext specific syntax $text = preg_replace( '#]+'.preg_quote($oneCode, '#').'.+[^<]*#Uis', $safePregValue, $text ); // Dcontent specific syntax $text = preg_replace( '#(
'.esc_html($format->imageCaption).'
'; } } // If TITLE_IMG, add the image to the title $result = ''; if (in_array($format->tag->format, ['TITLE_IMG', 'TITLE_IMG_RIGHT'])) { $format->title = $image.$format->title; $image = ''; } if (!empty($format->link) && !empty($image) && !empty($format->tag->clickableimg)) { $image = ''.$image.''; } // If the image should be displayed before the title, do it if ($format->tag->format === 'TOP_IMG' && !empty($image)) { $result = $image; $image = ''; } // If we want to keep the left/right column for the image, put the whole article in a table if (in_array($format->tag->format, ['COL_LEFT', 'COL_RIGHT'])) { $maxWidth = empty($format->tag->maxwidth) ? '' : ' width: '.$format->tag->maxwidth.'px;'; if (empty($image)) { $format->tag->format = 'TOP_LEFT'; } else { $result = '';
if ($format->tag->format === 'COL_LEFT') {
$result = '
';
echo esc_html(acym_translation('ACYM_DISPLAY'));
echo ' ';
echo '';
acym_radio(
$valImages,
'pict'.$suffix,
$displayedPictures,
['onclick' => $updateFunction.'();'],
['containerClass' => 'dcontent_pictures'],
!acym_isAdmin()
);
echo ' ';
echo '';
if (!empty($option['caption'])) {
echo '';
echo '';
acym_radio(
[
acym_selectOption('1', 'ACYM_YES'),
acym_selectOption('0', 'ACYM_NO'),
],
'caption'.$suffix,
$defaultValues->caption ?? '0',
['onclick' => $updateFunction.'();'],
['containerClass' => 'cell large-7']
);
echo ' ';
}
}
private function displayCheckboxField(array $option, string $suffix, string $updateFunction): void
{
if (!empty($option['default'])) {
$checkedValues = explode(',', $option['default']);
foreach ($option['options'] as $key => $oneOption) {
$oneOption[1] = in_array($key, $checkedValues);
$option['options'][$key] = $oneOption;
}
}
echo '';
foreach ($option['options'] as $value => $title) {
echo ' ';
}
private function displayRadioField(array $option, string $suffix, string $updateFunction): void
{
$radioOptions = [];
foreach ($option['options'] as $value => $title) {
$radioOptions[] = acym_selectOption($value, $title);
}
acym_radio(
$radioOptions,
$option['name'].$suffix,
$option['default'],
['onclick' => $updateFunction.'();'],
['pluginMode' => true],
!acym_isAdmin()
);
}
private function displaySelectField(array $option, string $suffix, string $updateFunction): void
{
$selectOptions = [];
foreach ($option['options'] as $value => $title) {
if (is_object($title)) {
$selectOptions[] = acym_selectOption($title->value, $title->text);
} else {
$selectOptions[] = acym_selectOption($value, $title);
}
}
$default = empty($option['default']) ? null : $option['default'];
$defaultOrder = null;
if (!empty($default) && strpos($default, ',')) {
[$default, $defaultOrder] = explode(',', $default);
}
$attributes = [
'onchange' => $updateFunction.'();',
'id' => $option['name'].$suffix,
];
if ($option['name'] === 'order') {
$attributes['class'] = 'acym__dynamics__ordering__select';
}
acym_select(
$selectOptions,
$option['name'].$suffix,
$default,
$attributes,
'value',
'text',
null,
false,
true
);
if ($option['name'] === 'order') {
$dirs = [
'desc' => acym_translation('ACYM_DESC'),
'asc' => acym_translation('ACYM_ASC'),
];
if (empty($defaultOrder)) {
$defaultOrder = empty($option['defaultdir']) ? null : $option['defaultdir'];
}
echo ' ';
acym_select(
$dirs,
'orderdir'.$suffix,
$defaultOrder,
[
'onchange' => $updateFunction.'();',
'style' => 'width: 115px;',
'class' => 'acym__dynamics__ordering__select',
],
'value',
'text',
null,
false,
true
);
}
}
private function displayMultiselectField(array $option, string $suffix, string $updateFunction): void
{
$selectOptions = [];
foreach ($option['options'] as $value => $title) {
$selectOptions[] = acym_selectOption($value, $title);
}
if (!isset($option['default'])) {
$option['default'] = [];
}
if (!is_array($option['default'])) {
$option['default'] = explode(',', $option['default']);
}
acym_selectMultiple(
$selectOptions,
$option['name'].$suffix,
$option['default'],
['onchange' => $updateFunction.'();', 'id' => $option['name'].$suffix],
'value',
'text',
true
);
}
private function displayLanguageField(array $option, string $suffix, string $updateFunction): void
{
$languageOptions = ['any' => acym_translation('ACYM_ANY')];
foreach (acym_getLanguages(true) as $language) {
$languageOptions[$language->language] = $language->name;
}
if (empty($option['default'])) {
$option['default'] = acym_getVar('string', 'language');
if (acym_isMultilingual() && (empty($option['default']) || $option['default'] === 'main')) {
$option['default'] = $this->config->get('multilingual_default');
}
}
acym_select(
$languageOptions,
$option['name'].$suffix,
empty($option['default']) ? null : $option['default'],
['onchange' => $updateFunction.'();', 'id' => $option['name'].$suffix],
'value',
'text',
null,
false,
true
);
}
private function displayFormatPanel(string $suffix, string $updateFunction, string $type, $defaultValues): void
{
echo ' $value) {
echo esc_attr($attribute).'="'.esc_attr($value).'"';
}
}
echo '>';
echo '';
echo '';
echo ' ';
}
echo '';
echo ' ';
}
private function appendOptionJs(array &$jsOptionsMerge, array $option, string $suffix, string $type): void
{
switch ($option['type']) {
case 'pictures':
if (!empty($option['caption'])) {
$jsOptionsMerge[] = 'otherinfo += "| caption:" + jQuery(\'input[name="caption'.esc_attr($suffix).'"]:checked\').val();';
}
$jsOptionsMerge[] = '
var _pictVal'.esc_attr($suffix).' = jQuery(\'input[name="pict'.esc_attr($suffix).'"]:checked\').val();
otherinfo += "| pict:" + _pictVal'.esc_attr($suffix).';
if(_pictVal'.esc_attr($suffix).' == "resized"){
jQuery("#pictsize'.esc_attr($suffix).'").show();
otherinfo += "| maxwidth:" + jQuery(\'input[name="pictwidth'.esc_attr($suffix).'"]\').val();
otherinfo += "| maxheight:" + jQuery(\'input[name="pictheight'.esc_attr($suffix).'"]\').val();
}else{
jQuery("#pictsize'.esc_attr($suffix).'").hide();
}';
break;
case 'checkbox':
$separator = empty($option['separator']) ? ',' : $option['separator'];
$jsOptionsMerge[] = 'var _checked'.esc_attr($option['name'].$suffix).' = [];
jQuery("input:checkbox[name='.esc_attr($option['name'].$suffix).']:checked").each(function(){
_checked'.esc_attr($option['name'].$suffix).'.push(jQuery(this).val());
});
if(_checked'.esc_attr($option['name'].$suffix).'.length) otherinfo += "| '.esc_attr($option['name']).':" + _checked'.esc_attr(
$option['name'].$suffix
).'.join("'.esc_attr($separator).'");';
if ($option['title'] === 'ACYM_DISPLAY' && (!isset($option['format']) || $option['format'])) {
if ($type === 'grouped') {
$jsOptionsMerge[] = 'var alternate = jQuery(\'input[name="alternate'.esc_attr($suffix).'"]:checked\').val();';
$jsOptionsMerge[] = 'if (!acym_helper.empty(alternate)) otherinfo += "| alternate";';
}
$jsOptionsMerge[] = 'var selectedFormatOption = jQuery(\'.button-radio-selected[acym-button-radio-group="dcontentFormat'.esc_attr($suffix).'"]\')';
$jsOptionsMerge[] = 'if (!acym_helper.empty(selectedFormatOption)) otherinfo += "| format:" + selectedFormatOption.attr("acym-data-type");';
}
break;
case 'boolean':
case 'radio':
$jsOptionsMerge[] = 'otherinfo += "| '.esc_attr($option['name']).':" + jQuery(\'input[name="'.esc_attr($option['name'].$suffix).'"]:checked\').val();';
break;
case 'select':
if ($option['name'] === 'order') {
$jsOptionsMerge[] = 'otherinfo += "| '.esc_attr($option['name']).':" + jQuery(\'[name="'.esc_attr(
$option['name'].$suffix
).'"]\').val() + "," + jQuery(\'[name="orderdir'.esc_attr($suffix).'"]\').val();';
} else {
$jsOptionsMerge[] = 'otherinfo += "| '.esc_attr($option['name']).':" + jQuery(\'[name="'.esc_attr($option['name'].$suffix).'"]\').val();';
}
break;
case 'language':
$jsOptionsMerge[] = 'otherinfo += "| '.esc_attr($option['name']).':" + jQuery(\'[name="'.esc_attr($option['name'].$suffix).'"]\').val();';
break;
case 'multiselect':
$jsOptionsMerge[] = '
var theMultiSelect = document.querySelector(\'[name="'.esc_attr($option['name'].$suffix).'[]"]\');
var selectedOptions = [];
for(var i = 0 ; i < theMultiSelect.length ; i++){
if(theMultiSelect[i].selected){
selectedOptions.push(theMultiSelect[i].value);
}
}
otherinfo += "| '.esc_attr($option['name']).':" + selectedOptions.join(",");';
break;
case 'text':
case 'number':
case 'intextfield':
case 'date':
$jsOptionsMerge[] = 'otherinfo += "| '.esc_attr($option['name']).':" + jQuery(\'input[name="'.esc_attr($option['name'].$suffix).'"]\').val();';
break;
case 'custom':
//TODO
$jsOptionsMerge[] = $option['js'];
break;
}
}
private function displayDynamicScript(array $jsOptionsMerge, string $suffix, string $updateFunction, string $dynamicIdentifier, string $type, $defaultValues): void
{
$storageVar = 'window._additionalInfo'.$suffix;
echo '';
}
/**
* In Joomla, we can translate elements in extensions using the FaLang extension
*/
public function translateItem(object &$item, object &$tag, string $referenceTable, int $referenceId = 0): void
{
if (!acym_isExtensionActive('com_falang')) {
return;
}
if (!empty($tag->falang)) {
$langId = $tag->falang;
} elseif (!empty($tag->lang)) {
$langId = intval(substr($tag->lang, strpos($tag->lang, ',') + 1));
} elseif (!empty($this->contextLanguage)) {
$languages = acym_loadObjectList('SELECT `lang_id`, `lang_code`, `sef` FROM #__languages');
foreach ($languages as $language) {
if (in_array($this->contextLanguage, [$language->lang_code, $language->sef])) {
$langId = $language->lang_id;
break;
}
}
}
if (empty($langId)) {
return;
}
if (empty($referenceId)) {
$referenceId = $tag->id;
}
$translations = acym_loadObjectList(
'SELECT `reference_field`, `value`
FROM `#__falang_content`
WHERE `published` = 1
AND `reference_table` = '.acym_escapeDB($referenceTable).'
AND `language_id` = '.intval($langId).'
AND `reference_id` = '.intval($referenceId)
);
if (empty($translations)) {
return;
}
foreach ($translations as $oneTranslation) {
if (empty($oneTranslation->value)) {
continue;
}
$translatedField = $oneTranslation->reference_field;
$item->$translatedField = $oneTranslation->value;
}
}
public function createDummyEmailObject(int $mailId, string $code, string $previewBody): object
{
if (!empty($mailId)) {
$mailClass = new MailClass();
$email = $mailClass->getOneById($mailId);
}
if (empty($email)) {
$email = new \stdClass();
$email->id = 0;
$email->name = '';
$email->subject = '';
$email->from_name = '';
$email->from_email = '';
$email->reply_to_name = '';
$email->reply_to_email = '';
$email->bcc = '';
$email->links_language = '';
}
$language = acym_getVar('string', 'language', 'main');
if (!empty($language)) {
if ($language === 'main') {
$language = $this->config->get('multilingual_default', ACYM_DEFAULT_LANGUAGE);
}
$email->links_language = $language;
}
$email->creation_date = acym_date('now', 'Y-m-d H:i:s', false);
$email->creator_id = acym_currentUserId();
$email->thumbnail = '';
$email->drag_editor = '1';
$email->type = MailClass::TYPE_STANDARD;
$email->settings = '';
$email->stylesheet = '';
$email->attachments = '';
// This is only the dynamic text/content code
$email->body = $code;
// This is the whole editor current content
$email->previewBody = $previewBody;
return $email;
}
}
';
echo esc_html(acym_translation('ACYM_FORMAT'));
echo ' ';
echo '';
$default = empty($defaultValues->format) ? 'TOP_LEFT' : $defaultValues->format;
$formats = ['TOP_LEFT', 'TOP_RIGHT', 'TITLE_IMG', 'TITLE_IMG_RIGHT', 'CENTER_IMG', 'TOP_IMG', 'COL_LEFT', 'COL_RIGHT'];
foreach ($formats as $oneFormat) {
$class = 'button-radio';
if ($default === $oneFormat) {
$class .= ' button-radio-selected';
}
echo '';
}
echo ' ';
if ($type === 'grouped') {
echo '';
echo esc_html(acym_translation('ACYM_ALTERNATE'));
acym_info(['textShownInTooltip' => 'ACYM_ALTERNATE_DESC']);
echo ' ';
echo '';
acym_boolean(
'alternate'.$suffix,
!empty($defaultValues->alternate),
'alternate'.$suffix,
['onclick' => $updateFunction.'();']
);
echo ' ';
}
echo ' | |||||||||