wordpress-popup
Last commit date
popoverincludes
13 years ago
license.txt
15 years ago
popover-load-js.php
13 years ago
popover.php
13 years ago
readme.txt
13 years ago
screenshot-1.png
14 years ago
screenshot-2.png
14 years ago
screenshot-3.png
14 years ago
popover-load-js.php
167 lines
| 1 | <?php |
| 2 | /* |
| 3 | * Popover selective loading file - had to move from JS to PHP because we needed some extra processing that couldn't be handled in a JS file :( |
| 4 | */ |
| 5 | // Header settings code based on code from load-scripts.php |
| 6 | error_reporting(0); |
| 7 | |
| 8 | $compress = ( isset($_GET['c']) && $_GET['c'] ); |
| 9 | $force_gzip = ( $compress && 'gzip' == $_GET['c'] ); |
| 10 | $expires_offset = 31536000; |
| 11 | $out = ''; |
| 12 | |
| 13 | header('Content-Type: application/x-javascript; charset=UTF-8'); |
| 14 | header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT'); |
| 15 | header("Cache-Control: public, max-age=$expires_offset"); |
| 16 | |
| 17 | if ( $compress && ! ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) { |
| 18 | header('Vary: Accept-Encoding'); // Handle proxies |
| 19 | if ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) { |
| 20 | header('Content-Encoding: deflate'); |
| 21 | $out = gzdeflate( $out, 3 ); |
| 22 | } elseif ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ) { |
| 23 | header('Content-Encoding: gzip'); |
| 24 | $out = gzencode( $out, 3 ); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | define( 'POPOVERJSLOCATION', dirname($_SERVER["SCRIPT_FILENAME"]) ); |
| 29 | define( 'ABSPATH', dirname(dirname(dirname(POPOVERJSLOCATION))) . '/' ); |
| 30 | define( 'WPINC', 'wp-includes' ); |
| 31 | |
| 32 | // Load WordPress so that we can get some bits and pieces. |
| 33 | require_once( ABSPATH . 'wp-load.php'); |
| 34 | |
| 35 | ?> |
| 36 | // |
| 37 | // Javascript file to selectively load the WPMUDEV Pop Up |
| 38 | // |
| 39 | // Written by Barry (Incsub) |
| 40 | // |
| 41 | // |
| 42 | // |
| 43 | |
| 44 | // Where the admin-ajax.php file is relative to the domain - have to hardcode for now due to this being a JS file |
| 45 | var po_adminajax = '<?php echo admin_url( 'admin-ajax.php' ); ?>'; |
| 46 | |
| 47 | // Enable us to get some cookie information - from http://stackoverflow.com/questions/5639346/shortest-function-for-reading-a-cookie-in-javascript |
| 48 | function po_get_cookie(name) { |
| 49 | |
| 50 | var nameEQ = name + "="; |
| 51 | var ca = document.cookie.split(';'); |
| 52 | for(var i=0;i < ca.length;i++) { |
| 53 | var c = ca[i]; |
| 54 | while (c.charAt(0)==' ') c = c.substring(1,c.length); |
| 55 | if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); |
| 56 | } |
| 57 | return null; |
| 58 | } |
| 59 | |
| 60 | function po_createCookie(name,value,days) { |
| 61 | if (days) { |
| 62 | var date = new Date(); |
| 63 | date.setTime(date.getTime()+(days*24*60*60*1000)); |
| 64 | var expires = "; expires="+date.toGMTString(); |
| 65 | } |
| 66 | else var expires = ""; |
| 67 | document.cookie = name+"="+value+expires+"; path=/"; |
| 68 | } |
| 69 | |
| 70 | function po_removeMessageBoxForever() { |
| 71 | jQuery('#darkbackground').remove(); |
| 72 | jQuery(this).parents(popovername).remove(); |
| 73 | po_createCookie('popover_never_view', 'hidealways', 365); |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | function po_removeMessageBox() { |
| 78 | jQuery('#darkbackground').remove(); |
| 79 | jQuery(this).parents(popovername).remove(); |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | function po_loadMessageBox( ) { |
| 84 | |
| 85 | // move the data back to the data variable, from mydata so we can use it without changing a chunk of code :) |
| 86 | data = mydata; |
| 87 | |
| 88 | if( data['html'] != '' ) { |
| 89 | // Set the name for other functions to use |
| 90 | popovername = '#' + data['name']; |
| 91 | |
| 92 | jQuery( '<style type="text/css">' + data['style'] + '</style>' ).appendTo('head'); |
| 93 | jQuery( data['html'] ).appendTo('body'); |
| 94 | |
| 95 | if( data['usejs'] == 'yes' ) { |
| 96 | |
| 97 | jQuery('#' + data['name']).width(jQuery('#message').width()); |
| 98 | jQuery('#' + data['name']).height(jQuery('#message').height()); |
| 99 | |
| 100 | jQuery('#' + data['name']).css('top', (jQuery(window).height() / 2) - (jQuery('#message').height() / 2) ); |
| 101 | jQuery('#' + data['name']).css('left', (jQuery(window).width() / 2) - (jQuery('#message').width() / 2) ); |
| 102 | } |
| 103 | |
| 104 | jQuery('#' + data['name']).css('visibility', 'visible'); |
| 105 | jQuery('#darkbackground').css('visibility', 'visible'); |
| 106 | |
| 107 | jQuery('#clearforever').click(po_removeMessageBoxForever); |
| 108 | jQuery('#closebox').click(po_removeMessageBox); |
| 109 | |
| 110 | jQuery('#message').hover( function() {jQuery('.claimbutton').removeClass('hide');}, function() {jQuery('.claimbutton').addClass('hide');}); |
| 111 | } |
| 112 | |
| 113 | } |
| 114 | |
| 115 | function po_onsuccess( data ) { |
| 116 | // set the data to be a global variable so we can grab it after the timeout |
| 117 | mydata = data; |
| 118 | |
| 119 | if(data['name'] != 'nopoover') { |
| 120 | window.setTimeout( po_loadMessageBox, data['delay'] ); |
| 121 | } |
| 122 | |
| 123 | } |
| 124 | |
| 125 | function po_load_popover() { |
| 126 | |
| 127 | var theajax = po_adminajax; |
| 128 | var thefrom = window.location; |
| 129 | var thereferrer = document.referrer; |
| 130 | |
| 131 | // Check if we are forcing a popover - if not then set it to a default value of 0 |
| 132 | if (typeof force_popover === 'undefined') { |
| 133 | force_popover = 0; |
| 134 | } |
| 135 | |
| 136 | jQuery.ajax( { |
| 137 | url : theajax, |
| 138 | dataType : 'jsonp', |
| 139 | jsonpCallback : 'po_onsuccess', |
| 140 | data : { action : 'popover_selective_ajax', |
| 141 | thefrom : thefrom.toString(), |
| 142 | thereferrer : thereferrer.toString(), |
| 143 | active_popover : force_popover.toString() |
| 144 | }, |
| 145 | success : function(data) { |
| 146 | |
| 147 | } |
| 148 | } |
| 149 | ); |
| 150 | |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | |
| 155 | // The main function |
| 156 | function po_selectiveLoad() { |
| 157 | |
| 158 | po_load_popover(); |
| 159 | |
| 160 | } |
| 161 | |
| 162 | // Call when the page is fully loaded |
| 163 | jQuery(window).load(po_selectiveLoad); |
| 164 | |
| 165 | <?php |
| 166 | exit; |
| 167 | ?> |