Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Addon Name: Suppress on Display Time rule (beta)
- Plugin URI: http://premium.wpmudev.org/project/the-pop-over-plugin/
- Description: Allows to set Suppress on Display Time in hours.
- Author: Dharmendra (Incsub)
- Author URI: http://premium.wpmudev.org
- Version: 1.0
- */
- abstract class Popover_Rules_Rule_DisplayTime extends Popover_Rules_Rule {
- protected $_defaults = array(
- "dhours" => '24',
- );
- public function apply_rule ($show, $popover) {
- $data = !empty($popover->popover_settings[$this->_id]) ? $popover->popover_settings[$this->_id] : false;
- if (empty($data)) return $show;
- $data = wp_parse_args($data, $this->_defaults);
- $dexp = time() + intval($data['dhours']) * 60 * 60 ;
- if ( isset($_COOKIE['popover_lastdtime_' . $this->_id . COOKIEHASH]) ) {
- $dhours = intval($_COOKIE['popover_lastdtime_' . $this->_id .COOKIEHASH]);
- } else {
- if(!headers_sent()) setcookie('popover_lastdtime_' . $this->_id . COOKIEHASH, time() , $dexp , COOKIEPATH, COOKIE_DOMAIN);
- return true;
- }
- if ($dhours < time() - intval($data['dhours']) * 60 * 60 )
- {
- if(!headers_sent()) setcookie('popover_lastdtime_'. $this->_id .COOKIEHASH, time() , $dexp , COOKIEPATH, COOKIE_DOMAIN);
- return true;
- }
- return $show;
- }
- public function get_admin_interface ($data) {
- $data = wp_parse_args($data[$this->_id], $this->_defaults);
- $markup = __('Display popover after', 'popover');
- $markup .= ' <input type="text" name="' . $this->_get_field_name("dhours") . '" id="' . $this->_get_field_id("dhours") . '" value="' . (int)$data["dhours"] . '" size="5"/> ' . __('Hours', 'popover');
- return $markup;
- }
- public function save_settings ($settings) {
- if (empty($_POST[$this->_id])) return $settings;
- $data = stripslashes_deep($_POST[$this->_id]);
- $result = array();
- $keys = array_keys($this->_defaults);
- foreach ($keys as $key) {
- if (empty($data[$key])) continue;
- $result[$key] = (int)$data[$key];
- }
- $settings[$this->_id] = $result;
- return $settings;
- }
- }
- class Popover_Rules_Rule_OnDisplayTime extends Popover_Rules_Rule_DisplayTime {
- const RULE = 'sup_display_time';
- public static function add () {
- $me = new self;
- return $me;
- }
- protected function __construct () {
- $this->_id = self::RULE;
- $this->_info = array(
- "title" => __('Suppress on Display Time (beta)', 'popover'),
- "message" => __('Suppresses the popover on specific Display Time', 'popover'),
- );
- $this->_action = __('Show', 'popover');
- parent::__construct();
- }
- public function apply_rule ($show, $popover) {
- return parent::apply_rule($show, $popover);
- }
- }
- class Popover_Rules_DisplayTime {
- private function __construct () {
- Popover_Rules_Rule_OnDisplayTime::add();
- }
- public static function serve () {
- $me = new self;
- }
- }
- Popover_Rules_DisplayTime::serve();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement