Exemplo n.º 1
0
 protected function injectCommand(Chain $chain, $msg, $isPrivate = true)
 {
     $request = $chain->getRequest();
     $request['msg'] = $msg;
     if ($isPrivate) {
         $request['to'] = $chain->getUser()->getId();
     } else {
         $request['self'] = 1;
     }
     $chain->setRequest($request);
 }
Exemplo n.º 2
0
 /**
  * C-o-R pattern
  * @param Chain $chain input stream
  * @return false|null|true
  */
 public function handleRequest(Chain $chain)
 {
     $request = $chain->getRequest();
     $text = strip_tags(htmlentities(trim($request['msg'])));
     $msgMaxLength = DI::get()->getConfig()->msgMaxLength;
     if (mb_strlen($text) > $msgMaxLength) {
         $text = mb_strcut($text, 0, $msgMaxLength) . self::CUT;
     }
     $request['msg'] = $text;
     $chain->setRequest($request);
 }
Exemplo n.º 3
0
 /**
  * C-o-R pattern
  * @param Chain $chain input stream
  * @return false|null|true
  */
 public function handleRequest(Chain $chain)
 {
     $config = DI::get()->getConfig()->domain;
     /** @var Client $client */
     $client = DI::get()->container()->get('httpClient');
     $regexp = '~\\b' . $config->protocol . addcslashes($config->web, '.') . '/audio\\.php\\?(?:token=.*)?track_id=(.*)\\b~u';
     if (preg_match($regexp, $chain->getRequest()['msg'], $matches)) {
         $url = $config->protocol . $config->web . '/audio_player.php?track_id=' . $matches[1];
         DI::get()->getLogger()->info('Sending http request to ' . $url);
         $httpRequest = $client->request('GET', $url, ['User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12']);
         $httpRequest->on('response', $this->onResponse($chain));
         $httpRequest->on('error', function (\Exception $e) {
             DI::get()->getLogger()->err($e->getMessage() . $e->getPrevious()->getMessage());
         });
         $httpRequest->end();
         $request = $chain->getRequest();
         $lang = $chain->getUser()->getLang();
         $replacement = '<div class="img-thumbnail">' . '<a class="music" href="#" title="' . $lang->getPhrase('Music.PlayTip') . '" id="music-$1" data-src="">' . '<span class="glyphicon glyphicon-play-circle"></span> <span class="audio-title">...</span></a></div>';
         $request['msg'] = $text = preg_replace($regexp, $replacement, $request['msg']);
         $chain->setRequest($request);
         $props = $chain->getUser()->getProperties();
         $props->setMusicCount($props->getMusicCount() + 1);
     }
 }