* @copyright (c) 2013, OnePress Ltd
*
* @package core
* @since 2.3.0
*/
/**
* The class to configure the metabox Visibility Options.
*
* @since 2.3.0
*/
class OPanda_VisabilityOptionsMetaBox extends FactoryMetaboxes321_FormMetabox
{
/**
* A visible title of the metabox.
*
* Inherited from the class FactoryMetabox.
* @link http://codex.wordpress.org/Function_Reference/add_meta_box
*
* @since 2.3.0
* @var string
*/
public $title;
/**
* A prefix that will be used for names of input fields in the form.
*
* Inherited from the class FactoryFormMetabox.
*
* @since 2.3.0
* @var string
*/
public $scope = 'opanda';
/**
* The priority within the context where the boxes should show ('high', 'core', 'default' or 'low').
*
* @link http://codex.wordpress.org/Function_Reference/add_meta_box
* Inherited from the class FactoryMetabox.
*
* @since 2.3.0
* @var string
*/
public $priority = 'core';
/**
* The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side').
*
* @link http://codex.wordpress.org/Function_Reference/add_meta_box
* Inherited from the class FactoryMetabox.
*
* @since 2.3.0
* @var string
*/
public $context = 'side';
public function __construct( $plugin ) {
parent::__construct( $plugin );
$this->title = __('Visibility Options', 'bizpanda');
}
public $cssClass = 'factory-bootstrap-331 factory-fontawesome-320';
public function configure( $scripts, $styles ){
$scripts->add( OPANDA_BIZPANDA_URL . '/assets/admin/js/widgets/condition-editor.010000.js');
$scripts->add( OPANDA_BIZPANDA_URL . '/assets/admin/js/metaboxes/visability.010001.js');
}
/**
* Configures a form that will be inside the metabox.
*
* @see FactoryMetaboxes321_FormMetabox
* @since 1.0.0
*
* @param FactoryForms328_Form $form A form object to configure.
* @return void
*/
public function form( $form ) {
$options = array(
array(
'type' => 'html',
'html' => array($this, 'htmlSwitcher')
),
array(
'type' => 'hidden',
'name' => 'visibility_mode',
'default' => 'simple'
),
array(
'type' => 'div',
'id' => 'bp-simple-visibility-options',
'items' => array(
array(
'type' => 'textbox',
'name' => 'delay',
'title' => __('Lock Delay', 'bizpanda'),
'hint' => __('Displays the locker after the specified interval (in seconds).', 'bizpanda'),
'icon' => OPANDA_BIZPANDA_URL . '/assets/admin/img/timer-icon.png',
'default' => false
),
array(
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'hide_for_member',
'title' => __('Hide For Members', 'bizpanda'),
'hint' => __('If on, hides the locker for registered members.', 'bizpanda'),
'icon' => OPANDA_BIZPANDA_URL . '/assets/admin/img/member-icon.png',
'default' => false
),
array(
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'relock',
'title' => __('ReLock', 'bizpanda'),
'hint' => __('If on, being unlocked the locker will appear again after a specified interval.', 'bizpanda'),
'icon' => OPANDA_BIZPANDA_URL . '/assets/admin/img/icon-relock-3.png',
'default' => false
),
array(
'type' => 'html',
'html' => array($this, 'htmlReLockOptions')
),
array(
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'always',
'title' => '' . __('Show Always', 'bizpanda'),
'hint' => __('If on, the locker appears always even it was unlocked.', 'bizpanda'),
'default' => false
),
array(
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'mobile',
'title' => __('Mobile', 'bizpanda'),
'hint' => __('If on, the locker will appear on mobile devices.', 'bizpanda'),
'icon' => OPANDA_BIZPANDA_URL . '/assets/admin/img/mobile-icon.png',
'default' => true
)
)
),
array(
'type' => 'div',
'id' => 'bp-advanced-visibility-options',
'items' => array(
array(
'type' => 'html',
'html' => array( $this, 'visibilityFilters' )
),
array(
'type' => 'hidden',
'name' => 'visibility_filters'
)
)
)
);
if ( OPanda_Items::isCurrentFree() ) {
$options[] = array(
'type' => 'html',
'html' => '
' . __( '
Go Premium
To Unlock These Features
Learn More', 'bizpanda' ) . '
'
);
}
$options = apply_filters( 'opanda_visability_options', $options, $this );
$form->add( $options );
}
public function htmlReLockOptions() {
$relock = $this->provider->getValue('relock', false);
$interval = $this->provider->getValue('relock_interval', 0);
if ( $interval == 0 ) $interval = '';
$units = $this->provider->getValue('relock_interval_units', 'days');
?>
'user',
'title' => __('User', 'bizpanda'),
'items' => array(
array(
'id' => 'user-role',
'title' =>__('Role', 'bizpanda'),
'type' => 'select',
'values' => array(
'type' => 'ajax',
'action' => 'bp_ajax_get_user_roles'
),
'description' => __('A role of the user who views your website. The role "guest" is applied to unregistered users.', 'bizpanda')
),
array(
'id' => 'user-registered',
'title' =>__('Registration Date', 'bizpanda'),
'type' => 'date',
'description' => __('The date when the user who views your website was registered. For unregistered users this date always equals to 1 Jan 1970.', 'bizpanda')
),
array(
'id' => 'user-mobile',
'title' =>__('Mobile Device', 'bizpanda'),
'type' => 'select',
'values' => array(
array('value' => 'yes', 'title' => __('Yes', 'bizpanda') ),
array('value' => 'no', 'title' => __('No', 'bizpanda') )
),
'description' => __('Determines whether the user views your website from mobile device or not.', 'bizpanda')
),
array(
'id' => 'user-cookie-name',
'title' =>__('Cookie Name', 'bizpanda'),
'type' => 'text',
'onlyEquals' => true,
'description' => __('Determines whether the user\'s browser has a cookie with a given name.', 'bizpanda')
)
)
),
array(
'id' => 'session',
'title' => __('Session', 'bizpanda'),
'items' => array(
array(
'id' => 'session-pageviews',
'title' =>__('Total Pageviews', 'bizpanda'),
'type' => 'integer',
'description' => sprintf( __('The total count of pageviews made by the user within one\'s current session on your website. You can specify a duration of the sessions here.', 'bizpanda'), opanda_get_admin_url('settings', array('opanda_screen' => 'lock') ) )
),
array(
'id' => 'session-locker-pageviews',
'title' =>__('Locker Pageviews', 'bizpanda'),
'type' => 'integer',
'description' => sprintf( __('The count of views of pages where lockers located, made by the user within one\'s current session on your website. You can specify a duration of the sessions here.', 'bizpanda'), opanda_get_admin_url('settings', array('opanda_screen' => 'lock') ) )
),
array(
'id' => 'session-landing-page',
'title' =>__('Landing Page', 'bizpanda'),
'type' => 'text',
'description' => sprintf( __('A page of your website from which the user starts one\'s current session. You can specify a duration of the sessions here.', 'bizpanda'), opanda_get_admin_url('settings', array('opanda_screen' => 'lock') ) )
),
array(
'id' => 'session-referrer',
'title' =>__('Referrer', 'bizpanda'),
'type' => 'text',
'description' => sprintf( __('A referrer URL which has brought the user to your website within the user\'s current session. You can specify a duration of the sessions here.', 'bizpanda'), opanda_get_admin_url('settings', array('opanda_screen' => 'lock') ) )
)
)
),
array(
'id' => 'location',
'title' => __('Location', 'bizpanda'),
'items' => array(
array(
'id' => 'location-page',
'title' =>__('Current Page', 'bizpanda'),
'type' => 'text',
'description' => __('An URL of the current page where a user who views your website is located.', 'bizpanda')
),
array(
'id' => 'location-referrer',
'title' =>__('Current Referrer', 'bizpanda'),
'type' => 'text',
'description' => __('A referrer URL which has brought a user to the current page.', 'bizpanda')
)
)
),
array(
'id' => 'post',
'title' => __('Post', 'bizpanda'),
'items' => array(
array(
'id' => 'post-published',
'title' =>__('Publication Date', 'bizpanda'),
'type' => 'date',
'description' => __('The publication date of a post where a user who views your website is located currently.', 'bizpanda')
)
)
),
);
$groupedFilterParams = apply_filters('bp_visibility_filter_params', $groupedFilterParams);
$filterParams = array();
foreach( $groupedFilterParams as $filterGroup ) {
$filterParams = array_merge( $filterParams, $filterGroup['items'] );
}
// templates
$templates = array(
array(
'id' => 'hide_for_members',
'title' => __('[Hide For Members]: Show the locker only for guests', 'bizpanda'),
'filter' => array(
'type' => 'showif',
'conditions' => array(
array(
'type' => 'condition',
'param' => 'user-role',
'operator' => 'equals',
'value' => 'guest'
)
)
)
),
array(
'id' => 'mobile',
'title' => __('[Hide On Mobile]: Hide the locker on mobile devices', 'bizpanda'),
'filter' => array(
'type' => 'hideif',
'conditions' => array(
array(
'type' => 'condition',
'param' => 'user-mobile',
'operator' => 'equals',
'value' => 'yes'
)
)
)
),
array(
'id' => 'delayed_lock',
'title' => __('[Delayed Lock]: Show the locker only in posts older than 5 days', 'bizpanda'),
'filter' => array(
'type' => 'showif',
'conditions' => array(
array(
'type' => 'condition',
'param' => 'post-published',
'operator' => 'older',
'value' => array(
'type' => 'relative',
'unitsCount' => 5,
'units' => 'days'
)
)
)
)
)
);
$templates = apply_filters('bp_visibility_templates', $templates);
?>
Click here to add one.', 'bizpanda') ?>
Click here to add one.', 'bizpanda') ?>
scope . '_lock_delay'] );
$interval = isset( $_POST[$this->scope . '_lock_delay_interval'] )
? intval( $_POST[$this->scope . '_lock_delay_interval'] )
: 0;
if ( $interval < 0 ) $interval = 0;
$units = isset( $_POST[$this->scope . '_lock_delay_interval_units'] )
? $_POST[$this->scope . '_lock_delay_interval_units']
: null;
if ( !$units || !in_array($units, array('days', 'hours', 'minutes') )) {
$units = 'days';
}
if ( !$interval ) $_POST[$this->scope . '_lock_delay'] = null;
if ( !$delay ) {
$interval = 0;
$units = 'days';
}
$intervalInMinutes = $interval;
if ( $units == 'days' ) $intervalInMinutes = 24 * 60 * $interval;
if ( $units == 'hours' ) $intervalInMinutes = 60 * $interval;
$this->provider->setValue('lock_delay_interval_in_seconds', $intervalInMinutes * 60 );
$this->provider->setValue('lock_delay_interval', $interval);
$this->provider->setValue('lock_delay_interval_units', $units);
// saves relock options
$delay = isset( $_POST[$this->scope . '_relock'] );
$interval = isset( $_POST[$this->scope . '_relock_interval'] )
? intval( $_POST[$this->scope . '_relock_interval'] )
: 0;
if ( $interval < 0 ) $interval = 0;
$units = isset( $_POST[$this->scope . '_relock_interval_units'] )
? $_POST[$this->scope . '_relock_interval_units']
: null;
if ( !$units || !in_array($units, array('days', 'hours', 'minutes') )) {
$units = 'days';
}
if ( !$interval ) $_POST[$this->scope . '_relock'] = null;
if ( !$delay ) {
$interval = 0;
$units = 'days';
}
$intervalInMinutes = $interval;
if ( $units == 'days' ) $intervalInMinutes = 24 * 60 * $interval;
if ( $units == 'hours' ) $intervalInMinutes = 60 * $interval;
$this->provider->setValue('relock_interval_in_seconds', $intervalInMinutes * 60 );
$this->provider->setValue('relock_interval', $interval);
$this->provider->setValue('relock_interval_units', $units);
do_action('onp_sl_visability_options_on_save', $this);
}
}
global $bizpanda;
FactoryMetaboxes321::register('OPanda_VisabilityOptionsMetaBox', $bizpanda);