/** * Find out where this file is going and let the user know where * @param string $item The relative location of the music file in the unsorted directory * @param array $info The music file's tag data * @return string */ function sorting_message($item, $info) { $duplicate = TRUE; //Both artist and album have data if ($info['artist'] != 'Unknown Artist' && $info['album'] != 'Unknown Album') { //Send a message that we found data $this->Output->send(' %2- ID3 Tags Found%n'); $this->Output->send(' %2- Sorted by Artist and Album%n'); } //Artist has data, but album does not if ($info['artist'] != 'Unknown Artist' && $info['album'] == 'Unknown Album') { //Send a message that we found data $this->Output->send(' %2- ID3 Tags Found%n'); $this->Output->send(' %2- Sorted by Artist%n'); } //Artist has no data, but album does if ($info['artist'] == 'Unknown Artist' && $info['album'] != 'Unknown Album') { //Send a message that we found data $this->Output->send(' %2- ID3 Tags Found%n'); $this->Output->send(' %2- Sorted by Album%n'); } //Artist and album have no data if ($info['artist'] == 'Unknown Artist' && $info['album'] == 'Unknown Album') { $this->Output->send(' %1- Unknown Song Data%n'); $duplicate = FALSE; } //Work out the destination $file = substr($item, strrpos($item, '/')); //Check if this a duplicate if ($this->duplicate_check($info) && $duplicate == TRUE) { return $this->Config->read('sorted') . '_duplicateMusic/' . ucwords($info['artist']) . '/' . ucwords($info['album']) . '/' . $file; } else { return $this->Config->read('sorted') . ucwords($info['artist']) . '/' . ucwords($info['album']) . '/' . $file; } }
/** * Convert all the possible elements from which you can import content * to a resource. * * @param string|resource $res * @return TempFileObject */ protected function convertToResource($res) { $file = new TempFileObject($this->options['tmp'] . '/' . StringUtils::randString(50)); switch (true) { case $res instanceof FileObject: $file->write($res->read()); unset($res); break; case is_resource($res): $file->write(stream_get_contents($res)); break; case file_exists($res): case filter_var($res, FILTER_VALIDATE_URL): $file->write(stream_get_contents(fopen($res, 'r'))); break; default: $file->write($res); } $file->rewind(); return $file; }
/** * Parses the Link element. * * @return array the parsed JRD element */ private function parseLink() { $link = array(); while ($this->reader->moveToNextAttribute()) { if ($this->reader->namespaceURI == '') { $link[$this->reader->localName] = $this->reader->value; } } $this->reader->moveToElement(); if ($this->reader->isEmptyElement) { return $link; } while ($this->reader->read()) { if ($this->reader->nodeType == XMLReader::END_ELEMENT && $this->reader->namespaceURI == self::XRD_NS && $this->reader->localName == 'Link') { break; } if ($this->reader->nodeType == XMLReader::ELEMENT && $this->reader->namespaceURI == self::XRD_NS) { switch ($this->reader->localName) { case 'Property': if (!isset($link['properties'])) { $link['properties'] = array(); } $this->parseProperty($link['properties']); break; case 'Title': if ($this->reader->xmlLang) { $lang = $this->reader->xmlLang; } else { $lang = 'und'; } if (!isset($link['titles'])) { $link['titles'] = array(); } $link['titles'][$lang] = $this->reader->readString(); break; } } } return $link; }
/** * Protected method for sending data to SMTP connection * * @param string $data data to be sent to SMTP server * @param mixed $checkCode code to check for in server response, false to skip * @return bool Success * @access protected */ function _smtpSend($data, $checkCode = '250') { if (!is_null($data)) { $this->__smtpConnection->write($data . "\r\n"); } while ($checkCode !== false) { $response = ''; $startTime = time(); while (substr($response, -2) !== "\r\n" && time() - $startTime < $this->smtpOptions['timeout']) { $response .= $this->__smtpConnection->read(); } if (substr($response, -2) !== "\r\n") { $this->smtpError = 'timeout'; return false; } $response = end(explode("\r\n", rtrim($response, "\r\n"))); if (preg_match('/^(' . $checkCode . ')(.)/', $response, $code)) { if ($code[2] === '-') { continue; } return $code[1]; } $this->smtpError = $response; return false; } return true; }
/** * Private method for sending data to SMTP connection * * @param string $data data to be sent to SMTP server * @param mixed $checkCode code to check for in server response, false to skip * @return bool Success * @access private */ function __smtpSend($data, $checkCode = '250') { if (!is_null($data)) { $this->__smtpConnection->write($data . "\r\n"); } if ($checkCode !== false) { $response = $this->__smtpConnection->read(); if (!preg_match('/^' . $checkCode . '/', $response)) { $this->smtpError = $response; return false; } } return true; }
/** * Receives a number of bytes from the server. * * @param integer $length Number of bytes to read. * * @return string The server response. */ function _recvBytes($length) { $response = ''; $response_length = 0; while ($response_length < $length) { $response .= $this->_sock->read($length - $response_length); $response_length = $this->_getLineLength($response); } $this->_debug('S: ' . rtrim($response)); return $response; }
/** * Reads data from this connection * * @param integer $length the number of bytes to read. * * @return boolean true if one or more messages were receved from this * connection and false if a partial message or another * frame type was received. */ public function read($length) { $buffer = $this->socket->read($length); if ($this->state < self::STATE_OPEN) { $this->handshakeBuffer .= $buffer; $headerPos = mb_strpos($this->handshakeBuffer, "\r\n\r\n", 0, '8bit'); if ($headerPos !== false) { $data = mb_substr($this->handshakeBuffer, 0, $headerPos, '8bit'); try { $this->handleHandshake($data); } catch (Net_Notifier_WebSocket_ProtocolException $e) { $this->state = self::STATE_CLOSED; $this->shutdown(); } $length = mb_strlen($this->handshakeBuffer, '8bit'); $buffer = mb_substr($this->handshakeBuffer, $headerPos + 4, $length - $headerPos - 5, '8bit'); } } if ($this->state > self::STATE_CONNECTING) { $frames = $this->parser->parse($buffer); foreach ($frames as $frame) { $this->handleFrame($frame); } } return count($this->textMessages) > 0 || count($this->binaryMessages) > 0; }
/** * Send a command and retrieves a response from the server. * * @param string $cmd The command to send. * @param boolean $auth Whether this is an authentication command. * * @return string|PEAR_Error Reponse string if an OK response, PEAR_Error * if a NO response. */ function _doCmd($cmd = '', $auth = false) { $referralCount = 0; while ($referralCount < $this->_maxReferralCount) { if (strlen($cmd)) { if (PEAR::isError($error = $this->_sendCmd($cmd))) { return $error; } } $response = ''; while (true) { if (PEAR::isError($line = $this->_recvLn())) { return $line; } $uc_line = $this->_toUpper($line); if ('OK' == substr($uc_line, 0, 2)) { $response .= $line; return rtrim($response); } if ('NO' == substr($uc_line, 0, 2)) { // Check for string literal error message. if (preg_match('/^no {([0-9]+)\\+?}/i', $line, $matches)) { $line .= str_replace("\r\n", ' ', $this->_sock->read($matches[1] + 2)); $this->_debug("S: {$line}"); } return PEAR::raiseError(trim($response . substr($line, 2)), 3); } if ('BYE' == substr($uc_line, 0, 3)) { if (PEAR::isError($error = $this->disconnect(false))) { return PEAR::raiseError('Cannot handle BYE, the error was: ' . $error->getMessage(), 4); } // Check for referral, then follow it. Otherwise, carp an // error. if (preg_match('/^bye \\(referral "(sieve:\\/\\/)?([^"]+)/i', $line, $matches)) { // Replace the old host with the referral host // preserving any protocol prefix. $this->_data['host'] = preg_replace('/\\w+(?!(\\w|\\:\\/\\/)).*/', $matches[2], $this->_data['host']); if (PEAR::isError($error = $this->_handleConnectAndLogin())) { return PEAR::raiseError('Cannot follow referral to ' . $this->_data['host'] . ', the error was: ' . $error->getMessage(), 5); } break; } return PEAR::raiseError(trim($response . $line), 6); } if (preg_match('/^{([0-9]+)\\+?}/i', $line, $matches)) { // Matches String Responses. $str_size = $matches[1] + 2; $line = ''; $line_length = 0; while ($line_length < $str_size) { $line .= $this->_sock->read($str_size - $line_length); $line_length = $this->_getLineLength($line); } $this->_debug("S: {$line}"); if (!$auth) { // Receive the pending OK only if we aren't // authenticating since string responses during // authentication don't need an OK. $this->_recvLn(); } return $line; } if ($auth) { // String responses during authentication don't need an // OK. $response .= $line; return rtrim($response); } $response .= $line . "\r\n"; $referralCount++; } } return PEAR::raiseError('Max referral count (' . $referralCount . ') reached. Cyrus murder loop error?', 7); }
/** * Private method for sending data to SMTP connection * * @param string $data data to be sent to SMTP server * @param mixed $checkCode code to check for in server response, false to skip * @return bool Success * @access private */ function __smtpSend($data, $checkCode = '250') { if (!is_null($data)) { $this->__smtpConnection->write($data . "\r\n"); } if ($checkCode !== false) { $response = ''; while ($str = $this->__smtpConnection->read()) { $response .= $str; if ($str[3] == ' ') { break; } } if (stristr($response, $checkCode) === false) { $this->smtpError = $response; return false; } } return true; }