Advertisement
Guest User

float lr

a guest
Feb 23rd, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.00 KB | None | 0 0
  1. <?php
  2. /**
  3.  Plugin Name: Float Left Right Advertising
  4.  Plugin URI: http://blog.casanova.vn/float-left-right-advertising/
  5.  Version: 2.0
  6.  Description: <strong>[CASANOVA]</strong> Float Advertising on Left and Right, Ads scroll up/down when user scroll page up/down. Support multi setting: width of left banner, width of right banner, margin-top, margin-left, margin-right and HTML code for banner. After active this plugin please goto <strong>Settings</strong> --> <strong><a href="options-general.php?page=float_ads.php">Float Left Right Advertising</a></strong> and config your Advertising.
  7.  Author: Nguyen Duc Manh
  8.  Author URI: http://casanova.vn
  9. */
  10.  
  11.  
  12. /*****************Frontend****************************************/
  13.  
  14. function load_csnv_script(){
  15.     if(get_option('csnv_is_active') && (get_option('csnv_left_code') || get_option('csnv_right_code')) ){
  16.         wp_enqueue_script( 'jquery' );
  17.         wp_enqueue_script(
  18.             'floatads.js',
  19.             plugins_url('/floatads.js', __FILE__),
  20.             '',
  21.             '',
  22.             false
  23.         );
  24.         add_action('wp_footer', 'append_code_to_body');
  25.     }  
  26. }
  27.  
  28. function is_mobile() {
  29.  
  30.     // Get the user agent
  31.  
  32.     $user_agent = $_SERVER['HTTP_USER_AGENT'];
  33.  
  34.     // Create an array of known mobile user agents
  35.     // This list is from the 21 October 2010 WURFL File.
  36.     // Most mobile devices send a pretty standard string that can be covered by
  37.     // one of these.  I believe I have found all the agents (as of the date above)
  38.     // that do not and have included them below.  If you use this function, you
  39.     // should periodically check your list against the WURFL file, available at:
  40.     // http://wurfl.sourceforge.net/
  41.  
  42.  
  43.     $mobile_agents = Array(
  44.  
  45.  
  46.         "240x320",
  47.         "acer",
  48.         "acoon",
  49.         "acs-",
  50.         "abacho",
  51.         "ahong",
  52.         "airness",
  53.         "alcatel",
  54.         "amoi",
  55.         "android",
  56.         "anywhereyougo.com",
  57.         "applewebkit/525",
  58.         "applewebkit/532",
  59.         "asus",
  60.         "audio",
  61.         "au-mic",
  62.         "avantogo",
  63.         "becker",
  64.         "benq",
  65.         "bilbo",
  66.         "bird",
  67.         "blackberry",
  68.         "blazer",
  69.         "bleu",
  70.         "cdm-",
  71.         "compal",
  72.         "coolpad",
  73.         "danger",
  74.         "dbtel",
  75.         "dopod",
  76.         "elaine",
  77.         "eric",
  78.         "etouch",
  79.         "fly " ,
  80.         "fly_",
  81.         "fly-",
  82.         "go.web",
  83.         "goodaccess",
  84.         "gradiente",
  85.         "grundig",
  86.         "haier",
  87.         "hedy",
  88.         "hitachi",
  89.         "htc",
  90.         "huawei",
  91.         "hutchison",
  92.         "inno",
  93.         "ipad",
  94.         "ipaq",
  95.         "ipod",
  96.         "jbrowser",
  97.         "kddi",
  98.         "kgt",
  99.         "kwc",
  100.         "lenovo",
  101.         "lg ",
  102.         "lg2",
  103.         "lg3",
  104.         "lg4",
  105.         "lg5",
  106.         "lg7",
  107.         "lg8",
  108.         "lg9",
  109.         "lg-",
  110.         "lge-",
  111.         "lge9",
  112.         "longcos",
  113.         "maemo",
  114.         "mercator",
  115.         "meridian",
  116.         "micromax",
  117.         "midp",
  118.         "mini",
  119.         "mitsu",
  120.         "mmm",
  121.         "mmp",
  122.         "mobi",
  123.         "mot-",
  124.         "moto",
  125.         "nec-",
  126.         "netfront",
  127.         "newgen",
  128.         "nexian",
  129.         "nf-browser",
  130.         "nintendo",
  131.         "nitro",
  132.         "nokia",
  133.         "nook",
  134.         "novarra",
  135.         "obigo",
  136.         "palm",
  137.         "panasonic",
  138.         "pantech",
  139.         "philips",
  140.         "phone",
  141.         "pg-",
  142.         "playstation",
  143.         "pocket",
  144.         "pt-",
  145.         "qc-",
  146.         "qtek",
  147.         "rover",
  148.         "sagem",
  149.         "sama",
  150.         "samu",
  151.         "sanyo",
  152.         "samsung",
  153.         "sch-",
  154.         "scooter",
  155.         "sec-",
  156.         "sendo",
  157.         "sgh-",
  158.         "sharp",
  159.         "siemens",
  160.         "sie-",
  161.         "softbank",
  162.         "sony",
  163.         "spice",
  164.         "sprint",
  165.         "spv",
  166.         "symbian",
  167.         "tablet",
  168.         "talkabout",
  169.         "tcl-",
  170.         "teleca",
  171.         "telit",
  172.         "tianyu",
  173.         "tim-",
  174.         "toshiba",
  175.         "tsm",
  176.         "up.browser",
  177.         "utec",
  178.         "utstar",
  179.         "verykool",
  180.         "virgin",
  181.         "vk-",
  182.         "voda",
  183.         "voxtel",
  184.         "vx",
  185.         "wap",
  186.         "wellco",
  187.         "wig browser",
  188.         "wii",
  189.         "windows ce",
  190.         "wireless",
  191.         "xda",
  192.         "xde",
  193.         "zte"
  194.     );
  195.  
  196.     // Pre-set $is_mobile to false.
  197.  
  198.     $is_mobile = false;
  199.  
  200.     // Cycle through the list in $mobile_agents to see if any of them
  201.     // appear in $user_agent.
  202.  
  203.     foreach ($mobile_agents as $device) {
  204.  
  205.         // Check each element in $mobile_agents to see if it appears in
  206.         // $user_agent.  If it does, set $is_mobile to true.
  207.  
  208.         if (stristr($user_agent, $device)) {
  209.  
  210.             $is_mobile = true;
  211.  
  212.             // break out of the foreach, we don't need to test
  213.             // any more once we get a true value.
  214.  
  215.             break;
  216.         }
  217.     }
  218.  
  219.     return $is_mobile;
  220. }
  221.  
  222. function append_code_to_body(){
  223. ?>
  224.     <?php
  225.         $screen_w   =   get_option("screen_w");
  226.         $MainContentW   =   get_option("csnv_content_w")?get_option("csnv_content_w"):1000;
  227.        
  228.         //Width + height
  229.         $LeftBannerW    =   get_option("csnv_left_w")?get_option("csnv_left_w"):100;
  230.         $LeftBannerH    =   get_option("csnv_left_h")?get_option("csnv_left_h"):500;
  231.        
  232.         $RightBannerW   =   get_option("csnv_right_w")?get_option("csnv_right_w"):100;
  233.         $RightBannerH   =   get_option("csnv_right_h")?get_option("csnv_right_h"):500;
  234.        
  235.        
  236.         //Ajust
  237.         $LeftAdjust     =   get_option("csnv_margin_left")?get_option("csnv_margin_left"):10;
  238.         $RightAdjust    =   get_option("csnv_margin_right")?get_option("csnv_margin_right"):10;
  239.         $TopAdjust      =   get_option("csnv_margin_top")?get_option("csnv_margin_top"):80;
  240.        
  241.         $mobile_show    =   get_option("mobile_show");
  242.         $is_mobile      =   is_mobile();
  243.      ?>
  244.    
  245.     <?php if(empty($is_mobile))://Neu la may tinh ?>
  246.         <script type="text/javascript">
  247.             var clientWidth =   window.screen.width;
  248.             if(clientWidth >= <?php echo $screen_w; ?>){
  249.                 document.write('<div id="divAdRight" style="position: absolute; top: 0px; width:<?php echo $RightBannerW; ?>px; <?php if($RightBannerH) echo "height:".$RightBannerH."px;"; ?> overflow:hidden;"> <?php echo html_entity_decode(get_option('csnv_right_code')); ?></div><div id="divAdLeft" style="position: absolute; top: 0px; width:<?php echo $LeftBannerW; ?>px; <?php if($LeftBannerH) echo "height:".$LeftBannerH."px;"; ?> overflow:hidden;"><?php  echo html_entity_decode(get_option('csnv_left_code')); ?></div>'); 
  250.                
  251.                 var MainContentW = <?php echo $MainContentW; ?>;
  252.                 var LeftBannerW = <?php echo $LeftBannerW; ?>;
  253.                 var RightBannerW = <?php echo $RightBannerW; ?>;
  254.                 var LeftAdjust = <?php echo $LeftAdjust; ?>;
  255.                 var RightAdjust = <?php echo $RightAdjust; ?>;
  256.                 var TopAdjust = <?php echo $TopAdjust; ?>;
  257.                 ShowAdDiv();
  258.                 window.onresize=ShowAdDiv;
  259.             }
  260.         </script>
  261.     <?php else: //Neu la mobile ?>    
  262.         <?php if($mobile_show==1):?>
  263.             <script type="text/javascript">
  264.             var clientWidth =   window.screen.width;
  265.             if(clientWidth >= <?php echo $screen_w; ?>){
  266.                 document.write('<div id="divAdRight" style="position: absolute; top: 0px; width:<?php echo $RightBannerW; ?>px; height:<?php echo $RightBannerH; ?>px; overflow:hidden;"> <?php echo html_entity_decode(get_option('csnv_right_code')); ?></div><div id="divAdLeft" style="position: absolute; top: 0px; width:<?php echo $LeftBannerW; ?>px; height:<?php echo $LeftBannerH; ?>px; overflow:hidden;"><?php  echo html_entity_decode(get_option('csnv_left_code')); ?></div>');
  267.                
  268.                 var MainContentW = <?php echo $MainContentW; ?>;
  269.                 var LeftBannerW = <?php echo $LeftBannerW; ?>;
  270.                 var RightBannerW = <?php echo $RightBannerW; ?>;
  271.                 var LeftAdjust = <?php echo $LeftAdjust; ?>;
  272.                 var RightAdjust = <?php echo $RightAdjust; ?>;
  273.                 var TopAdjust = <?php echo $TopAdjust; ?>;
  274.                 ShowAdDiv();
  275.                 window.onresize=ShowAdDiv;  
  276.             }
  277.         </script>
  278.         <?php endif; ?>
  279.     <?php endif;//End check mobile?>
  280.    
  281. <?php  
  282. }
  283.  
  284.  
  285. add_action('init', 'load_csnv_script');
  286.  
  287. /************Admin Panel***********/
  288. function csnv_ads_plugin_remove(){
  289.     delete_option('csnv_is_active');   
  290.     delete_option('screen_w');
  291.    
  292.     delete_option('csnv_content_w');
  293.     delete_option('csnv_left_w');
  294.     delete_option('csnv_left_h');
  295.     delete_option('csnv_right_w');
  296.     delete_option('csnv_right_h');
  297.     delete_option('csnv_margin_left');
  298.     delete_option('csnv_margin_right');
  299.     delete_option('csnv_margin_top');
  300.     delete_option('csnv_left_code');
  301.     delete_option('csnv_right_code');
  302.     delete_option('mobile_show');
  303. }
  304. function csnv_ads_plugin_install(){
  305.     add_option('csnv_is_active',1);
  306.     add_option('screen_w','1024');
  307.     add_option('csnv_content_w','1000');
  308.    
  309.     add_option('csnv_left_w','100');
  310.     add_option('csnv_left_h','500');
  311.    
  312.     add_option('csnv_right_w','100');
  313.     add_option('csnv_right_h','500');
  314.    
  315.     add_option('csnv_margin_left','10');
  316.     add_option('csnv_margin_right','10');
  317.     add_option('csnv_margin_top','80');
  318.     add_option('mobile_show','0');
  319.    
  320.     add_option('csnv_left_code','<a href="http://abc.lt" target="_blank"><img src="'.plugins_url('/leftbanner.jpg', __FILE__).'"  width ="100" alt="" /></a>');
  321.     add_option('csnv_right_code','<a href="http://abc.lt" target="_blank"><img src="'.plugins_url('/rightbanner.jpg', __FILE__).'"  width ="100" alt="" /></a>');  
  322. }
  323.  
  324. function csnv_ads_menu() {
  325.     add_options_page( __('Float Left Right Advertising',''), __('Float Left Right Advertising',''), 8, basename(__FILE__), 'csnv_ads_setting');
  326. }
  327. function csnv_ads_setting(){
  328.         if($_POST['status_submit']==1){        
  329.             update_option('csnv_is_active',intval($_POST['csnv_is_active']));
  330.             update_option('csnv_left_code',htmlentities(stripslashes($_POST['csnv_left_code'])));
  331.             update_option('csnv_right_code',htmlentities(stripslashes($_POST['csnv_right_code'])));
  332.            
  333.             update_option('csnv_content_w',intval($_POST['csnv_content_w']));
  334.            
  335.             update_option('csnv_left_w',intval($_POST['csnv_left_w']));
  336.             update_option('csnv_left_h',intval($_POST['csnv_left_h']));
  337.            
  338.             update_option('csnv_right_w',intval($_POST['csnv_right_w']));
  339.             update_option('csnv_right_h',intval($_POST['csnv_right_h']));
  340.            
  341.             update_option('csnv_margin_left',intval($_POST['csnv_margin_left']));
  342.             update_option('csnv_margin_right',intval($_POST['csnv_margin_right']));
  343.             update_option('csnv_margin_top',intval($_POST['csnv_margin_top']));
  344.             update_option('mobile_show',intval($_POST['mobile_show']));
  345.            
  346.             update_option('screen_w',intval($_POST['screen_w']));
  347.             echo '<div id="message" class="updated fade"><p>Your settings were saved !</p></div>';
  348.         }
  349.         if($_POST['status_submit']==2){
  350.             update_option('csnv_is_active',1);
  351.             update_option('screen_w','1024');
  352.             update_option('csnv_content_w','1000');
  353.             update_option('csnv_left_w','100');
  354.             update_option('csnv_left_h','500');
  355.            
  356.             update_option('csnv_right_w','100');
  357.             update_option('csnv_right_h','500');
  358.            
  359.             update_option('csnv_margin_left','10');
  360.             update_option('csnv_margin_right','10');
  361.             update_option('csnv_margin_top','80');
  362.            
  363.             update_option('mobile_show',0);
  364.            
  365.             update_option('csnv_left_code','<a href="http://abc.lt" target="_blank"><img src="'.plugins_url('/leftbanner.jpg', __FILE__).'" width ="100" alt="" /></a>');
  366.             update_option('csnv_right_code','<a href="http://abc.lt" target="_blank"><img src="'.plugins_url('/rightbanner.jpg', __FILE__).'"  width ="100" alt="" /></a>');   
  367.            
  368.             echo '<div id="message" class="updated fade"><p>Your settings were reset !</p></div>';
  369.         }
  370.     ?>
  371.     <h2>Float Left Right Advertising Setting</h2>
  372.     <form method="post" id="csnv_options"> 
  373.         <input type="hidden" name="status_submit" id="status_submit" value="2"  />
  374.         <table width="100%" cellspacing="2" cellpadding="5" class="editform">
  375.             <tr valign="top">
  376.                 <td width="150" scope="row">Active plugin:</td>
  377.                 <td>
  378.                     <label><input type="radio" name="csnv_is_active" <?php if (get_option('csnv_is_active')=='1'):?> checked="checked"<?php endif;?> value="1" />Yes</label>
  379.                     <label><input type="radio" name="csnv_is_active" <?php if (get_option('csnv_is_active')=='0'):?> checked="checked"<?php endif;?> value="0" />No</label>
  380.                 </td>
  381.             </tr>
  382.            
  383.             <tr valign="top">
  384.                 <td scope="row">Show ads if client <strong>screen width</strong> &gt;=</td>
  385.                 <td>
  386.                     <select name="screen_w">
  387.                         <option value="800" <?php if(get_option("screen_w")==800) echo "selected"; ?>>800</option>
  388.                         <option value="1024" <?php if(get_option("screen_w")==1024) echo "selected"; ?>>1024</option>
  389.                         <option value="1280" <?php if(get_option("screen_w")==1280) echo "selected"; ?>>1280</option>
  390.                     </select> px
  391.                 </td>
  392.             </tr>
  393.             <tr valign="top">
  394.                 <td  scope="row">Main content width:<br /><small>Width of your website</small></td>
  395.                 <td scope="row">           
  396.                     <input name="csnv_content_w" size="4" maxlength="4" value="<?php echo html_entity_decode(get_option('csnv_content_w'));?>" /> px (number only)
  397.                 </td>
  398.             </tr>
  399.            
  400.             <tr>
  401.                 <td>Show Ads on mobile devices</td>
  402.                 <td>
  403.                     <select name="mobile_show">
  404.                         <option value="1"<?php if(get_option("mobile_show")==1) echo " selected"; ?>>Yes</option>
  405.                         <option value="0"<?php if(get_option("mobile_show")==0) echo " selected"; ?>>No</option>
  406.                     </select>
  407.                 </td>
  408.             </tr>
  409.            
  410.             <tr valign="top">
  411.                 <td  scope="row">Banner Left:</td>
  412.                 <td scope="row">   
  413.                     <table cellspacing="10">
  414.                         <tr>
  415.                             <td>
  416.                                 <label>Width: <input name="csnv_left_w" size="3" maxlength="3" value="<?php echo html_entity_decode(get_option('csnv_left_w'));?>" /> px
  417.                                 <br /><small>Width of your left banner</small>
  418.                                 </label>
  419.                             </td>
  420.                             <td>
  421.                                 <label>Height: <input name="csnv_left_h" size="3" maxlength="3" value="<?php echo html_entity_decode(get_option('csnv_left_h'));?>" /> px
  422.                                 <br /><small>Height of your left banner</small>
  423.                                 </label>
  424.                             </td>
  425.                         </tr>
  426.                     </table>       
  427.                 </td>
  428.             </tr>
  429.            
  430.             <tr valign="top">
  431.                 <td  scope="row">Banner Right </td>
  432.                 <td scope="row">
  433.                     <table cellspacing="10">
  434.                         <tr>
  435.                             <td><label>Width:
  436.                     <input name="csnv_right_w" size="3" maxlength="3" value="<?php echo html_entity_decode(get_option('csnv_right_w'));?>" /> px <br /><small>Width of your right banner</small>
  437.                     </label></td>
  438.                         <td>
  439.                             <label>Height:
  440.                     <input name="csnv_right_h" size="3" maxlength="3" value="<?php echo html_entity_decode(get_option('csnv_right_h'));?>" /> px<br /><small>Height of your right banner</small>
  441.                     </label>
  442.                         </td>
  443.                         </tr>
  444.                     </table>
  445.                                
  446.                 </td>
  447.             </tr>
  448.            
  449.             <tr valign="top">
  450.                 <td  scope="row">Margin Left:</td>
  451.                 <td scope="row">           
  452.                     <input name="csnv_margin_left" size="3" maxlength="3" value="<?php echo html_entity_decode(get_option('csnv_margin_left'));?>" /> px (number only)
  453.                 </td>
  454.             </tr>
  455.             <tr valign="top">
  456.                 <td  scope="row">Margin Right:</td>
  457.                 <td scope="row">           
  458.                     <input name="csnv_margin_right" size="3" maxlength="3" value="<?php echo html_entity_decode(get_option('csnv_margin_right'));?>" /> px (number only)
  459.                 </td>
  460.             </tr>
  461.             <tr valign="top">
  462.                 <td  scope="row">Margin Top:</td>
  463.                 <td scope="row">           
  464.                     <input name="csnv_margin_top" size="3" maxlength="3" value="<?php echo html_entity_decode(get_option('csnv_margin_top'));?>" /> px (number only)
  465.                 </td>
  466.             </tr>
  467.            
  468.             <tr valign="top">
  469.                 <td  scope="row">HTML left Code:<br/><small>Put HTML code for your left ads</small></td>
  470.                 <td scope="row">           
  471.                     <textarea name="csnv_left_code" rows="5" cols="50"><?php echo html_entity_decode(get_option('csnv_left_code'));?></textarea>   
  472.                 </td>
  473.             </tr>
  474.             <tr valign="top">
  475.                 <td  scope="row">HTML right Code:<br/><small>Put HTML code for your right ads</small></td>
  476.                 <td scope="row">           
  477.                     <textarea name="csnv_right_code" rows="5" cols="50"><?php echo html_entity_decode(get_option('csnv_right_code'));?></textarea> 
  478.                 </td>
  479.             </tr>
  480.              <tr valign="top">
  481.                 <td  scope="row"></td>
  482.                 <td scope="row">           
  483.                     <input type="button" name="save" onclick="document.getElementById('status_submit').value='1'; document.getElementById('csnv_options').submit();" value="Save setting" class="button-primary" />
  484.                 </td>
  485.             </tr>
  486.             <tr><td colspan="2"><br /><br /></td></tr>
  487.             <tr valign="top">
  488.                 <td  scope="row"></td>
  489.                 <td scope="row">           
  490.                     <input type="button" name="reset" onclick="document.getElementById('status_submit').value='2'; document.getElementById('csnv_options').submit();" value="Reset to default setting" class="button" />
  491.                 </td>
  492.             </tr>
  493.         </table>
  494.        
  495.     </form>
  496.     <?php
  497. }
  498.  
  499. //add setting menu
  500. add_action('admin_menu', 'csnv_ads_menu');
  501. /* What to do when the plugin is activated? */
  502. register_activation_hook(__FILE__,'csnv_ads_plugin_install');
  503. /* What to do when the plugin is deactivated? */
  504. register_deactivation_hook( __FILE__, 'csnv_ads_plugin_remove' );
  505.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement