popover.help.php
13 years ago
popoveradmin.php
13 years ago
popoverajax.php
13 years ago
popoverpublic.php
13 years ago
popoverpublic.php
206 lines
| 1 | <?php |
| 2 | |
| 3 | if(!class_exists('popoverpublic')) { |
| 4 | |
| 5 | class popoverpublic { |
| 6 | |
| 7 | var $mylocation = ''; |
| 8 | var $build = 5; |
| 9 | var $db; |
| 10 | |
| 11 | var $tables = array( 'popover', 'popover_ip_cache' ); |
| 12 | var $popover; |
| 13 | var $popover_ip_cache; |
| 14 | |
| 15 | var $activepopover = false; |
| 16 | |
| 17 | var $thepopover; |
| 18 | |
| 19 | function __construct() { |
| 20 | |
| 21 | global $wpdb; |
| 22 | |
| 23 | $this->db =& $wpdb; |
| 24 | |
| 25 | foreach($this->tables as $table) { |
| 26 | $this->$table = popover_db_prefix($this->db, $table); |
| 27 | } |
| 28 | |
| 29 | // Adds the JS to the themes header - this replaces all previous methods of loading |
| 30 | add_action( 'init', array( &$this, 'initialise_plugin') ); |
| 31 | |
| 32 | add_action( 'plugins_loaded', array(&$this, 'load_textdomain')); |
| 33 | |
| 34 | $directories = explode(DIRECTORY_SEPARATOR,dirname(__FILE__)); |
| 35 | $this->mylocation = $directories[count($directories)-1]; |
| 36 | |
| 37 | $installed = get_option('popover_installed', false); |
| 38 | |
| 39 | if($installed === false || $installed != $this->build) { |
| 40 | $this->install(); |
| 41 | |
| 42 | update_option('popover_installed', $this->build); |
| 43 | } |
| 44 | |
| 45 | } |
| 46 | |
| 47 | function popoverpublic() { |
| 48 | $this->__construct(); |
| 49 | } |
| 50 | |
| 51 | function install() { |
| 52 | |
| 53 | if($this->db->get_var( "SHOW TABLES LIKE '" . $this->popover . "' ") != $this->popover) { |
| 54 | $sql = "CREATE TABLE `" . $this->popover . "` ( |
| 55 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 56 | `popover_title` varchar(250) DEFAULT NULL, |
| 57 | `popover_content` text, |
| 58 | `popover_settings` text, |
| 59 | `popover_order` bigint(20) DEFAULT '0', |
| 60 | `popover_active` int(11) DEFAULT '0', |
| 61 | PRIMARY KEY (`id`) |
| 62 | )"; |
| 63 | |
| 64 | $this->db->query($sql); |
| 65 | |
| 66 | } |
| 67 | |
| 68 | // Add in IP cache table |
| 69 | if($this->db->get_var( "SHOW TABLES LIKE '" . $this->popover_ip_cache . "' ") != $this->popover_ip_cache) { |
| 70 | $sql = "CREATE TABLE `" . $this->popover_ip_cache . "` ( |
| 71 | `IP` varchar(12) NOT NULL DEFAULT '', |
| 72 | `country` varchar(2) DEFAULT NULL, |
| 73 | `cached` bigint(20) DEFAULT NULL, |
| 74 | PRIMARY KEY (`IP`), |
| 75 | KEY `cached` (`cached`) |
| 76 | )"; |
| 77 | |
| 78 | $this->db->query($sql); |
| 79 | |
| 80 | } |
| 81 | |
| 82 | } |
| 83 | |
| 84 | function load_textdomain() { |
| 85 | |
| 86 | $locale = apply_filters( 'popover_locale', get_locale() ); |
| 87 | $mofile = popover_dir( "popoverincludes/languages/popover-$locale.mo" ); |
| 88 | |
| 89 | if ( file_exists( $mofile ) ) |
| 90 | load_textdomain( 'popover', $mofile ); |
| 91 | |
| 92 | } |
| 93 | |
| 94 | function initialise_plugin() { |
| 95 | |
| 96 | $settings = get_popover_option('popover-settings', array( 'loadingmethod' => 'external')); |
| 97 | |
| 98 | switch( $settings['loadingmethod'] ) { |
| 99 | |
| 100 | case 'external': $this->add_selective_javascript(); |
| 101 | break; |
| 102 | |
| 103 | case 'footer': $this->add_popover_files(); |
| 104 | break; |
| 105 | |
| 106 | } |
| 107 | |
| 108 | } |
| 109 | |
| 110 | function add_selective_javascript() { |
| 111 | global $pagenow; |
| 112 | |
| 113 | if(!in_array($pagenow, array('wp-login.php', 'wp-register.php'))) { |
| 114 | // We need javascript so make sure we load it here |
| 115 | wp_enqueue_script('jquery'); |
| 116 | |
| 117 | // Now to register our new js file |
| 118 | wp_register_script( 'popoverselective', popover_url('popover-load-js.php') ); |
| 119 | wp_enqueue_script( 'popoverselective' ); |
| 120 | } |
| 121 | |
| 122 | } |
| 123 | |
| 124 | function add_frontend_selective_javascript() { |
| 125 | global $pagenow; |
| 126 | |
| 127 | if(!in_array($pagenow, array('wp-login.php', 'wp-register.php'))) { |
| 128 | // We need javascript so make sure we load it here |
| 129 | wp_enqueue_script('jquery'); |
| 130 | |
| 131 | // Now to register our new js file |
| 132 | wp_register_script( 'popoverselective', popover_url('popover-load-custom-js.php') ); |
| 133 | wp_enqueue_script( 'popoverselective' ); |
| 134 | } |
| 135 | |
| 136 | } |
| 137 | |
| 138 | function myURL() { |
| 139 | |
| 140 | if ( isset($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"]) == "on") { |
| 141 | $url .= "https://"; |
| 142 | } else { |
| 143 | $url = 'http://'; |
| 144 | } |
| 145 | |
| 146 | if ($_SERVER["SERVER_PORT"] != "80") { |
| 147 | $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; |
| 148 | } else { |
| 149 | $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; |
| 150 | } |
| 151 | |
| 152 | return trailingslashit($url); |
| 153 | } |
| 154 | |
| 155 | function add_popover_files() { |
| 156 | |
| 157 | global $popoverajax; |
| 158 | |
| 159 | if( method_exists( $popoverajax, 'selective_message_display') ) { |
| 160 | |
| 161 | // Set up the rquest information from here - this is passed in using the standard JS interface so we need to fake it |
| 162 | $_REQUEST['thereferrer'] = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : ''; |
| 163 | $_REQUEST['thefrom'] = $this->myURL(); |
| 164 | |
| 165 | $this->thepopover = $popoverajax->selective_message_display(); |
| 166 | |
| 167 | if( isset($this->thepopover['name']) && $this->thepopover['name'] != 'nopopover' ) { |
| 168 | wp_enqueue_script('jquery'); |
| 169 | |
| 170 | wp_enqueue_script('popoverlegacyjs', popover_url('popoverincludes/js/popoverlegacy.js'), array('jquery'), $this->build); |
| 171 | wp_localize_script('popoverlegacyjs', 'popover', array( 'divname' => $this->thepopover['name'], |
| 172 | 'usejs' => $this->thepopover['usejs'], |
| 173 | 'delay' => $this->thepopover['delay'] |
| 174 | )); |
| 175 | |
| 176 | add_action('wp_head', array(&$this, 'output_header_content')); |
| 177 | add_action('wp_footer', array(&$this, 'output_footer_content')); |
| 178 | |
| 179 | } |
| 180 | |
| 181 | } |
| 182 | |
| 183 | } |
| 184 | |
| 185 | function output_header_content() { |
| 186 | // Output the styles |
| 187 | ?> |
| 188 | <style type="text/css"> |
| 189 | <?php |
| 190 | echo $this->thepopover['style']; |
| 191 | ?> |
| 192 | </style> |
| 193 | <?php |
| 194 | } |
| 195 | |
| 196 | function output_footer_content() { |
| 197 | |
| 198 | echo $this->thepopover['html']; |
| 199 | |
| 200 | } |
| 201 | |
| 202 | } |
| 203 | |
| 204 | } |
| 205 | |
| 206 | ?> |