<div class="wrap"> <div class="icon32" id="icon-options-general"><br></div> <h2><?php _e('Last track settings', LastTrackPlugin::domain()); ?> </h2> <p></p> <form action="options.php" method="post"> <?php settings_fields(LastTrackPlugin::PREFIX); ?> <?php do_settings_sections(LastTrackPlugin::get_name_with_prefix('options')); ?> <?php submit_button(); ?> </form> </div> <?php wp_enqueue_script("jquery"); wp_enqueue_script(LastTrackPlugin::get_name_with_prefix('options_js'), plugins_url('js/options.js', __FILE__), array('jquery'));
public function get_last_songs($count = 0) { $songs = array(); $curl = curl_init($this->url); if (!$curl) { $songs['errors'][] = __('Cannot init curl.', LastTrackPlugin::domain()); return $songs; } $options = array(CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT => $this->connect_timeout, CURLOPT_TIMEOUT => $this->timeout); if ($this->is_require_auth) { $options[CURLOPT_HTTPAUTH] = CURLAUTH_ANY; $options[CURLOPT_USERPWD] = $this->login . ':' . $this->password; } $wrong_key = $this->set_options($curl, $options); if (isset($wrong_key)) { $songs['errors'][] = printf(__("Cannot set option '%s': %s", LastTrackPlugin::domain()), curl_error($curl)); curl_close($curl); return $songs; } $xml = curl_exec($curl); if (!isset($xml)) { $songs['errors'][] = printf(__("Cannot exec curl: %s", LastTrackPlugin::domain()), curl_error($curl)); curl_close($curl); return $songs; } $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); switch ($status) { case 401: $songs['errors'][] = __('Unauthorized.', LastTrackPlugin::domain()); curl_close($curl); return $songs; case 200: break; default: $songs['errors'][] = $xml; curl_close($curl); return $songs; } $data = new SimpleXMLElement($xml); $counter = 0; foreach ($data->SONGHISTORY->SONG as $song) { $title = strval($song->TITLE); $is_exclude = false; foreach ($this->exclude as $test) { if (strpos(mb_strtoupper($title), mb_strtoupper($test)) !== false) { $is_exclude = true; break; } } if ($is_exclude) { continue; } if ($counter == 0) { $songs['current'] = $this->parse_title($title); ++$counter; continue; } $songs['lasts'][] = $this->parse_title($title); if ($count > 0 && $count == $counter) { break; } ++$counter; } return $songs; }
public static function ajax() { $ajax = array('title' => LastTrackPlugin::get_option('title'), 'content' => LastTrackWidget::get_template()); exit(json_encode($ajax)); }
<?php /* Plugin Name: Last Track Shoutcast Plugin URI: https://github.com/rodnover55/last_tracks_shoutcast Description: Show last track from shoutcast Version: 1.0.0 Author: rodnover Author URI: License: GPL */ include_once 'last_track_plugin.php'; LastTrackPlugin::activate();
public static function get_option($option_name) { return get_option(LastTrackPlugin::get_name_with_prefix($option_name), LastTrackPlugin::$options[LastTrackPlugin::get_name_with_prefix($option_name)]); }
<div> <?php include_once "text_with_link.php"; if (isset($songs['errors'])) { switch ($information) { case LastTrackPlugin::INFORMATION_MESSAGE: echo $information_message; break; case LastTrackPlugin::INFORMATION_FULL: foreach ($songs['errors'] as $error) { ?> <?php _e('Errors:', LastTrackPlugin::domain()); echo $error; ?> <br/><?php } break; } return; } else { ?> <div> <div class="current_song_title"><?php echo $current_song; ?> </div> <?php text_with_link($href, "<div class='current_song_artist'>{$songs['current']['artist']}</div>" . "<div class='current_song_track'>{$songs['current']['track']}</div>"); ?> <br/>
public static function admin_menu() { add_options_page(__('Last track shoutcast settings', LastTrackPlugin::domain()), __('Last tracks shoutcast', LastTrackPlugin::domain()), 'manage_options', LastTrackPlugin::PREFIX, array(__CLASS__, 'get_options')); }