Location: PHPKode > scripts > Quick Notice > quick-notice/quick-notice.php
<?php 
/**
 * @package Quick Notice
 * @author Shaon
 * @version 1.0.2
 */
/*
Plugin Name: Quick Notice Bar
Plugin URI: http://www.wpeden.com/
Description: Display important message/notice from site admin to visitor
Author: Shaon
Version: 1.0.2
Author URI: http://www.wpeden.com/
*/
 

$plugindir = str_replace('\\','/',dirname(__FILE__));
 

define('PLUGINDIR',$plugindir);  

function wpqn_install(){      
    add_option('wpp_redirect', true); 
    
}

function wpqn_redirect(){
    if (get_option('wpp_redirect', false)) {
        delete_option('wpp_redirect');
        wp_redirect(home_url('/wp-admin/admin.php?page=quick-notice'));
    }
}


function wpqn_save_notice(){
    if($_POST['notice']) {
       update_option('_wpqn_notice', $_POST['notice']);       
       update_option('_wpqn_disabled', $_POST['_wpqn_disabled']);       
   }
   die('Notice Updated');
} 

 
function wpqn_admin_options(){   
    $notice = get_option('_wpqn_notice');
    ?>
   <style type="text/css">
   .inm{
       padding-left: 10px;
       color: #008000;
       font-weight: bold;
   }
   </style>
   <div class="wrap">
   <div class="icon32" id="icon-plugins"><br></div>
   <h2>Setup Quick Notice</h2> <br>
   <form action="" method="post" id="wpqn">
    <input type="hidden" name="action" value="wpqn_save_notice">
    <label>Message:</label>
    <input type="text" name="notice[message]" value="<?php echo htmlspecialchars(stripcslashes($notice['message'])); ?>" style="font-size: 14pt;padding:3px 10px;width:100%;">
    <br clear="all" />
    <br clear="all" />
    <div style="width: 30%;float:left;margin-right: 25px;">
    <label>Link URL:</label><br/>
    <input type="text" name="notice[url]" value="<?php echo $notice['url']; ?>" style="padding:3px 10px;width:100%;">
    <br clear="all" />
    <br clear="all" />    
    <label>Link Label:</label><br/>
    <input type="text" name="notice[link_label]" value="<?php echo $notice['link_label']?$notice['link_label']:'Read More &#187;'; ?>" style="padding:3px 10px;width:100%;">
    </div>
    <div style="width: 50%;float:left;">
    <label>Background CSS Style: <em>( you can copy exclusive css styles from <a href='http://www.colorzilla.com/gradient-editor/' target="_blank" style="font-weight:bold">here</a> )</em></label><br/>
    <input type="text" name="notice[bg_css]" value="<?php echo $notice['bg_css']?$notice['bg_css']:"background: #6d0019;background: -moz-linear-gradient(top, #6d0019 0%, #a90329 74%);background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6d0019), color-stop(74%,#a90329));background: -webkit-linear-gradient(top, #6d0019 0%,#a90329 74%);background: -o-linear-gradient(top, #6d0019 0%,#a90329 74%);background: -ms-linear-gradient(top, #6d0019 0%,#a90329 74%);filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6d0019', endColorstr='#a90329',GradientType=0 );background: linear-gradient(top, #6d0019 0%,#a90329 74%);"; ?>" style="padding:3px 10px;width:100%;">
    <br clear="all" />
    <br clear="all" />
    <table width="100%">
    <tr><td>
    <label>Text Color:</label><br/>
    <input type="text" name="notice[text_color]" value="<?php echo $notice['text_color']?$notice['text_color']:'#ffffff'; ?>" style="padding:3px 10px;width:120px;">
    </td>
    <td>
    <label>Font:</label><br/>
    <select name="notice[font]">
    <option value="Michroma" <?php echo $notice['font']=='Michroma'?'selected=selected':''; ?> >Michroma</option>
    <option value="Oswald" <?php echo $notice['font']=='Oswald'?'selected=selected':''; ?>>Oswald</option>
    <option value="Lobster+Two" <?php echo $notice['font']=='Lobster+Two'?'selected=selected':''; ?> >Lobster Two</option>
    <option value="Nixie+One" <?php echo $notice['font']=='Nixie+One'?'selected=selected':''; ?> >Nixie One</option>
    <option value="Kameron" <?php echo $notice['font']=='Kameron'?'selected=selected':''; ?> >Kameron</option>    
    <option value="Shadows+Into+Light" <?php echo $notice['font']=='Shadows+Into+Light'?'selected=selected':''; ?> >Shadows Into Light</option>    
    <option value="Special+Elite" <?php echo $notice['font']=='Special+Elite'?'selected=selected':''; ?> >Special Elite</option>
    <option value="Jura" <?php echo $notice['font']=='Jura'?'selected=selected':''; ?> >Jura</option>
    <option value="Artifika" <?php echo $notice['font']=='Artifika'?'selected=selected':''; ?> >Artifika</option>
    <option value="Bevan" <?php echo $notice['font']=='Bevan'?'selected=selected':''; ?> >Bevan</option>
    <option value="Maven+Pro" <?php echo $notice['font']=='Maven+Pro'?'selected=selected':''; ?> >Maven Pro</option>
    <option value="Tenor+Sans" <?php echo $notice['font']=='Tenor+Sans'?'selected=selected':''; ?> >Tenor Sans</option>
    <option value="Metrophobic" <?php echo $notice['font']=='Metrophobic'?'selected=selected':''; ?> >Metrophobic</option>
    <option value="Ultra" <?php echo $notice['font']=='Ultra'?'selected=selected':''; ?> >Ultra</option>
    <option value="Muli" <?php echo $notice['font']=='Muli'?'selected=selected':''; ?> >Muli</option>
    <option value="Anonymous+Pro" <?php echo $notice['font']=='Anonymous Pro'?'selected=selected':''; ?> >Anonymous Pro</option>
    <option value="Paytone+One" <?php echo $notice['font']=='Paytone+One'?'selected=selected':''; ?> >Paytone One</option>
    <option value="Francois+One" <?php echo $notice['font']=='Francois+One'?'selected=selected':''; ?> >Francois One</option>
    <option value="Verdana" <?php echo $notice['font']=='Verdana'?'selected=selected':''; ?> >Verdana</option>
    <option value="Tahoma" <?php echo $notice['font']=='Tahoma'?'selected=selected':''; ?> >Tahoma</option>
    </select>
    </td>
    <td>
    <label>Font Size:</label><br/>
    <input type="text" name="notice[font_size]" value="<?php echo $notice['font_size']?$notice['font_size']:'12'; ?>" style="padding:3px 10px;width:50px;"> pt
    </td>
    <td>
    <label>Font Weight:</label><br/>
    <select name="notice[font_weight]">
    <option value="normal">Normal</option>
    <option value="bold" <?php echo $notice['font_weight']=='bold'?'selected=selected':''; ?>>Bold</option>
    </select>
    </td>
    </tr>
    </table>    
    
    </div>
    <br>
    
    <br clear="all" />
    <br clear="all" />
    <input type="checkbox" name="_wpqn_disabled" value="1"> Hide Notice Bar from site 
    <br clear="all" />
    <br clear="all" />
    <input type="submit" id="btn" class="button-primary" value="Save Changes"> 
    <span id="loading" style="display: none;"><img src="images/loading.gif" alt=""> saving...</span>
    </form>
    </div>
    <script language="JavaScript">
    <!--
      jQuery('#wpqn').submit(function(){
           jQuery(this).ajaxSubmit({
               'url': ajaxurl,
               'beforeSubmit':function(){
                   jQuery('#loading').fadeIn();
               },
               'success':function(res){
                   jQuery('#loading').fadeOut();
               }
           });
      return false;
      });
    //-->
    </script>
    <?php 
   
}

