Author: Jan Schneider (jan@horde.org)
Inheritance: extends Horde_Translation_Autodetect
Example #1
0
 /**
  * Receives a single CRLF terminated server response string
  *
  * @return mixed 'NO', 'BAD', 'OK', raw response.
  * @throws Horde_Imsp_Exception
  */
 public function receive()
 {
     if (!$this->_stream) {
         throw new Horde_Imsp_Exception('No IMSP connection in place.');
     }
     $result = fgets($this->_stream, 512);
     if (!$result) {
         $this->_logger->err('Did not receive the expected response from the server.');
         throw new Horde_Imsp_Exception('Did not receive the expected response from the server.');
     }
     $meta = stream_get_meta_data($this->_stream);
     if ($meta['timed_out']) {
         $this->_logger->err('Connection timed out.');
         throw new Horde_Imsp_Exception(Horde_Imsp_Translation::t('Connection timed out!'));
     }
     $server_response = trim($result);
     $this->_logger->debug('S: ' . $server_response);
     /* Parse out the response:
      * First make sure that this is not for a previous command.
      * If it is, it means we did not read all the server responses from
      * the last command...read them now, but throw an error. */
     while (preg_match("/^" . $this->_lastCommandTag . "/", $server_response)) {
         $server_response = trim(fgets($this->_stream, 512));
         throw new Horde_Imsp_Exception('Did not receive the expected response from the server: ' . $server_response);
     }
     $currentTag = $this->_tag;
     if (preg_match("/^" . $currentTag . " NO/", $server_response)) {
         $this->lastRawError = $server_response;
         return 'NO';
     }
     if (preg_match("/^" . $currentTag . " BAD/", $server_response)) {
         $this->_logger->err('The IMSP server did not understand your request.');
         $this->lastRawError = $server_response;
         return 'BAD';
     }
     if (preg_match("/^" . $currentTag . " OK/", $server_response)) {
         return 'OK';
     }
     /* If it was not a 'NO', 'BAD' or 'OK' response,
      * then it's up to the calling function to decide
      * what to do with it. */
     return $server_response;
 }
Example #2
0
 /**
  * Returns the plural translation of a message.
  *
  * @param string $singular  The singular version to translate.
  * @param string $plural    The plural version to translate.
  * @param integer $number   The number that determines singular vs. plural.
  *
  * @return string  The string translation, or the original string if no
  *                 translation exists.
  */
 public static function ngettext($singular, $plural, $number)
 {
     self::$_domain = 'Horde_Imsp';
     self::$_directory = '@data_dir@' == '@' . 'data_dir' . '@' ? __DIR__ . '/../../../locale' : '@data_dir@/Horde_Imsp/locale';
     return parent::ngettext($singular, $plural, $number);
 }