Advertisement
Guest User

Untitled

a guest
May 31st, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. <?php
  2. /*
  3. Addon Name: Suppress on Display Time rule (beta)
  4. Plugin URI: http://premium.wpmudev.org/project/the-pop-over-plugin/
  5. Description: Allows to set Suppress on Display Time in hours.
  6. Author: Dharmendra (Incsub)
  7. Author URI: http://premium.wpmudev.org
  8. Version: 1.0
  9. */
  10. abstract class Popover_Rules_Rule_DisplayTime extends Popover_Rules_Rule {
  11.  
  12. protected $_defaults = array(
  13. "dhours" => '24',
  14. );
  15.  
  16. public function apply_rule ($show, $popover) {
  17. $data = !empty($popover->popover_settings[$this->_id]) ? $popover->popover_settings[$this->_id] : false;
  18. if (empty($data)) return $show;
  19. $data = wp_parse_args($data, $this->_defaults);
  20. $dexp = time() + intval($data['dhours']) * 60 * 60 ;
  21. if ( isset($_COOKIE['popover_lastdtime_' . $this->_id . COOKIEHASH]) ) {
  22. $dhours = intval($_COOKIE['popover_lastdtime_' . $this->_id .COOKIEHASH]);
  23. } else {
  24. if(!headers_sent()) setcookie('popover_lastdtime_' . $this->_id . COOKIEHASH, time() , $dexp , COOKIEPATH, COOKIE_DOMAIN);
  25. return true;
  26. }
  27.  
  28. if ($dhours < time() - intval($data['dhours']) * 60 * 60 )
  29. {
  30. if(!headers_sent()) setcookie('popover_lastdtime_'. $this->_id .COOKIEHASH, time() , $dexp , COOKIEPATH, COOKIE_DOMAIN);
  31. return true;
  32. }
  33. return $show;
  34. }
  35.  
  36. public function get_admin_interface ($data) {
  37. $data = wp_parse_args($data[$this->_id], $this->_defaults);
  38. $markup = __('Display popover after', 'popover');
  39. $markup .= ' <input type="text" name="' . $this->_get_field_name("dhours") . '" id="' . $this->_get_field_id("dhours") . '" value="' . (int)$data["dhours"] . '" size="5"/> ' . __('Hours', 'popover');
  40. return $markup;
  41. }
  42.  
  43. public function save_settings ($settings) {
  44. if (empty($_POST[$this->_id])) return $settings;
  45.  
  46. $data = stripslashes_deep($_POST[$this->_id]);
  47. $result = array();
  48. $keys = array_keys($this->_defaults);
  49. foreach ($keys as $key) {
  50. if (empty($data[$key])) continue;
  51. $result[$key] = (int)$data[$key];
  52. }
  53. $settings[$this->_id] = $result;
  54. return $settings;
  55. }
  56. }
  57.  
  58. class Popover_Rules_Rule_OnDisplayTime extends Popover_Rules_Rule_DisplayTime {
  59.  
  60. const RULE = 'sup_display_time';
  61.  
  62. public static function add () {
  63. $me = new self;
  64. return $me;
  65. }
  66.  
  67. protected function __construct () {
  68. $this->_id = self::RULE;
  69. $this->_info = array(
  70. "title" => __('Suppress on Display Time (beta)', 'popover'),
  71. "message" => __('Suppresses the popover on specific Display Time', 'popover'),
  72. );
  73. $this->_action = __('Show', 'popover');
  74. parent::__construct();
  75. }
  76.  
  77. public function apply_rule ($show, $popover) {
  78. return parent::apply_rule($show, $popover);
  79. }
  80. }
  81.  
  82.  
  83. class Popover_Rules_DisplayTime {
  84.  
  85. private function __construct () {
  86. Popover_Rules_Rule_OnDisplayTime::add();
  87. }
  88.  
  89. public static function serve () {
  90. $me = new self;
  91. }
  92. }
  93. Popover_Rules_DisplayTime::serve();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement