Esempio n. 1
0
 /**
  * Patch the 'parse_request' action in WordPress to handle calls to this web service.
  */
 function __construct()
 {
     add_action("parse_request", function ($wp) {
         if ($_GET[PLUGIN_SLUG . '_player'] == '1') {
             $opt = Options::get_instance();
             $site_root = esc_url(home_url('/'));
             include PLUGIN_DIR . 'views/player.php';
             exit;
         }
     });
 }
 public function load()
 {
     require_once HM_LIMIT_LOGIN_DIR . 'inc/class-options.php';
     require_once HM_LIMIT_LOGIN_DIR . 'inc/class-errors.php';
     require_once HM_LIMIT_LOGIN_DIR . 'inc/class-cookies.php';
     require_once HM_LIMIT_LOGIN_DIR . 'inc/class-validation.php';
     require_once HM_LIMIT_LOGIN_DIR . 'inc/class-notifications.php';
     if (HM_LIMIT_LOGIN_VERSION !== get_option('hm_limit_login_version')) {
         $this->set_default_variables();
     }
     load_plugin_textdomain('limit-login-attempts', false, dirname(plugin_basename(__FILE__)));
     Options::get_instance();
     Errors::get_instance();
     Cookies::get_instance();
     Validation::get_instance();
     Notifications::get_instance();
 }
Esempio n. 3
0
 /**
  * (Web service method) Get current top 10 by vote sum
  * @param  mixed[] $args an empty array
  * @return mixed[] status; error_message; output (what to announce in IRC chat room)
  */
 private function web_stats($args)
 {
     // This function is messy. Maybe clean it up later, but it works now.
     $opt = Options::get_instance();
     $lengths = array();
     preg_replace_callback('/\\$\\{(\\w+),(\\d+)\\}/', function ($matches) {
         global $lengths;
         $lengths[$matches[1]] = $matches[2];
     }, $opt->txt_stats);
     // example: ${begin_repeat,10}#${num} ${title,21}${end_repeat}
     $response = preg_replace_callback('/\\$\\{begin_repeat,(\\d+)\\}(.*?)\\$\\{end_repeat\\}/i', function ($matches) {
         global $lengths;
         $limit = $matches[1];
         $template = $matches[2];
         $n = 1;
         $out = array();
         $results = Track::irc_stats($limit);
         foreach ($results as $result) {
             $v = get_object_vars($result);
             $stream_title = substr($result->stream_title, 0, $lengths['stream_title']);
             $title = substr($result->title, 0, $lengths['title']);
             $artist = substr($result->artist, 0, $lengths['artist']);
             $txt = $template;
             $txt = str_replace('${stream_title,' . $lengths['stream_title'] . '}', $stream_title, $txt);
             $txt = str_replace('${title,' . $lengths['title'] . '}', $title, $txt);
             $txt = str_replace('${artist,' . $lengths['artist'] . '}', $artist, $txt);
             $txt = str_ireplace('${num}', $n, $txt);
             $out[] = $txt;
             $n++;
         }
         return implode(' ', $out);
     }, $opt->txt_stats);
     return array('status' => 'ok', 'error_message' => '', 'output' => $response, 'private' => $opt->txt_stats_switch);
 }