This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!

Plugin: Google Language Translator

By: rm2773 on Jan 19th, 2013  |  syntax: PHP  |  size: 10.85 KB  |  views: 49  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3.  
  4. /*
  5.  
  6. Plugin Name: Google Language Translator
  7.  
  8. Plugin URI: http://www.studio88design.com/plugins/google-language-translator
  9.  
  10. Version: 1.2
  11. Description: The MOST SIMPLE Google Translator plugin.  This plugin adds Google Translator to your website by using a single shortcode, [google-translator]. Setting options include: layout style, hide/show Google toolbar, and hide/show Google branding. Add the shortcode to pages, posts, and widgets.
  12.  
  13. Author: Rob Myrick
  14.  
  15. Author URI: http://www.studio88design.com/
  16.  
  17. */
  18.  
  19.  
  20. add_filter('widget_text', 'do_shortcode');
  21.  
  22. add_action('admin_menu', 'googlelanguagetranslator_menu_options');
  23.  
  24. add_option("googlelanguagetranslator_active","0");
  25.  
  26. add_shortcode( 'google-translator', 'google_translator_shortcode');
  27.  
  28. function google_translator_shortcode() {
  29.     if (get_option('googlelanguagetranslator_display')=='Vertical'){
  30.     echo googlelanguagetranslator_vertical();
  31.     }
  32.  
  33.     elseif(get_option('googlelanguagetranslator_display')=='Horizontal'){
  34.     echo googlelanguagetranslator_horizontal();
  35.     }
  36.    
  37.     if (get_option('googlelanguagetranslator_toolbar')=='Yes'){
  38.     echo googlelanguagetranslator_toolbar_yes();
  39.     }
  40.  
  41.     elseif(get_option('googlelanguagetranslator_toolbar')=='No'){
  42.     echo googlelanguagetranslator_toolbar_no();
  43.     }
  44.  
  45.     if (get_option('googlelanguagetranslator_showbranding')=='Yes'){
  46.     echo googlelanguagetranslator_showbranding_yes();
  47.     }
  48.  
  49.     elseif(get_option('googlelanguagetranslator_showbranding')=='No'){
  50.     echo googlelanguagetranslator_showbranding_no();
  51.    }
  52.  
  53. }
  54.  
  55. function googlelanguagetranslator_menu_options(){
  56.         add_options_page('Google Language Translator', 'Google Language Translator', 'manage_options', 'googlelanguagetranslator-menu-options', 'googlelanguagetranslator_menu');
  57.        
  58.         if(isset($_POST['googlelanguagetranslator_update_options'])){
  59.                 update_option('googlelanguagetranslator_display',$_POST['googlelanguagetranslator_display']);
  60.             update_option('googlelanguagetranslator_toolbar',$_POST['googlelanguagetranslator_toolbar']);
  61.             update_option('googlelanguagetranslator_showbranding',$_POST['googlelanguagetranslator_showbranding']);
  62.         }
  63.        
  64. }
  65.  
  66. function googlelanguagetranslator_menu(){
  67.         if (!current_user_can('manage_options'))  {
  68.                 wp_die( __('You do not have sufficient permissions to access this page.') );
  69.         }
  70.         ?>
  71.         <div class="wrap" style="width:65%">
  72.           <div id="icon-options-general" class="icon32"></div>
  73.       <h2>Google Language Translator</h2>
  74.       <div id="poststuff" class="metabox-holder has-right-sidebar" >
  75.       <div class="postbox" style="width: 100%">
  76.       <h3>Settings</h3>
  77. <form method="post" action="options.php">
  78.             <?php wp_nonce_field('update-options');?>
  79.             <table width="100%" border="0" cellspacing="8" cellpadding="0" class="form-table">
  80.               <tr>
  81.                 <td>Plugin Status:</td>
  82.                 <td><input type="checkbox"  name="googlelanguagetranslator_active" id="googlelanguagetranslator_active" value="1" <?php if(get_option('googlelanguagetranslator_active')==1){echo "checked";}?> />
  83.                 Click Here to Activate Google Language Translator</td>
  84.               </tr>
  85.  
  86.               <tr>
  87.                 <td width="25%">Display options:</td>
  88.                 <td width="75%">
  89.                 <select name="googlelanguagetranslator_display" id="googlelanguagetranslator_display" style="width:100px;">
  90.                 <option value="Vertical" <?php if(get_option('googlelanguagetranslator_display')=='Vertical'){echo "selected";}?>>Vertical</option>
  91.                 <option value="Horizontal" <?php if(get_option('googlelanguagetranslator_display')=='Horizontal'){echo "selected";}?>>Horizontal</option>
  92.                 </select>                </td>
  93.               </tr>
  94.  
  95.               <tr>
  96.                 <td width="25%">Show Google Toolbar?</td>
  97.                 <td width="75%">
  98.                 <select name="googlelanguagetranslator_toolbar" id="googlelanguagetranslator_toolbar" style="width:100px;">
  99.                 <option value="Yes" <?php if(get_option('googlelanguagetranslator_toolbar')=='Yes'){echo "selected";}?>>Yes</option>
  100.                 <option value="No" <?php if(get_option('googlelanguagetranslator_toolbar')=='No'){echo "selected";}?>>No</option>
  101.                 </select>                </td>
  102.               </tr>
  103.  
  104.               <tr>
  105.                 <td width="25%">Show Google Branding?</td>
  106.                 <td width="75%">
  107.                 <select name="googlelanguagetranslator_showbranding" id="googlelanguagetranslator_showbranding" style="width:100px;">
  108.                 <option value="Yes" <?php if(get_option('googlelanguagetranslator_showbranding')=='Yes'){echo "selected";}?>>Yes</option>
  109.                 <option value="No" <?php if(get_option('googlelanguagetranslator_showbranding')=='No'){echo "selected";}?>>No</option>
  110.                 </select>                </td>
  111.               </tr>
  112.              
  113.               <tr>
  114.                 <td>&nbsp;</td>
  115.                 <td><input type="submit" class="button-primary" value="<?php _e('Update Option')?>" name="googlelanguagetranslator_update_options" /></td>
  116.               </tr>
  117.               <tr>
  118.                 <td>&nbsp;</td>
  119.                 <td>&nbsp;</td>
  120.               </tr>
  121.                          
  122.                           <tr>
  123.                                 <td width="25%">Copy/Paste This Shortcode:</td>
  124.                 <td width="75%">
  125.                                   [google-translator]
  126.                 </td>
  127.               </tr>
  128.              
  129.           </table>
  130. <input type="hidden" name="action" value="update" />
  131.             <input type="hidden" name="page_options" value="googlelanguagetranslator_active" />
  132.         </form>
  133.        </div>
  134.        </div>
  135.        
  136.        <div id="poststuff" class="metabox-holder" style="float: left; width: 48%;">
  137.       <div class="postbox">
  138.       <h3>Another Plugin You Might Like:</h3>
  139.           <table class="form-table" width="100%">
  140.           <tr><td align="left" valign="top">
  141.               <table width="100%" border="0" cellspacing="0" cellpadding="4">
  142.                
  143.                 <tr>
  144.                   <td>
  145.                       <div>
  146.                         <div>
  147.                           <div>
  148.                             <a href="http://wordpress.org/extend/plugins/malware-finder/" target="_blank">Malware Finder</a>
  149.                             This plugin enables you to look inside all your WordPress files at once to find malicious code.<br>
  150.                           </div>
  151.                         </div>
  152.                       </div>
  153.                   </td>
  154.                 </tr>
  155.  
  156.                 <tr>
  157.                   <td><strong>You can also download this plugin at <a href="http://www.studio88design.com" target="_blank">www.studio88design.com</a></strong></td>
  158.                 </tr>
  159.               </table>
  160.             </td>
  161.                 </tr>
  162.         </table></div></div>
  163.        <div id="poststuff" class="metabox-holder" style="float: right; width: 48%;">
  164.        <div class="postbox">
  165.       <h3>Please Consider A Donation</h3>
  166.       <div class="inside">
  167.       If you like this plugin and find it useful, help keep this plugin actively developed by clicking the donate button <br /><br />
  168.        <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  169. <input type="hidden" name="cmd" value="_donations">
  170. <input type="hidden" name="business" value="robertmyrick@hotmail.com">
  171. <input type="hidden" name="lc" value="US">
  172. <input type="hidden" name="item_name" value="Support Studio 88 Design and help us bring you more Wordpress goodies!  Any donation is kindly appreciated.  Thank you!">
  173. <input type="hidden" name="no_note" value="0">
  174. <input type="hidden" name="currency_code" value="USD">
  175. <input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHostedGuest">
  176. <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
  177. <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
  178. </form>
  179.  
  180. <br /><br />
  181. </div>
  182. </div></div>
  183.           </div>
  184.      
  185.         <?php
  186. }
  187.  
  188. function googlelanguagetranslator_vertical(){
  189.         if(get_option('googlelanguagetranslator_active')==1){
  190.                 $str.='<div id="google_translate_element"></div><script>
  191.         function googleTranslateElementInit() {
  192.           new google.translate.TranslateElement({
  193.                 pageLanguage: \'en\'
  194.           }, \'google_translate_element\');
  195.         }
  196.         </script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>'; ?>
  197.         <div style='width:100%; height:40px'><?php echo $str; ?></div>
  198. <?php }
  199. }
  200.  
  201. function googlelanguagetranslator_horizontal(){
  202.         if(get_option('googlelanguagetranslator_active')==1){
  203.                 $str.='<div id="google_translate_element"></div><script>
  204.         function googleTranslateElementInit() {
  205.           new google.translate.TranslateElement({
  206.                 pageLanguage: \'en\', layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL
  207.           }, \'google_translate_element\');
  208.         }
  209.         </script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>'; ?>
  210.                 <div style='width:100%; height:40px'><?php echo $str; ?></div>
  211. <?php }
  212. }
  213.  
  214. function googlelanguagetranslator_toolbar_yes(){
  215.   if(get_option('googlelanguagetranslator_active')==1) {
  216.         $str.='<style type="text/css">
  217. #google_translate_element {color: transparent;}
  218. .goog-te-gadget .goog-te-combo {margin: 2px 0px !important;}
  219. .goog-tooltip {display: none !important;}
  220. .goog-tooltip:hover {display: none !important;}
  221. .goog-text-highlight {background-color: transparent !important; border: none !important;box-shadow: none !important;}
  222. </style>';
  223.         echo $str;
  224.   }
  225. }
  226.  
  227. function googlelanguagetranslator_toolbar_no(){
  228.   if(get_option('googlelanguagetranslator_active')==1) {
  229. $str.='<style type="text/css">
  230.  
  231.  
  232. .goog-te-banner-frame{visibility:hidden !important;}
  233. body {top:0px !important;}
  234. </style>';
  235.         echo $str;
  236.   }
  237. }
  238.  
  239. function googlelanguagetranslator_showbranding_yes() {
  240.   if(get_option('googlelanguagetranslator_active')==1) {
  241.         $str.='<style type="text/css">
  242.  
  243. .goog-te-gadget .goog-te-combo {margin: 2px 0px !important;}
  244. .goog-tooltip {display: none !important;}
  245. .goog-tooltip:hover {display: none !important;}
  246. .goog-text-highlight {background-color: transparent !important; border: none !important; box-shadow: none !important;}
  247. </style>';
  248.         echo $str;
  249.   }
  250. }
  251.  
  252. function googlelanguagetranslator_showbranding_no() {
  253.   if(get_option('googlelanguagetranslator_active')==1) {
  254. $str.='<style type="text/css">
  255. #google_translate_element a {display: none;}
  256. div.goog-te-gadget {color: transparent !important;}
  257. .goog-te-gadget .goog-te-combo {margin: 2px 0px !important;}
  258. .goog-tooltip {display: none !important;}
  259. .goog-tooltip:hover {display: none !important;}
  260. .goog-text-highlight {background-color: transparent !important; border: none !important; box-shadow: none !important;}
  261. </style>';
  262.         echo $str;
  263.   }
  264. }
  265.  
  266. ?>
clone this paste RAW Paste Data