1. <?php
  2. /*
  3. Plugin Name: Active Share by OrangeSoda
  4. Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
  5. Description: Active share provides a box that shows up on individual posts once users have scrolled a specified amount to share the page.
  6. Version: 1.041
  7. Author: Dan Garfield for OrangeSoda.com
  8. Author URI: http://URI_Of_The_Plugin_Author
  9. License: GPL2
  10. */
  11.  
  12.  
  13. class active_share_NOT_genesis {
  14.     private $as_tshares = array(
  15.         array(
  16.         "name" => "Twitter",
  17.         "id" => "as-twitter",
  18.         "js" => "",
  19.         "style" => "float:left; margin: 0 5px; padding: 3px 0 0 0;",
  20.         "code" => '<a href="http://twitter.com/share" class="twitter-share-button" data-count="vertical">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>'
  21.         ),
  22.    
  23.         array(
  24.         "name" => "Tweetmeme",
  25.         "id" => "as-tweetmeme",
  26.         "js" => "",
  27.         "style" => "float:left; margin: 0 5px; padding: 3px 0 0 0;",
  28.         "code" => '<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script>'),
  29.        
  30.         array( 
  31.         "name" => "Google Buzz",
  32.         "id" => "as-buzzwidget",
  33.         "js" => "",
  34.         "style" => "float: left; margin: 0 5px;",
  35.         "code" => "<a title='Post to Google Buzz' class='google-buzz-button' href='http://www.google.com/buzz/post' data-button-style='normal-count'></a><script type='text/javascript' src='http://www.google.com/buzz/api/button.js'></script>"
  36.         ),
  37.    
  38.         array(
  39.         "name" => "Facebook",
  40.         "id" => "as-facebook",
  41.         "js" => "",
  42.         "style" => "float: left; margin: 0 5px; padding: 3px 0 0;",
  43.         "code" => '<a name="fb_share" type="box_count" href="http://www.facebook.com/sharer.php">Share</a>
  44.     <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>'
  45.         ),
  46.        
  47.         array(
  48.         "name" => "StumbleUpon",
  49.         "id" => "as-stumbleupon",
  50.         "js" => "",
  51.         "style" => "float: left; margin: 0 5px; padding: 4px 0px 0px;",
  52.         "code" => "<script src='http://www.stumbleupon.com/hostedbadge.php?s=5'></script>"
  53.         ),
  54.        
  55.         array(
  56.         "name" => "Reddit",
  57.         "id" => "as-reddit",
  58.         "js" => "",
  59.         "style" => "float: left; margin: 0 5px; padding: 4px 0px 0px;",
  60.         "code" => '<script type="text/javascript" src="http://reddit.com/static/button/button2.js"></script>'
  61.         ),
  62.        
  63.         array(
  64.         "name" => "Digg",
  65.         "id" => "as-digg",
  66.         "js" => "digg.js",
  67.         "style" => "float: left; margin: 0 5px; padding: 3px 0px 0px;",
  68.         "code" => '<script type="text/javascript">(function() {
  69. var s = document.createElement("SCRIPT"), s1 = document.getElementsByTagName("SCRIPT")[0];
  70. s.type = "text/javascript";
  71. s.async = true;
  72. s.src = "http://widgets.digg.com/buttons.js";
  73. s1.parentNode.insertBefore(s, s1);
  74. })();
  75. </script>
  76. <!-- Medium Button -->
  77. <a class="DiggThisButton DiggMedium"></a>'
  78.         )
  79.  
  80.     );
  81.        
  82.     function active_share_NOT_genesis() {
  83.        
  84.     }
  85.     //****************************************************************************************
  86.     //Set Functions
  87.     //****************************************************************************************
  88.     //output functions
  89.     function comment_marker($content=''){
  90.         $options = get_option('as_options');
  91.         if($options['as-posts']==1&&is_single()){
  92.             $content .= "<div id='active-share-comment-marker'></div>";
  93.         }
  94.         else if($options['as-pages']==1&&is_page()){
  95.             $content .= "<div id='active-share-comment-marker'></div>";
  96.         }
  97.         return $content;
  98.     }
  99.    
  100.     function jquery() {
  101.        
  102.     }
  103.    
  104.     function ass_loadjs(){
  105.         DEFINE('get_plugin_directory_uri', get_bloginfo('wpurl') . '/wp-content/plugins/active-share-by-orangesoda/');
  106.         $options = get_option('as_options');
  107.         if(($options['as-posts']==1&&is_single())||($options['as-pages']==1&&is_page())){
  108.             wp_register_script('active-share',
  109.             get_plugin_directory_uri . 'active-share.js', array('jquery'),'1.0');
  110.             wp_enqueue_script('active-share');
  111.         }
  112.        
  113. //      if(is_single()||is_page()){
  114. //         
  115. //          wp_register_script('active-share',
  116. //          get_plugin_directory_uri . 'active-share.js', array('jquery'),'1.0');
  117. //          wp_enqueue_script('active-share');
  118. //
  119. //      }
  120.     }
  121.    
  122.     function html2rgb($color)
  123.     {
  124.         if ($color[0] == '#')
  125.             $color = substr($color, 1);
  126.    
  127.         if (strlen($color) == 6)
  128.             list($r, $g, $b) = array($color[0].$color[1],
  129.                                      $color[2].$color[3],
  130.                                      $color[4].$color[5]);
  131.         elseif (strlen($color) == 3)
  132.             list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
  133.         else
  134.             return false;
  135.    
  136.         $r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
  137.    
  138.         return "$r, $g, $b";
  139.     }
  140.    
  141.     function print_shares($id){
  142.         if (function_exists('wp_reset_postdata')){
  143.             wp_reset_postdata();
  144.         }
  145.         $options = get_option('as_options');
  146.         if(($options['as-posts']==1&&is_single())||($options['as-pages']==1&&is_page())){
  147.             $as_tshares = $this->as_tshares;           
  148.             $title = get_the_title($id);
  149.             $bgcolor = "rgba(" . $this->html2rgb($options['as-bgcolor']) . ", " . $options['as-opacity']/100 . ")";
  150.             $color = $options['as-color'];
  151.             $twocolor = $options['as-twocolor'];
  152.             $width = $options['as-width'];
  153.             $message = $options['as-message'];
  154.             print "<div id='as-share-window' style='width: 100%; display: block; position: fixed; top: -450px; left: 0px; background-color: $bgcolor; z-index: 100; padding: 0 0 10px 0;'><div style='width: " . $width . "px; margin: 20px auto;'>";
  155.            
  156.             foreach ($as_tshares AS $theshare){
  157.                 if($options[$theshare['id']]==1) {
  158.                     print "<span id ='" . $theshare['id'] . "' style='" . $theshare['style'] . "'>" . $theshare['code'] . "</span>";
  159.                 }
  160.             }
  161.            
  162.             ?>
  163.             <span style='display:block; margin: 0 5px; padding: 5px 0px 0px; color: <?php print $twocolor; ?>'><?php print $message;?><br /><span style='color: <?php print $color; ?>; font-size: 18px;'><?php print $title; ?></span></span>
  164.             </div>
  165.             </div>
  166.             <?php
  167.         }
  168.     }
  169.        
  170.     //admin functions
  171.     function active_share_settings() {
  172.         if (!current_user_can('manage_options'))  {
  173.             wp_die( __('You do not have sufficient permissions to access this page.') );
  174.         }
  175.         //If posting to the form
  176.         if($_POST['checks']&&$_POST['as-bgcolor']&&$_POST['as-color']){
  177.             $oldoptions = get_option('as_options'); //load old options
  178.             $update = array(
  179.                 'as-posts'=>'',
  180.                 'as-pages'=>'',
  181.                 'as-message'=>$_POST['as-message'],
  182.                 'as-width'=>'',
  183.                 'as-level'=>'');
  184.             $checkboxes = array(
  185.                 'as-posts'=>'',
  186.                 'as-pages'=>''
  187.             );
  188.             foreach ($this->as_tshares AS $theshare){
  189.                 $update[$theshare['id']]='';
  190.                 $checkboxes[$theshare['id']]='';
  191.             }
  192.            
  193.             //validation, old change color if a valid hex colorcode
  194.             if(preg_match('(#?([A-Fa-f0-9]){3}(([A-Fa-f0-9]){3})?)', $_POST['as-bgcolor'])) {
  195.                 $update['as-bgcolor'] = $_POST['as-bgcolor'];
  196.             }
  197.             else {
  198.                 $update['as-bgcolor'] = $oldoptions['as-bgcolor'];
  199.             }
  200.             if(preg_match('(#?([A-Fa-f0-9]){3}(([A-Fa-f0-9]){3})?)', $_POST['as-color'])) {
  201.                 $update['as-color'] = $_POST['as-color'];
  202.             }
  203.             else {
  204.                 $update['as-color'] = $oldoptions['as-color'];
  205.             }
  206.             if(preg_match('(#?([A-Fa-f0-9]){3}(([A-Fa-f0-9]){3})?)', $_POST['as-twocolor'])) {
  207.                 $update['as-twocolor'] = $_POST['as-twocolor'];
  208.             }
  209.             else {
  210.                 $update['as-color'] = $oldoptions['as-color'];
  211.             }
  212.             if($_POST['as-width'] < 1500 && $_POST['as-width'] > 600) {
  213.                 $update['as-width'] = $_POST['as-width'];
  214.             }
  215.             else {
  216.                 $update['as-width'] = 800;
  217.             }
  218.             if($_POST['as-opacity'] <= 100 && $_POST['as-opacity'] >= 0) {
  219.                 $update['as-opacity'] = $_POST['as-opacity'];
  220.             }
  221.             else {
  222.                 $update['as-opacity'] = 80;
  223.             }
  224.            
  225.             //check if a checkbox is present, if so mark it as 1 in the DB else mark as 0
  226.             $checked = array_flip($_POST['checks']);
  227.             foreach($checkboxes AS $check => $null){
  228.                 if(isset($checked[$check])){
  229.                     $update[$check] = 1;
  230.                 }
  231.                 else {
  232.                     $update[$check] = 0;
  233.                 }
  234.             }
  235.            
  236.             update_option('as_options', $update); //update options
  237.            
  238.         }
  239.    
  240.         $option = get_option('as_options'); //load options for form display
  241.     ?>
  242.         <div class="wrap"><form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
  243.         <?php settings_fields( 'active-share-group' ); ?>
  244.         <h1>Active Share Settings</h1><p style="width: 500px">Active Share is a free plugin provided by <a href="http://orangesoda.com">OrangeSoda</a> and written by Dan Garfield. For marketing tips <a href="http://twitter.com/orangesoda">follow OrangeSoda on twitter</a>. This plugin was inspired by a similar feature on okcupid's blog. Their blog is awesome and you should <a href="http://blog.okcupid.com/">check it out</a>.</p>
  245.         <h2>Placement Options</h2>
  246.         <p>
  247.             <table class="form-table">
  248.                 <tr>
  249.                 <th scope="row">Posts</th>
  250.                 <td><input type="checkbox" <?php echo $this->checkboxes($option["as-posts"]);?> name="checks[]" value="as-posts" /></td>
  251.                 </tr>
  252.                 <tr>
  253.                 <th scope="row">Pages</th>
  254.                 <td><input type="checkbox" <?php echo $this->checkboxes($option["as-pages"]);?> name="checks[]" value="as-pages" /></td>
  255.                 </tr>
  256.             </table>
  257.         </p>
  258.         <h2>Sharing Services</h2>
  259.         <p>
  260.             <table class="form-table">
  261.             <?php
  262.                 foreach ($this->as_tshares AS $theshare){
  263.                     print '<tr valign="top">';
  264.                     print '<th scope="row">Show ' . $theshare["name"] . '</th>';
  265.                     print '<td><input type="checkbox"' . $this->checkboxes($option[$theshare["id"]]) . 'name="checks[]" value="' . $theshare["id"] . '" /></td>';
  266.                     print '</tr>';
  267.                 }
  268.             ?>
  269.             </table>
  270.         </p>
  271.        
  272.         <h2>Style Settings</h2>
  273.         <p>
  274.             <table class="form-table">
  275.                 <tr valign="top">
  276.                 <th scope="row">Background Color</th>
  277.                 <td><input type="text" name="as-bgcolor" value="<?php echo $option['as-bgcolor']; ?>" /></td>
  278.                 </tr>
  279.                 <tr valign="top">
  280.                 <th scope="row">Background Opacity (0=transparent, 100=opaque)</th>
  281.                 <td><input type="text" name="as-opacity" value="<?php echo $option['as-opacity']; ?>" /></td>
  282.                 </tr>
  283.                 <tr valign="top">
  284.                 <th scope="row">Text Color</th>
  285.                 <td><input type="text" name="as-color" value="<?php echo $option['as-color']; ?>" /></td>
  286.                 <tr valign="top">
  287.                 <th scope="row">Message Color</th>
  288.                 <td><input type="text" name="as-twocolor" value="<?php echo $option['as-twocolor']; ?>" /></td>
  289.                 </tr>
  290.                 <tr valign="top">
  291.                 <th scope="row">Message Text</th>
  292.                 <td><input type="text" name="as-message" value="<?php echo $option['as-message']; ?>" /></td>
  293.                 </tr>
  294.                 <tr valign="top">
  295.                 <th scope="row">Width (between 600 and 1500</th>
  296.                 <td><input type="text" name="as-width" value="<?php echo $option['as-width']; ?>" /></td>
  297.                 </tr>
  298.             </table>
  299.         </p>
  300.        
  301.         <p class="submit">
  302.             <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
  303.         </p>
  304.     </p>
  305.     </form>
  306.     </div>
  307.    
  308.     <?php
  309.     }
  310.    
  311.     function checkboxes($option) {
  312.         if($option==1) {
  313.             $return = 'checked="checked"';
  314.         }
  315.         else {
  316.             $return = '';
  317.         }
  318.         return $return;
  319.     }
  320.    
  321.    
  322.     //****************************************************************************************
  323.     //add options
  324.     //****************************************************************************************
  325.     function as_add_options() {
  326.         $as_tshare = $this->as_tshares;
  327.         $as_option = array();
  328.         $i = 0;
  329.         $en = 1;
  330.         foreach ($as_tshare AS $theshare){
  331.             if ($i == 0){ $en = 0; $i++; }
  332.             else if($i<4){ $en = 1; $i++; }
  333.             else { $en = 0; }
  334.             $as_option[$theshare['id']] = $en;
  335.         }
  336.        
  337.         $as_option['as-posts'] = 1;
  338.         $as_option['as-pages'] = 1;
  339.         $as_option['as-bgcolor'] = '#000000';
  340.         $as_option['as-color'] = '#FFFFFF';
  341.         $as_option['as-opacity'] = '100';
  342.         $as_option['as-twocolor'] = '#9F9F9F';
  343.         $as_option['as-message'] = 'be a pal and share this would ya?';
  344.         $as_option['as-width'] = 800;
  345.         $as_option['as-level'] = 1;
  346.    
  347.         add_option("as_options", $as_option);
  348.        
  349.    
  350.     }
  351. }
  352.  
  353.  
  354.  
  355. global $as_share;
  356. $as_share = new active_share_NOT_genesis();
  357.  
  358. function active_share_menu() {
  359.     global $as_share;
  360.         add_options_page(__('Active Share Settings','active-share-settings'), __('Active Share Settings','active-share-settings'), 'manage_options',  'active_share_NOT_genesis', array(&$as_share, 'active_share_settings'));
  361.    
  362. }
  363.  
  364. //****************************************************************************************
  365. //add filters and actions
  366. //****************************************************************************************
  367. //function actions and filters
  368. add_filter('the_content', array(&$as_share, 'comment_marker'));
  369. add_action('wp_print_scripts',  array(&$as_share, 'ass_loadjs'), 10, 1);
  370. add_action('wp_footer', array(&$as_share, 'print_shares'), 1, 1);
  371.  
  372. //options actions and filters
  373. if ( is_admin() ){ // admin actions
  374.     add_action('admin_menu', 'active_share_menu');
  375.     add_action( 'admin_init', array(&$as_share, 'as_add_options' ));
  376. }
  377.  
  378. ?>