ОсновноеRadiotalkПользовательское
Общие вопросы по интернет радио вещанию
7   •   Посмотреть все темы

Скрипт вывода статистики на wordpress

 

17
Spirg @Spirg
Всем привет, в общем сразу к сути. Есть скрипт на Wordpress выводящий стату айскаста, довольно таки хорошо справляется, 2 маунтпоинта как мне и нужно, в общем вопрос, как сделать в этом скрипте что бы трек кол-во слушателей само обновлялось. Я читал уже много мануал и пытался что то сам сделать, но дело в том, куда бы я не ставил любую строку, говорит что скрипт не работает, ошибка в парcинге... Помогите плиз вот сам скрипт:
  1. <?php
  2. /**
  3. * Plugin Name: Icecast Now Playing
  4. * Plugin URI: **********
  5. * Description: A widget to display Icecast server statistics.
  6. * Version: 1.6.0
  7. * Author: Wlliam J. Galway
  8. * Author URI: **********
  9. *
  10. * Icecast Now Playing a widget to display Icecast server connection stats in a Wordpress blog.
  11. * Copyright (C) <2010> <William J. Galway>
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * Add function to widgets_init that'll load our widget.
  27. */
  28. error_reporting(-1);
  29. add_action( 'widgets_init', 'icecast_status_load_widgets' );
  30. /**
  31. * Register our widget.
  32. * 'Icecast_Status_Widget' is the widget class used below.
  33. */
  34. function icecast_status_load_widgets() {
  35. register_widget( 'Icecast_Status_Widget' );
  36. }
  37. /**
  38. * Icecast Status Widget class.
  39. */
  40. error_reporting(1);
  41. class Icecast_Status_Widget extends WP_Widget {
  42. /**
  43. * Widget setup.
  44. */
  45. function Icecast_Status_Widget() {
  46. /* Widget settings. */
  47. $widget_ops = array( 'classname' => 'icecaststatus', 'description' => __('Display Icecast statistics.', 'icecaststatus') );
  48. /* Widget control settings. */
  49. $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'icecast-widget' );
  50. /* Create the widget. */
  51. $this->WP_Widget( 'icecast-widget', __('Icecast Now Playing', 'icecaststatus'), $widget_ops, $control_ops );
  52. }
  53. /**
  54. * How to display the widget on the screen.
  55. */
  56. function widget( $args, $instance ) {
  57. extract( $args );
  58. /* Our variables from the widget settings. */
  59. $title = apply_filters('widget_title', $instance['title'] );
  60. $server = $instance['servername'];
  61. $username = $instance['username'];
  62. $password = $instance['password'];
  63. $mount1= $instance['mount1'];
  64. $mount2= $instance['mount2'];
  65. $description1= $instance['description1'];
  66. $description2= $instance['description2'];
  67. /* Before widget (defined by themes). */
  68. echo $before_widget;
  69. /* Display the widget title if one was input (before and after defined by themes). */
  70. if ( $title )
  71. echo $before_title . $title . $after_title;
  72. // Open Icecast stats url
  73. $fp = fopen("http://$username:$password@$server/admin/stats","r");
  74. if (!$fp) {
  75. echo "Error reading Icecast data from $server\n";
  76. }
  77. else {
  78. stream_set_timeout($fp, 2);
  79. $stats = "";
  80. while(!feof($fp))
  81. {
  82. $stats .= fread($fp, 8192);
  83. }
  84. fclose($fp);
  85. // Now parse the XML output for our mountpoint
  86. $xml_parser = xml_parser_create();
  87. xml_parse_into_struct($xml_parser, $stats, $vals, $index);
  88. xml_parser_free($xml_parser);
  89. $params = array();
  90. $level = array();
  91. foreach ($vals as $xml_elem) {
  92. if ($xml_elem['type'] == 'open') {
  93. if (array_key_exists('attributes',$xml_elem)) {
  94. list($level[$xml_elem['level']],$extra) =
  95. array_values($xml_elem['attributes']);
  96. } else {
  97. $level[$xml_elem['level']] = $xml_elem['tag'];
  98. }
  99. }
  100. if ($xml_elem['type'] == 'complete') {
  101. $start_level = 1;
  102. $php_stmt = '$params';
  103. while($start_level < $xml_elem['level']) {
  104. $php_stmt .= '[$level['.$start_level.']]';
  105. $start_level++;
  106. }
  107. $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
  108. eval($php_stmt);
  109. }
  110. $info = array(
  111. 'track1' => $params['ICESTATS'][$mount1]['TITLE'],
  112. 'track2' => $params['ICESTATS'][$mount2]['TITLE'],
  113. 'listen1' => $params['ICESTATS'][$mount1]['LISTENURL'],
  114. 'listen2' => $params['ICESTATS'][$mount2]['LISTENURL'],
  115. 'users1' => $params['ICESTATS'][$mount1]['LISTENERS'],
  116. 'users2' => $params['ICESTATS'][$mount2]['LISTENERS'],
  117. 'server1' => $params['ICESTATS'][$mount1]['SERVER_URL'],
  118. 'server2' => $params['ICESTATS'][$mount2]['SERVER_URL']);
  119. }
  120. /**
  121. * Begin display Icecast connection statistics in widget
  122. * Change the widget display layout here
  123. */
  124. if ($info['track1']){
  125. if ($description1){
  126. echo "<strong>$description1</strong><br/>";
  127. }
  128. echo "<a href=\"$info[listen1].m3u\">$info[track1]</a>\n";
  129. echo "<br/>";
  130. echo "Слушает:<a href=\"$info[server1]\">$info[users1]</a>";
  131. echo "<br />";
  132. }
  133. if ($info['track2']){
  134. if ($description2){
  135. echo "<strong>$description2</strong><br/>";
  136. }
  137. echo "<a href=\"$info[listen2].m3u\">$info[track2]</a>\n";
  138. echo "<br />";
  139. echo "Слушает:<a href=\"$info[server2]\">$info[users2]</a>";
  140. echo "<br />";
  141. }
  142. }
  143. // End of display Icecast connection statistics in widget.
  144. /* After widget (defined by themes). */
  145. echo $after_widget;
  146. }
  147. /**
  148. * Update the widget settings.
  149. */
  150. function update( $new_instance, $old_instance ) {
  151. $instance = $old_instance;
  152. /* Strip tags for title and name to remove HTML (important for text inputs). */
  153. /* Necessary for form data persistance. */
  154. $instance['title'] = strip_tags( $new_instance['title'] );
  155. $instance['servername'] = strip_tags( $new_instance['servername'] );
  156. $instance['username'] = strip_tags( $new_instance['username'] );
  157. $instance['password'] = strip_tags( $new_instance['password'] );
  158. $instance['mount1'] = strip_tags( $new_instance['mount1'] );
  159. $instance['mount2'] = strip_tags( $new_instance['mount2'] );
  160. $instance['description1'] = strip_tags( $new_instance['description1'] );
  161. $instance['description2'] = strip_tags( $new_instance['description2'] );
  162. return $instance;
  163. }
  164. /**
  165. * Displays the widget settings controls on the widget panel.
  166. * Make use of the get_field_id() and get_field_name() function
  167. * when creating your form elements. This handles the confusing stuff.
  168. */
  169. function form( $instance ) {
  170. /* Set up some default widget settings. */
  171. $defaults = array(
  172. 'title' => __('Icecast', 'icecaststatus'),
  173. 'servername' => __('127.0.0.1:8000', 'icecaststatus'),
  174. 'username' => __('admin', 'icecaststatus'),
  175. 'password' => __('password', 'icecaststatus'),
  176. 'mount1' => __('/ices', 'icecaststatus'),
  177. 'mount2' => __('/mpd', 'icecaststatus'),
  178. 'description1' => __('Now Playing', 'icecaststatus'),
  179. 'description2' => __('Now Playing', 'icecaststatus'));
  180. $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  181. <!-- Widget Title: Text Input -->
  182. <p>
  183. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'hybrid'); ?></label>
  184. <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
  185. </p>
  186. <!-- Server Name: Text Input -->
  187. <p>
  188. <label for="<?php echo $this->get_field_id( 'servername' ); ?>"><?php _e('server name:port', 'icecaststatus'); ?></label>
  189. <input id="<?php echo $this->get_field_id( 'servername' ); ?>" name="<?php echo $this->get_field_name( 'servername' ); ?>" value="<?php echo $instance['servername']; ?>" style="width:100%;" />
  190. </p>
  191. <!-- User Name: Text Input -->
  192. <p>
  193. <label for="<?php echo $this->get_field_id( 'username' ); ?>"><?php _e('username:', 'icecaststatus'); ?></label>
  194. <input id="<?php echo $this->get_field_id( 'username' ); ?>" name="<?php echo $this->get_field_name( 'username' ); ?>" value="<?php echo $instance['username']; ?>" style="width:100%;" />
  195. </p>
  196. <!-- Password: Text Input -->
  197. <p>
  198. <label for="<?php echo $this->get_field_id( 'password' ); ?>"><?php _e('password:', 'icecaststatus'); ?></label>
  199. <input id="<?php echo $this->get_field_id( 'password' ); ?>" name="<?php echo $this->get_field_name( 'password' ); ?>" value="<?php echo $instance['password']; ?>" style="width:100%;" />
  200. </p>
  201. <!-- Mount: Text Input -->
  202. <p>
  203. <label for="<?php echo $this->get_field_id( 'mount1' ); ?>"><?php _e('mount 1:', 'icecaststatus'); ?></label>
  204. <input id="<?php echo $this->get_field_id( 'mount1' ); ?>" name="<?php echo $this->get_field_name( 'mount1' ); ?>" value="<?php echo $instance['mount1']; ?>" style="width:100%;" />
  205. </p>
  206. <!-- Stream Description: Text Input -->
  207. <p>
  208. <label for="<?php echo $this->get_field_id( 'description1' ); ?>"><?php _e('stream description:', 'icecaststatus'); ?></label>
  209. <input id="<?php echo $this->get_field_id( 'description1' ); ?>" name="<?php echo $this->get_field_name( 'description1' ); ?>" value="<?php echo $instance['description1']; ?>" style="width:100%;" />
  210. </p>
  211. <!-- Mount: Text Input -->
  212. <p>
  213. <label for="<?php echo $this->get_field_id( 'mount2' ); ?>"><?php _e('mount 2:', 'icecaststatus'); ?></label>
  214. <input id="<?php echo $this->get_field_id( 'mount2' ); ?>" name="<?php echo $this->get_field_name( 'mount2' ); ?>" value="<?php echo $instance['mount2']; ?>" style="width:100%;" />
  215. </p>
  216. <!-- Stream Description: Text Input -->
  217. <p>
  218. <label for="<?php echo $this->get_field_id( 'description2' ); ?>"><?php _e('stream description:', 'icecaststatus'); ?></label>
  219. <input id="<?php echo $this->get_field_id( 'description2' ); ?>" name="<?php echo $this->get_field_name( 'description2' ); ?>" value="<?php echo $instance['description2']; ?>" style="width:100%;" />
  220. </p>
  221. <?php
  222. }
  223. }
  224. ?>

Отредактировано Spirg - 30.08.2011
0
1572
KyPIIaToB @KyPIIaToB
Дружище, ты написал не туда явно, тебе на форум посвященный wordpress. Тут готовые скрипты для каких либо CMS не обсуждаются.

0
17
Spirg @Spirg
а жаль, ну я написал на сайт вп, но этот сайт я знаю уже очень давно решил что возможно помогут, мне просто за 2 дня нужно эту проблему решить

0





Согласие на обработку данных на нашем сайте

Продолжая просматривать страницу, вы соглашаетесь с использованием файлов «Cookie» и с Политикой конфиденциальности «Privacy».
Наверху или внизу страницы вы можете изменить валюту и язык по умолчанию. Английская версия сайта ещё находится в доработке и доступна не полностью.