popoverpublic.php
231 lines
| 1 | <?php |
| 2 | |
| 3 | if(!class_exists('popoverpublic')) { |
| 4 | |
| 5 | class popoverpublic { |
| 6 | |
| 7 | var $mylocation = ''; |
| 8 | var $build = 3; |
| 9 | |
| 10 | function __construct() { |
| 11 | |
| 12 | add_action('init', array(&$this, 'selective_message_display'), 1); |
| 13 | add_action('wp_footer', array(&$this, 'selective_message_display')); |
| 14 | |
| 15 | add_action( 'plugins_loaded', array(&$this, 'load_textdomain')); |
| 16 | |
| 17 | $directories = explode(DIRECTORY_SEPARATOR,dirname(__FILE__)); |
| 18 | $this->mylocation = $directories[count($directories)-1]; |
| 19 | |
| 20 | } |
| 21 | |
| 22 | function popoverpublic() { |
| 23 | $this->__construct(); |
| 24 | } |
| 25 | |
| 26 | function load_textdomain() { |
| 27 | |
| 28 | $locale = apply_filters( 'popover_locale', get_locale() ); |
| 29 | $mofile = popover_dir( "popoverincludes/languages/popover-$locale.mo" ); |
| 30 | |
| 31 | if ( file_exists( $mofile ) ) |
| 32 | load_textdomain( 'popover', $mofile ); |
| 33 | |
| 34 | } |
| 35 | |
| 36 | function selective_message_display() { |
| 37 | |
| 38 | if(is_multisite() && defined('PO_GLOBAL')) { |
| 39 | $getoption = 'get_site_option'; |
| 40 | } else { |
| 41 | $getoption = 'get_option'; |
| 42 | } |
| 43 | |
| 44 | $popover_check = $getoption('popover_check', array()); |
| 45 | |
| 46 | $show = false; |
| 47 | |
| 48 | if(!empty($popover_check)) { |
| 49 | |
| 50 | $order = explode(',', $popover_check['order']); |
| 51 | |
| 52 | foreach($order as $key) { |
| 53 | switch ($key) { |
| 54 | |
| 55 | case "supporter": |
| 56 | if(function_exists('is_supporter') && !is_supporter()) { |
| 57 | $show = true; |
| 58 | } else { |
| 59 | return false; |
| 60 | } |
| 61 | break; |
| 62 | |
| 63 | case "loggedin": if(!$this->is_loggedin()) { |
| 64 | $show = true; |
| 65 | } else { |
| 66 | return false; |
| 67 | } |
| 68 | break; |
| 69 | |
| 70 | case "isloggedin": if($this->is_loggedin()) { |
| 71 | $show = true; |
| 72 | } else { |
| 73 | return false; |
| 74 | } |
| 75 | break; |
| 76 | |
| 77 | case "commented": if(!$this->has_commented()) { |
| 78 | $show = true; |
| 79 | } else { |
| 80 | return false; |
| 81 | } |
| 82 | break; |
| 83 | |
| 84 | case "internal": $internal = str_replace('http://','',get_option('siteurl')); |
| 85 | if(!$this->referrer_matches(addcslashes($internal,"/"))) { |
| 86 | $show = true; |
| 87 | } else { |
| 88 | return false; |
| 89 | } |
| 90 | break; |
| 91 | |
| 92 | case "count": $popover_count = $getoption('popover_count', '3'); |
| 93 | if($this->has_reached_limit($popover_count)) { |
| 94 | return false; |
| 95 | } |
| 96 | break; |
| 97 | |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | if($show == true) { |
| 103 | |
| 104 | if($this->clear_forever()) { |
| 105 | $show = false; |
| 106 | } |
| 107 | |
| 108 | } |
| 109 | |
| 110 | if($show == true) { |
| 111 | // Show the advert |
| 112 | wp_enqueue_style('popovercss', popover_url('popoverincludes/css/popover.css'), array(), $this->build); |
| 113 | wp_enqueue_script('popoverjs', popover_url('popoverincludes/js/popover.js'), array('jquery'), $this->build); |
| 114 | |
| 115 | if($getoption('popover_usejs', 'no') == 'yes') { |
| 116 | wp_enqueue_script('popoveroverridejs', popover_url('popoverincludes/js/popoversizing.js'), array('jquery'), $this->build); |
| 117 | } |
| 118 | |
| 119 | add_action('wp_footer', array(&$this, 'page_footer')); |
| 120 | wp_enqueue_script('jquery'); |
| 121 | |
| 122 | // Add the cookie |
| 123 | if ( isset($_COOKIE['popover_view_'.COOKIEHASH]) ) { |
| 124 | $count = intval($_COOKIE['popover_view_'.COOKIEHASH]); |
| 125 | if(!is_numeric($count)) $count = 0; |
| 126 | $count++; |
| 127 | } else { |
| 128 | $count = 1; |
| 129 | } |
| 130 | if(!headers_sent()) setcookie('popover_view_'.COOKIEHASH, $count , time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); |
| 131 | } |
| 132 | |
| 133 | } |
| 134 | |
| 135 | function sanitise_array($arrayin) { |
| 136 | |
| 137 | foreach($arrayin as $key => $value) { |
| 138 | $arrayin[$key] = htmlentities(stripslashes($value) ,ENT_QUOTES, 'UTF-8'); |
| 139 | } |
| 140 | |
| 141 | return $arrayin; |
| 142 | } |
| 143 | |
| 144 | function page_footer() { |
| 145 | |
| 146 | if(is_multisite() && defined('PO_GLOBAL')) { |
| 147 | $getoption = 'get_site_option'; |
| 148 | } else { |
| 149 | $getoption = 'get_option'; |
| 150 | } |
| 151 | |
| 152 | $content = stripslashes($getoption('popover_content', '')); |
| 153 | |
| 154 | $popover_size = $getoption('popover_size', array('width' => '500px', 'height' => '200px')); |
| 155 | $popover_location = $getoption('popover_location', array('left' => '100px', 'top' => '100px')); |
| 156 | $popover_colour = $getoption('popover_colour', array('back' => 'FFFFFF', 'fore' => '000000')); |
| 157 | $popover_margin = $getoption('popover_margin', array('left' => '0px', 'top' => '0px', 'right' => '0px', 'bottom' => '0px')); |
| 158 | |
| 159 | $popover_size = $this->sanitise_array($popover_size); |
| 160 | $popover_location = $this->sanitise_array($popover_location); |
| 161 | $popover_colour = $this->sanitise_array($popover_colour); |
| 162 | $popover_margin = $this->sanitise_array($popover_margin); |
| 163 | |
| 164 | if($getoption('popover_usejs', 'no') == 'yes') { |
| 165 | $style = ''; |
| 166 | $box = 'color: #' . $popover_colour['fore'] . '; background: #' . $popover_colour['back'] . ';'; |
| 167 | |
| 168 | } else { |
| 169 | $style = 'left: ' . $popover_location['left'] . '; top: ' . $popover_location['top'] . ';'; |
| 170 | $style .= 'margin-top: ' . $popover_margin['top'] . '; margin-bottom: ' . $popover_margin['bottom'] . '; margin-right: ' . $popover_margin['right'] . '; margin-left: ' . $popover_margin['left'] . ';'; |
| 171 | |
| 172 | $box = 'width: ' . $popover_size['width'] . '; height: ' . $popover_size['height'] . '; color: #' . $popover_colour['fore'] . '; background: #' . $popover_colour['back'] . ';'; |
| 173 | |
| 174 | } |
| 175 | |
| 176 | |
| 177 | ?> |
| 178 | <div id='messagebox' class='visiblebox' style='<?php echo $style; ?>'> |
| 179 | <a href='' id='closebox' title='Close this box'></a> |
| 180 | <div id='message' style='<?php echo $box; ?>'> |
| 181 | <?php echo $content; ?> |
| 182 | <div class='clear'></div> |
| 183 | <div class='claimbutton hide'><a href='#' id='clearforever'><?php _e('Never see this message again.','popover'); ?></a></div> |
| 184 | </div> |
| 185 | <div class='clear'></div> |
| 186 | </div> |
| 187 | <?php |
| 188 | } |
| 189 | |
| 190 | function is_ie() |
| 191 | { |
| 192 | if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)) |
| 193 | return true; |
| 194 | else |
| 195 | return false; |
| 196 | } |
| 197 | |
| 198 | function is_loggedin() { |
| 199 | return is_user_logged_in(); |
| 200 | } |
| 201 | |
| 202 | function has_commented() { |
| 203 | if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) { |
| 204 | return true; |
| 205 | } else { |
| 206 | return false; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | |
| 211 | function has_reached_limit($count = 3) { |
| 212 | if ( isset($_COOKIE['popover_view_'.COOKIEHASH]) && addslashes($_COOKIE['popover_view_'.COOKIEHASH]) >= $count ) { |
| 213 | return true; |
| 214 | } else { |
| 215 | return false; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | function clear_forever() { |
| 220 | if ( isset($_COOKIE['popover_never_view']) ) { |
| 221 | return true; |
| 222 | } else { |
| 223 | return false; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | } |
| 228 | |
| 229 | } |
| 230 | |
| 231 | ?> |