';
}
public static function label_for($key) { return self::label($key); }
private static function control($key, $field, array $cfg, $named = false) {
$choices = self::choices($key);
$addr = 'data-field="' . $field . '"' . ($named ? ' name="' . $field . '"' : '');
if (!empty($choices)) {
echo '';
return;
}
if (is_bool($cfg[$key])) {
echo '';
return;
}
if (is_string($cfg[$key])) {
echo '';
return;
}
$step = ('cartMin' === $key) ? '0.01' : '1';
echo '';
}
private static function choices($key) {
switch ($key) {
case 'trigger':
return array(
'load' => __('As soon as the page loads', 'ai-eshop-optimizer'),
'delay' => __('After a delay', 'ai-eshop-optimizer'),
'scroll' => __('At a scroll depth', 'ai-eshop-optimizer'),
'idle' => __('After the visitor goes idle', 'ai-eshop-optimizer'),
'exit' => __('On exit intent', 'ai-eshop-optimizer'),
'approach' => __('When it comes into view (recommended)', 'ai-eshop-optimizer'),
'interaction' => __('On the first interaction with the page', 'ai-eshop-optimizer'),
);
case 'freq':
return array(
'always' => __('Every time', 'ai-eshop-optimizer'),
'session' => __('Once per browser session', 'ai-eshop-optimizer'),
'once' => __('Once ever', 'ai-eshop-optimizer'),
'days' => __('Once every N days', 'ai-eshop-optimizer'),
);
case 'device':
return array(
'all' => __('All devices', 'ai-eshop-optimizer'),
'desktop' => __('Desktop only', 'ai-eshop-optimizer'),
'mobile' => __('Mobile only', 'ai-eshop-optimizer'),
);
case 'visitor':
return array(
'all' => __('Everyone', 'ai-eshop-optimizer'),
'guest' => __('Logged-out visitors', 'ai-eshop-optimizer'),
'logged_in' => __('Logged-in customers', 'ai-eshop-optimizer'),
'new' => __('First-time visitors', 'ai-eshop-optimizer'),
'returning' => __('Returning visitors', 'ai-eshop-optimizer'),
);
case 'cart':
return array(
'any' => __('Any cart', 'ai-eshop-optimizer'),
'empty' => __('Empty cart', 'ai-eshop-optimizer'),
'has_items' => __('Cart has items', 'ai-eshop-optimizer'),
'min_total' => __('Cart is over a minimum', 'ai-eshop-optimizer'),
);
case 'instigator':
return array(
'any' => __('However they arrived', 'ai-eshop-optimizer'),
'web_push' => __('From a web push notification', 'ai-eshop-optimizer'),
'newsletter' => __('From an email or newsletter', 'ai-eshop-optimizer'),
'paid' => __('From a paid ad', 'ai-eshop-optimizer'),
'referral' => __('From another site or a collaborator', 'ai-eshop-optimizer'),
'direct' => __('Typed the address or used a bookmark', 'ai-eshop-optimizer'),
);
}
return array();
}
private static function label($key) {
$map = array(
'trigger' => __('Show it', 'ai-eshop-optimizer'),
'delayMs' => __('Delay (ms)', 'ai-eshop-optimizer'),
'scrollPct' => __('Scroll depth (%)', 'ai-eshop-optimizer'),
'idleS' => __('Idle time (seconds)', 'ai-eshop-optimizer'),
'rootMargin' => __('Load it this early (px)', 'ai-eshop-optimizer'),
'reserveHeight' => __('Hold space for it (px)', 'ai-eshop-optimizer'),
'freq' => __('How often', 'ai-eshop-optimizer'),
'freqDays' => __('Every N days', 'ai-eshop-optimizer'),
'maxImpr' => __('Lifetime limit', 'ai-eshop-optimizer'),
'maxPerSession' => __('Times per session', 'ai-eshop-optimizer'),
'device' => __('Devices', 'ai-eshop-optimizer'),
'visitor' => __('Who sees it', 'ai-eshop-optimizer'),
'cart' => __('Cart state', 'ai-eshop-optimizer'),
'cartMin' => __('Cart minimum', 'ai-eshop-optimizer'),
'audience' => __('Saved audience', 'ai-eshop-optimizer'),
'instigator' => __('What sent them here', 'ai-eshop-optimizer'),
'instigatorRef' => __('Which campaign or collaborator', 'ai-eshop-optimizer'),
'priority' => __('Priority', 'ai-eshop-optimizer'),
'test' => __('Test mode', 'ai-eshop-optimizer'),
);
return isset($map[$key]) ? $map[$key] : $key;
}
private static function checkbox_text($key) {
if ('test' === $key) {
return __('Show it to me on every page, ignoring every rule below. Records no analytics.', 'ai-eshop-optimizer');
}
return __('Enabled', 'ai-eshop-optimizer');
}
private static function help($key) {
switch ($key) {
case 'trigger':
return __('"When it comes into view" is the fastest option: a block the visitor never scrolls to costs them nothing at all, because nothing it needs is downloaded until it is nearly on screen.', 'ai-eshop-optimizer');
case 'rootMargin':
return __('How far below the fold to start loading, so it is ready by the time the visitor reaches it. Larger is smoother but starts the download sooner.', 'ai-eshop-optimizer');
case 'reserveHeight':
return __('Keeps the page from jumping while the content loads. Space is held only when this block is actually going to appear, so a visitor who has already seen it as many times as you allow gets no empty gap. It is used on the FIRST view only: after that the browser remembers the real height, separately for phones and desktops, and uses that instead. Enter roughly how tall it is ON A PHONE if that is where most of your visitors are.', 'ai-eshop-optimizer');
case 'maxPerSession':
return __('How many times this block may appear while the visitor keeps their browser open. 0 means no limit. It is counted per BLOCK, not per page view, so pages that never contained it do not use up the allowance.', 'ai-eshop-optimizer');
case 'maxImpr':
return __('A cap across the visitor\'s whole history, on top of whichever "How often" rule is chosen. 0 means no limit.', 'ai-eshop-optimizer');
case 'freqDays':
return __('Only used when "How often" is set to "Once every N days".', 'ai-eshop-optimizer');
case 'delayMs':
return __('1000 ms is one second. Only used by the "After a delay" trigger.', 'ai-eshop-optimizer');
case 'priority':
return __('When two blocks want the screen at the same moment, the lower number wins.', 'ai-eshop-optimizer');
case 'audience':
return __('The id of a saved audience. Leave at 0 for everybody. Logged-out visitors never match an audience.', 'ai-eshop-optimizer');
case 'cartMin':
return __('Only used when "Cart state" is set to "Cart is over a minimum".', 'ai-eshop-optimizer');
case 'instigator':
return __('Show this only to visitors who arrived a particular way. The visit is remembered for 30 minutes, so it still applies once they have clicked through to a second page.', 'ai-eshop-optimizer');
case 'instigatorRef':
return __('Optional. Narrows the rule to one campaign or collaborator — enter any part of the tag on their links, e.g. the campaign name or their code. Leave empty for all of them. Matching ignores capitals.', 'ai-eshop-optimizer');
}
return '';
}
public static function collect($row, $stored = array(), $prefix = 'cond_') {
$row = is_array($row) ? $row : array();
$merged = is_array($stored) ? $stored : array();
$len = strlen($prefix);
foreach ($row as $k => $v) {
if (strncmp((string) $k, $prefix, $len) !== 0) { continue; }
$merged[substr((string) $k, $len)] = $v;
}
return AIEO_Display_Conditions::sanitize($merged);
}
}