background)) { $style = 'background:' . $affiliateLink->background; } if (!empty($affiliateLink->color)) { $style = $style . (empty($style) ? '' : ';') . 'color:' . $affiliateLink->color; } return empty($style) ? '' : 'style="' . $style . '"'; } // Generate tables (responsive and not) static function generate_table($table) { $tableId = $table->getId(); $isTableWithColumnHeader = in_array($table->getHeaderType(), array('COLUMN_HEADER', 'BOTH')); $isTableWithRowHeader = in_array($table->getHeaderType(), array('ROW_HEADER', 'BOTH')); $isTableWithBothHeader = $table->getHeaderType() === 'BOTH'; $columnCount = count($table->getContent()[0]) + ($isTableWithBothHeader ? 1 : 0); $columnHeaderStyle = $isTableWithColumnHeader ? AFES_GenerationUtils::get_header_style(AFES_Constants::COLUMN, $table->getHeaderOptions()) : null; $rowHeaderStyle = $isTableWithRowHeader ? AFES_GenerationUtils::get_header_style(AFES_Constants::ROW, $table->getHeaderOptions()) : null; $responsiveBreakpoint = $table->getResponsiveBreakpoint(); $isResponsiveTable = is_numeric($responsiveBreakpoint) && $responsiveBreakpoint > 0; if ($isResponsiveTable) { ?> getId())) { $rel = []; if ($link->isNoFollow() === "1") { $rel[] = 'nofollow'; } if ($link->isOpenInNewTab()) { $rel[] = 'noopener'; } ?> isOpenInNewTab() ? 'target="_blank"' : ''; ?> 0 ? 'rel="' . esc_attr(implode(' ', $rel)) . '"' : ''; ?>>getLabel()); ?>
getMaxWidth(), $columnCount); ?>>
>
getBackgroundColor(); for ($i = 0; $i < count($table->getContent()); $i++) { $rowContent = $table->getContent()[$i]; for ($j = 0; $j < count($rowContent); $j++) { $cellContent = $rowContent[$j]; $cellType = isset($cellContent->type) ? $cellContent->type : null; $cellValue = isset($cellContent->value) ? AFES_GenerationUtils::format_html_content($cellContent->value) : null; if ($cellType === AFES_Constants::AFFILIATION && ($j !== 0 || !$isTableWithRowHeader)) { AFES_GenerationUtils::generate_affiliate_links_cell_content($cellValue, AFES_GenerationUtils::get_background_color_style_or_empty($backgroundColor), false); ?>
>
getHeaderType()) { case 'ROW_HEADER': AFES_GenerationUtils::generate_responsive_table_row($table, $rowHeaderStyle); break; case 'BOTH': AFES_GenerationUtils::generate_responsive_table_both($table, $columnHeaderStyle, $rowHeaderStyle); break; default : AFES_GenerationUtils::generate_responsive_table_column_or_none($table, $columnHeaderStyle); break; } } private static function generate_responsive_table_row($table, $rowHeaderStyle) { $tableContent = $table->getContent(); ?>
> value); ?>
type) ? $cellContent->type : null; $cellValue = isset($cellContent->value) ? AFES_GenerationUtils::format_html_content($cellContent->value) : null; $backgroundColor = AFES_GenerationUtils::get_background_color_style_or_empty($table->getBackgroundColor()); if ($cellType === AFES_Constants::AFFILIATION) { AFES_GenerationUtils::generate_affiliate_links_cell_content($cellValue, $backgroundColor, true); } else { ?>
>
getContent(); ?>
> value); ?>
> value); ?>
type) ? $cellContent->type : null; $cellValue = isset($cellContent->value) ? AFES_GenerationUtils::format_html_content($cellContent->value) : null; $backgroundColor = AFES_GenerationUtils::get_background_color_style_or_empty($table->getBackgroundColor()); if ($cellType === AFES_Constants::AFFILIATION) { AFES_GenerationUtils::generate_affiliate_links_cell_content($cellValue, $backgroundColor, true); } else { ?>
getBackgroundColor()); ?>>
getContent(); $isColumnTable = $table->getHeaderType() === 'COLUMN_HEADER'; ?>
> value); ?>
type) ? $cellContent->type : null; $cellValue = isset($cellContent->value) ? AFES_GenerationUtils::format_html_content($cellContent->value) : null; $backgroundColor = AFES_GenerationUtils::get_background_color_style_or_empty($table->getBackgroundColor()); if ($cellType === AFES_Constants::AFFILIATION) { AFES_GenerationUtils::generate_affiliate_links_cell_content($cellValue, $backgroundColor, false); } else { ?>
>
0) { $style = 'max-width: ' . $maxWidth . 'px!important;'; } return 'style="' . $style . 'grid-template-columns: repeat(' . $columnCount . ', auto);"'; } private static function get_header_style($headerType, $headerOptions) { $headerStyle = ''; foreach ((array)$headerOptions as $key => $value) { if (!empty($value) && preg_match('#^' . $headerType . '#i', $key) === 1) { $headerStyle .= (empty($headerStyle) ? '' : ';') . str_replace(strtolower($headerType) . '-', '', $key) . ':' . $value; } } return $headerStyle === '' ? '' : 'style="' . $headerStyle . '"'; } private static function get_style_to_apply( $i, $j, $backgroundColor, $isTableWithColumnHeader, $isTableWithRowHeader, $columnHeaderStyle, $rowHeaderStyle) { if ($isTableWithColumnHeader && $i === 0) { return $columnHeaderStyle; } if ($j === 0 && ($isTableWithRowHeader && $i !== 0 || $isTableWithRowHeader && !$isTableWithColumnHeader)) { return $rowHeaderStyle; } return AFES_GenerationUtils::get_background_color_style_or_empty($backgroundColor); } private static function get_background_color_style_or_empty($backgroundColor) { return empty($backgroundColor) ? '' : 'style="background:' . $backgroundColor . '!important"'; } private static function format_html_content($content) { return AFES_GenerationUtils::replace_placeholders(str_replace('&NewLine;', '', str_replace('"', '"', $content))); } private static function replace_placeholders($content) { foreach (AFES_Constants::AVAILABLE_ICONS as $key => $value) { $content = str_replace($key, '', $content); } return $content; } }