function wpqn_show_notice(){
    if(get_option('_wpqn_disabled',0)==1) return;
    $notice = get_option('_wpqn_notice');
?>
<link href='http://fonts.googleapis.com/css?family=<?php echo $notice['font']; ?>&v1' rel='stylesheet' type='text/css'>
<style type="text/css">
.wpqn{
<?php echo $notice['bg_css']?stripcslashes($notice['bg_css']):"background: #6d0019;background: -moz-linear-gradient(top, #6d0019 0%, #a90329 74%);background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6d0019), color-stop(74%,#a90329));background: -webkit-linear-gradient(top, #6d0019 0%,#a90329 74%);background: -o-linear-gradient(top, #6d0019 0%,#a90329 74%);background: -ms-linear-gradient(top, #6d0019 0%,#a90329 74%);filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6d0019', endColorstr='#a90329',GradientType=0 );background: linear-gradient(top, #6d0019 0%,#a90329 74%);"; ?>
border-bottom: 3px solid #fff;
-moz-box-shadow: 0 0 5px #888;
-webkit-box-shadow: 0 0 5px#888;
box-shadow: 0 0 5px #888;
z-index:999999;
font-size: <?php echo $notice['font_size']?$notice['font_size']:'12'; ?>pt; 
font-family: '<?php echo str_replace("+"," ",$notice['font']); ?>';
text-align: center;
color: <?php echo $notice['color']?$notice['color']:'#ffffff'; ?>;
font-weight: <?php echo $notice['font_weight']?$notice['font_weight']:'normal'; ?>;
line-height: 35px;
}
.wpqn_down{
<?php echo $notice['bg_css']?stripcslashes($notice['bg_css']):"background: #6d0019;background: -moz-linear-gradient(top, #6d0019 0%, #a90329 74%);background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6d0019), color-stop(74%,#a90329));background: -webkit-linear-gradient(top, #6d0019 0%,#a90329 74%);background: -o-linear-gradient(top, #6d0019 0%,#a90329 74%);background: -ms-linear-gradient(top, #6d0019 0%,#a90329 74%);filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6d0019', endColorstr='#a90329',GradientType=0 );background: linear-gradient(top, #6d0019 0%,#a90329 74%);"; ?>
border-bottom: 3px solid #fff;
border-left: 3px solid #fff;
border-right: 3px solid #fff;
-moz-box-shadow: 0 0 5px #888;
-webkit-box-shadow: 0 0 5px#888;
box-shadow: 0 0 5px #888;
z-index:999999;
font-size: <?php echo $notice['font_size']?$notice['font_size']:'12'; ?>pt; 
font-family: '<?php echo str_replace("+"," ",$notice['font']); ?>';
text-align: center;
color: <?php echo $notice['color']?$notice['color']:'#ffffff'; ?>;
font-weight: <?php echo $notice['font_weight']?$notice['font_weight']:'normal'; ?>;
height: 35px;
-webkit-border-bottom-right-radius: 6px;
-webkit-border-bottom-left-radius: 6px;
-moz-border-radius-bottomright: 6px;
-moz-border-radius-bottomleft: 6px;
border-bottom-right-radius: 6px;
border-bottom-left-radius: 6px;
}
.wpqn a{
   color: <?php echo $notice['color']?$notice['color']:'#ffffff'; ?>; 
}

/*body{
    margin-top: 40px;
}*/

</style>
  <div style="width: 100%;position: fixed;top:0px;" class="wpqn" id="wpqn" onclick="jQuery('#wpqn').slideUp(function(){jQuery('#wpqn_down').slideDown();});">
  <?php echo htmlspecialchars_decode(stripcslashes($notice['message'])); ?>&nbsp;&nbsp;&nbsp;&nbsp;
  <?php if($notice['url']!=''){ ?>
  <a href='<?php echo $notice['url']; ?>'><?php echo $notice['link_label']; ?></a>
  <?php } ?>
  <img src="<?php echo plugins_url(); ?>/quick-notice/images/up.png" style="position: absolute;cursor:pointer;right:0px;margin-right: 20px;margin-top: 2px;" onclick="" />
  </div>
  
  <div style="width: 40px;position: fixed;top:0px;cursor:pointer;right:0px;margin-right: 15px;display: none;" class="wpqn_down" id="wpqn_down">
  <img src="<?php echo plugins_url(); ?>/quick-notice/images/down.png" onclick="jQuery('#wpqn_down').slideUp(function(){jQuery('#wpqn').slideDown();});" />
  </div>
  
<?php    
}


function wpqn_menu(){
    add_menu_page("Quick Notice","Quick Notice",'administrator','quick-notice','wpqn_admin_options');    
    
}

if(is_admin()){
    add_action("admin_menu","wpqn_menu");
    wp_enqueue_script("jquery");
    wp_enqueue_script("jquery-form",plugins_url().'/wordpress-perfection/jquery.form.js');    
    add_action('wp_ajax_wpqn_save_notice','wpqn_save_notice');
}else{
    add_action('wp_footer','wpqn_show_notice');
}
 

register_activation_hook(__FILE__,'wpqn_install');
add_action('admin_init','wpqn_redirect');
Return current item: Quick Notice