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

Untitled

By: a guest on Aug 1st, 2012  |  syntax: PHP  |  size: 6.35 KB  |  views: 47  |  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. Plugin Name: Teamspeak 3 Widget for Wordpress
  4. Plugin URI: http://michaelplas.de
  5. Description: Allows to show the Users and Channels of a Teamspeak3 as a Widget ( TS VIEWER )
  6. Author: Michael Plas
  7. Version: 1.0.3
  8. Author URI: http://www.michaelplas.de
  9. License: GPL 2.0, @see http://www.gnu.org/licenses/gpl-2.0.html
  10. */
  11.  
  12. class ts3_wp_viewer{
  13.  
  14.     function init() {
  15.         // check for the required WP functions, die silently for pre-2.2 WP.
  16.         if (!function_exists('wp_register_sidebar_widget'))
  17.                 return;
  18.  
  19.         // load all l10n string upon entry
  20.         load_plugin_textdomain('ts3_wp_viewer');
  21.  
  22.         // let WP know of this plugin's widget view entry
  23.         wp_register_sidebar_widget('ts3_wp_viewer', __('TS3 Viewer Widget', 'ts3_wp_viewer'), array('ts3_wp_viewer', 'widget'),
  24.             array(
  25.                 'classname' => 'ts3_wp_viewer',
  26.                 'description' => __('Allows to show the Users and Channels of a Teamspeak3 as a Widget ( TS VIEWER )', 'ts3_wp_viewer')
  27.             )
  28.         );
  29.  
  30.         // let WP know of this widget's controller entry
  31.         wp_register_widget_control('ts3_wp_viewer', __('Teamspeak3 Viewer', 'ts3_wp_viewer'), array('ts3_wp_viewer', 'control'),
  32.             array('width' => 300)
  33.         );
  34.  
  35.         // short code allows insertion of ts3_wp_viewer into regular posts as a [ts3_wp_viewer] tag.
  36.         // From PHP in themes, call do_shortcode('ts3_wp_viewer');
  37.         add_shortcode('ts3_wp_viewer', array('ts3_wp_viewer', 'shortcode'));
  38.     }
  39.  
  40.         // back end options dialogue
  41.         function control() {
  42.             $options = get_option('ts3_wp_viewer');
  43.                 if (!is_array($options))
  44.                         $options = array('serverip'=>'127.0.0.1','queryport'=>'10011', 'virtualserverport'=>'9987', 'name'=>'Teamspeak 3 Viewer');
  45.                 if ($_POST['ts3_wp_viewer-submit']) {
  46.                         $options['serverip'] = strip_tags(stripslashes($_POST['ts3_wp_viewer-serverip']));
  47.                         $options['virtualserverport'] = strip_tags(stripslashes($_POST['ts3_wp_viewer-virtualserverport']));
  48.                         $options['queryport'] = strip_tags(stripslashes($_POST['ts3_wp_viewer-queryport']));
  49.                         $options['name'] = strip_tags(stripslashes($_POST['ts3_wp_viewer-name']));
  50.                         $options['displaynamesonly'] = strip_tags(stripslashes($_POST['ts3_wp_viewer-displaynamesonly']));
  51.                         update_option('ts3_wp_viewer', $options);
  52.                 }
  53.                 $serverip = htmlspecialchars($options['serverip'], ENT_QUOTES);
  54.                         $queryport = htmlspecialchars($options['queryport'], ENT_QUOTES);
  55.                 $virtualserverport = htmlspecialchars($options['virtualserverport'], ENT_QUOTES);
  56.                 $name = htmlspecialchars($options['name'], ENT_QUOTES);
  57.                 $displaynamesonly=$options['displaynamesonly'];
  58.                 if($displaynamesonly=="true"){
  59.                 $selected="selected";
  60.                 }
  61.                 echo '<p style="text-align:right;"><label for="ts3_wp_viewer-name">Titel <input style="width: 200px;" id="ts3_wp_viewer-name" name="ts3_wp_viewer-name" type="text" value="'.$name.'" /></label></p>';
  62.                 echo '<p style="text-align:right;"><label for="ts3_wp_viewer-serverip">Server IP or DNS<input style="width: 200px;" id="ts3_wp_viewer-serverip" name="ts3_wp_viewer-serverip" type="text" value="'.$serverip.'" /></label></p>';
  63.                 echo '<p style="text-align:right;"><label for="ts3_wp_viewer-queryport">Queryport<input style="width: 200px;" id="ts3_wp_viewer-queryport" name="ts3_wp_viewer-queryport" type="text" value="'.$queryport.'" /></label></p>';
  64.                 echo '<p style="text-align:right;"><label for="ts3_wp_viewer-virtualserverport">Virtual Serverport<input style="width: 200px;" id="ts3_wp_viewer-virtualserverport" name="ts3_wp_viewer-virtualserverport" type="text" value="'.$virtualserverport.'" /></label></p>';
  65.                 echo '<p style="text-align:right;"><label for="ts3_wp_viewer-displaynamesonly">Display Option<select name="ts3_wp_viewer-displaynamesonly" size="1"><option value="false">Show Channellist</option><option '.$selected.' value="true">Show Names Only</option></select></label></p>';
  66.                 echo '<p style="text-align:right;"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9328389">Donate for this Plugin</a> </p>';
  67.                 echo '<p style="text-align:right;"><a href="http://www.michaelplas.de">Visit the Author</a> </p>';     
  68.                 echo '<input type="hidden" id="ts3_wp_viewer-submit" name="ts3_wp_viewer-submit" value="1" />';
  69.         }
  70.  
  71.     function view($is_widget, $args=array()) {
  72.         if($is_widget) extract($args);
  73.  
  74.         // get widget options
  75.         $options = get_option('ts3_wp_viewer');
  76.         $serverip = $options['serverip'];
  77.                 $queryport = $options['queryport'];
  78.         $virtualserverport = $options['virtualserverport'];
  79.                 $displaynamesonly=$options['displaynamesonly'];
  80.                 $name = $options['name'];
  81.                 $path =  plugins_url( 'teamspeak-3-viewer-plugin-for-wordpress-widget/images/viewer/' );
  82.                
  83.                 // Load the Lib
  84.                
  85.                 require_once("libraries/TeamSpeak3/TeamSpeak3.php");
  86.    
  87.                
  88.  
  89.  
  90. try
  91. {
  92.   /* connect to server and get TeamSpeak3_Node_Server object by URI */
  93.   if($queryport == ""){
  94.   $ts3_VirtualServer = TeamSpeak3::factory("serverquery://" . $serverip."/?server_port=". $virtualserverport."#no_query_clients");
  95. }else{
  96.  $ts3_VirtualServer = TeamSpeak3::factory("serverquery://" . $serverip.":" . $queryport."/?server_port=". $virtualserverport."#no_query_clients");
  97. }
  98.   if($displaynamesonly=="true"){
  99.    $clients = $ts3_VirtualServer->clientList();  
  100.   foreach ($clients as $clientObject) {
  101.             $clientInfo = $clientObject->getInfo();
  102.            
  103.                 $mystatus .= $clientInfo['client_nickname'] . "\<br>";
  104.            
  105.         }  
  106.   }else{
  107.   /* display virtual server viewer using HTML interface */
  108.   $mystatus .= $ts3_VirtualServer->getViewer(new TeamSpeak3_Viewer_Html($path));
  109.   }
  110.   /* display runtime from default profiler */
  111.  // echo "<br />Generated in " . TeamSpeak3_Helper_Profiler::get()->getRuntime() . " seconds";
  112.  
  113.  
  114.  
  115.  
  116.  
  117. }
  118. catch(Exception $e)
  119. {
  120.   $mystatus = "Error (ID " . $e->getCode() . ") <b>" . $e->getMessage() . "</b>";
  121. }
  122.  
  123.  
  124.         // the widget's form
  125.         $out[]  ='<div id="ts3_div">';
  126.              
  127.                 $out[] = $before_widget . $before_title . $name . $after_title;
  128.                
  129.                 $out[] = $mystatus;
  130.                 $out[]  ='</div>';
  131.         $out[] = $after_widget;
  132.         return join($out, "\n");
  133.     }
  134.  
  135.     function shortcode($atts, $content=null) {
  136.         return ts3_wp_viewer::view(false);
  137.     }
  138.  
  139.     function widget($atts) {
  140.         echo ts3_wp_viewer::view(true, $atts);
  141.     }
  142. }
  143.  
  144. add_action('widgets_init', array('ts3_wp_viewer', 'init'));
  145.  
  146. ?>
clone this paste RAW Paste Data