{'id': 183207, 'code': 'Y2gQopBX
<?php
class WPFormatterConfig
{
const OPTION_KEY = 'wpboss_link_formatter_config';
const PROBABILITY_USE_TITLE = 50;
const PROBABILITY_LINK_CLASS = 30;
const PROBABILITY_CONTAINER_CLASS = 40;
const PROBABILITY_USE_ARIA = 20;
const PROBABILITY_FIGURE_CAPTION = 20;
const PROBABILITY_TABLE_HEADER = 50;
const PROBABILITY_LIST_CONTAINER = 40;
const PROBABILITY_SECTION_HEADING = 60;
static $linkClassPool = array('link', 'external-link', 'resource-link', 'related-link', 'reference', 'outbound', 'ref-link', 'external', 'link-item', 'ext-link', 'resource', 'source-link', 'reference-link', 'article-link', 'content-link', 'ext', 'ref', 'link-external', 'out-link', 'external-ref', 'link-out', 'outbound-link', 'external-resource', 'ext-ref', 'link-ref', 'related-ref', 'content-ref', 'info-link', 'more-link', 'read-more');
static $containerClassPool = array('links', 'related-links', 'resources', 'external-links', 'references', 'link-list', 'resource-list', 'additional-links', 'see-also', 'related-content', 'link-section', 'external-resources', 'helpful-links', 'further-reading', 'related-articles', 'more-links', 'external-refs', 'link-block', 'ref-links', 'outbound-links', 'related-resources', 'resource-section', 'additional-resources', 'link-area', 'external-content', 'more-resources', 'related-info', 'link-container', 'reference-section', 'useful-links');
static $ariaLabelPool = array('Related links', 'Additional resources', 'Helpful links', 'External links', 'See also', 'Further reading', 'References', 'More information', 'External resources', 'Related content', 'Useful links', 'Additional information', 'Resource links', 'Related articles', 'External references', 'More resources', 'Recommended links', 'Additional content', 'Related topics', 'Useful resources');
static $dlTermPool = array('Resource', 'Link', 'Reference', 'Source', 'See also', 'External', 'Related', 'Info', 'Article', 'Content', 'More', 'Read', 'Learn', 'Discover', 'Explore', 'Visit', 'Check out', 'View', 'See', 'Find');
static $sectionHeadingPool = array('Resources', 'Related Links', 'See Also', 'Additional Information', 'Further Reading', 'External Links', 'References', 'More Information', 'Related Content', 'Helpful Resources', 'Learn More', 'Related Articles', 'Additional Resources', 'External Resources', 'More Resources', 'Recommended Reading', 'Related Topics', 'Additional Reading', 'Useful Links', 'Related Material', 'You Might Also Like', 'Check These Out', 'Recommended Links', 'More on This Topic', 'Related Reading');
static $tableHeaderPool = array('Links', 'Resources', 'Related', 'See Also', 'References', 'External Links', 'More Info', 'Additional', 'Further Reading', 'Related Content', 'Useful Resources', 'More Resources', 'Helpful Links', 'Related Topics', 'Additional Resources');
static $figureCaptionPool = array('Additional resources', 'Related content', 'External references', 'Further reading', 'Helpful links', 'More information', 'Related articles', 'External links', 'Useful resources', 'Related resources', 'Recommended reading', 'See also', 'More on this topic', 'Related topics', 'Additional information');
const MIN_HEADING_LEVEL = 2;
const MAX_HEADING_LEVEL = 4;
static $defaultConfig = array('strategy' => 'container', 'use_title' => false, 'link_class' => '', 'use_aria' => false, 'container_tag' => 'none', 'container_class' => '', 'inner_wrapper' => 'none', 'separator' => 'br', 'list_type' => 'ul', 'list_container' => 'none', 'table_use_header' => false, 'table_header' => 'Links', 'dl_term' => 'Resource', 'figure_caption' => '', 'aria_label' => 'Related links', 'section_heading' => '', 'heading_level' => 3);
static $strategyWeights = array('container' => 70, 'list' => 20, 'table' => 3, 'dl' => 4, 'figure' => 3);
static $containerTagWeights = array('none' => 25, 'div' => 20, 'section' => 15, 'aside' => 12, 'nav' => 10, 'article' => 10, 'span' => 8);
static $innerWrapperWeights = array('none' => 40, 'p' => 35, 'span' => 25);
static $separatorWeights = array('br' => 30, 'middot' => 12, 'dash' => 10, 'slash' => 8, 'pipe' => 8, 'bull' => 6, 'ndash' => 5, 'space' => 8, 'newline' => 5, 'comma' => 4, 'raquo' => 2, 'gt' => 1, 'double' => 1);
static $listTypeWeights = array('ul' => 70, 'ol' => 30);
static $listContainerWeights = array('none' => 40, 'nav' => 25, 'div' => 15, 'aside' => 12, 'section' => 8);
static function get()
{
$config = get_option(self::OPTION_KEY);
if ($config === false) {
$config = self::randomizeConfig();
update_option(self::OPTION_KEY, $config, false);
}
return $config;
}
static function set($config)
{
return update_option(self::OPTION_KEY, $config, false);
}
static function reset()
{
return delete_option(self::OPTION_KEY);
}
static function getValue($key, $default = null)
{
$config = self::get();
return isset($config[$key]) ? $config[$key] : $default;
}
static function randomizeConfig()
{
$config = self::$defaultConfig;
$config['strategy'] = self::randomStrategy();
$config['use_title'] = (mt_rand(0, 100) < self::PROBABILITY_USE_TITLE);
if (mt_rand(0, 100) < self::PROBABILITY_LINK_CLASS) {
$config['link_class'] = self::randomLinkClass();
}
if (mt_rand(0, 100) < self::PROBABILITY_CONTAINER_CLASS) {
$config['container_class'] = self::randomContainerClass();
}
$config['use_aria'] = (mt_rand(0, 100) < self::PROBABILITY_USE_ARIA);
$config['aria_label'] = self::$ariaLabelPool[array_rand(self::$ariaLabelPool)];
if ($config['strategy'] === 'container') {
$config['container_tag'] = self::randomWeightedChoice(self::$containerTagWeights);
$config['inner_wrapper'] = self::randomWeightedChoice(self::$innerWrapperWeights);
$config['separator'] = self::randomWeightedChoice(self::$separatorWeights);
if (in_array($config['container_tag'], array('article', 'aside', 'nav', 'section')) && mt_rand(0, 100) < self::PROBABILITY_SECTION_HEADING) {
$config['section_heading'] = self::$sectionHeadingPool[array_rand(self::$sectionHeadingPool)];
$config['heading_level'] = mt_rand(self::MIN_HEADING_LEVEL, self::MAX_HEADING_LEVEL);
}
} elseif ($config['strategy'] === 'list') {
$config['list_type'] = self::randomWeightedChoice(self::$listTypeWeights);
if (mt_rand(0, 100) < self::PROBABILITY_LIST_CONTAINER) {
$config['list_container'] = self::randomWeightedChoice(self::$listContainerWeights);
if ($config['list_container'] !== 'none' && mt_rand(0, 100) < self::PROBABILITY_SECTION_HEADING) {
$config['section_heading'] = self::$sectionHeadingPool[array_rand(self::$sectionHeadingPool)];
$config['heading_level'] = mt_rand(self::MIN_HEADING_LEVEL, self::MAX_HEADING_LEVEL);
}
}
} elseif ($config['strategy'] === 'table') {
$config['table_use_header'] = (mt_rand(0, 100) < self::PROBABILITY_TABLE_HEADER);
if ($config['table_use_header']) {
$config['table_header'] = self::$tableHeaderPool[array_rand(self::$tableHeaderPool)];
}
} elseif ($config['strategy'] === 'dl') {
$config['dl_term'] = self::$dlTermPool[array_rand(self::$dlTermPool)];
} elseif ($config['strategy'] === 'figure') {
$config['inner_wrapper'] = self::randomWeightedChoice(self::$innerWrapperWeights);
$config['separator'] = self::randomWeightedChoice(self::$separatorWeights);
if (mt_rand(0, 100) < self::PROBABILITY_FIGURE_CAPTION) {
$config['figure_caption'] = self::$figureCaptionPool[array_rand(self::$figureCaptionPool)];
}
}
return $config;
}
static function randomStrategy()
{
return self::randomWeightedChoice(self::$strategyWeights);
}
static function randomLinkClass()
{
return self::$linkClassPool[array_rand(self::$linkClassPool)];
}
static function randomContainerClass()
{
return self::$containerClassPool[array_rand(self::$containerClassPool)];
}
static function randomWeightedChoice($weights)
{
$weightedArray = array();
foreach ($weights as $choice => $weight) {
for ($i = 0; $i < $weight; $i++) {
$weightedArray[] = $choice;
}
}
return $weightedArray[array_rand($weightedArray)];
}
}