Create plain text response and return it as a string
@return string
519220
public function generateResponse()
    {
        $exception = $this->getException();
        return sprintf(
            "%s: %s in file %s on line %d%s\n",
            get_class($exception),
            $exception->getMessage(),
            $exception->getFile(),
            $exception->getLine(),
            $this->getTraceOutput()
        );
    }
1145875
static function getOutputEncodingHtml()
    {

        $txt = '';
        $tmp1 = '<meta http-equiv="Content-Type" content="text/html; charset=';
        $tmp2 = '" />';
        switch (ReporticoApp::getConfig("output_encoding")) {
            case "None":$txt = '';
                break;
            case "UTF8":$txt = $tmp1 . "utf-8" . $tmp2;'<meta charset="utf-8">';
                break;
            default:$txt = $tmp1 . ReporticoApp::getConfig("output_encoding") . $tmp2;
                break;
        }

        return $txt;
    }
896349
static function httpCharset()
    {
        $realCharset =& $GLOBALS['eZTextCodecHTTPCharsetReal'];
        if ( !isset( $realCharset ) )
        {
            $charset = '';
            if ( isset( $GLOBALS['eZTextCodecHTTPCharset'] ) )
                $charset = $GLOBALS['eZTextCodecHTTPCharset'];
            if ( $charset == '' )
            {
                if ( isset( $GLOBALS['eZTextCodecInternalCharsetReal'] ) )
                    $realCharset = $GLOBALS['eZTextCodecInternalCharsetReal'];
                else
                    $realCharset = eZTextCodec::internalCharset();
            }
            else
            {
                $realCharset = eZCharsetInfo::realCharsetCode( $charset );
            }
        }
        return $realCharset;
    }
1359384
public function respond()
    {
        // Make sure there always is a response
        if (null === $this->result)
        {
            $this->result = new Result;
            $this->result->setResponse(new Error(500, "No output produced"));
        }
        
        // Close and log all script output that hasn't been cleaned yet
        $this->endAllOutputBuffers($this->target_ob_level);

        // Add Content-Type mime header
        $response = $this->result->getResponse();
        $mime = $response->getMimeTypes();
        if (empty($mime))
        {
            $mime = Request::cli() ? "text/plain" : "text/html";
        }
        elseif (is_array($mime))
        {
            $types = $mime;
            $mime = null;
            foreach ($types as $type)
            {
                if ($this->request->accepts($type))
                {
                    $mime = $type;
                    break;
                }
            }
        }

        // If mime is not accepted, return a 406 response
        if (empty($mime) || !$this->request->accepts($mime))
        {
            $mime = 'text/html';
            $this->result->setResponse(new Error(406, "Not Acceptable", 'No acceptable response can be offered'));
        }

        // Execute hooks
        $hook_params = [
            'responder' => $this,
            'request' => $this->request,
            'mime' => $mime,
        ];

        $hook_params = Hook::execute('Wedeto.HTTP.Responder.Respond', $hook_params);

        // Check if mime type was updated
        if (is_string($hook_params['mime']))
            $mime_charset = $hook_params['mime'];

        $mime_charset = $mime;
        $tp = new FileType('', $mime);
        if ($tp->isPlainText())
            $mime_charset .= '; charset=utf-8';

        // Set mime type
        $this->setHeader('Content-Type', $mime_charset);

        // Add headers from response to the final response
        foreach ($this->result->getAllHeaders() as $key => $value)
            $this->setHeader($key, $value);

        // Store the response code
        $this->setResponseCode($response->getStatusCode());

        // All preparational work is done, time to send stuff to the client
        $this->doOutput($mime);
    }
663450
public function getStatusText()
    {
        switch ($this->getStatus()) {
            case self::Status_Success:
                return $this->t('message_response_success');
            case self::Status_Notices:
                return $this->t('message_response_notices');
            case self::Status_Warnings:
                return $this->t('message_response_warnings');
            case self::Status_Errors:
                return $this->t('message_response_errors');
            case self::Status_Exception:
                return $this->t('message_response_exception');
            case null:
                return $this->t('message_response_not_set');
            default:
                return sprintf($this->t('message_response_unknown'), $this->getStatus());
        }
    }
440749
public function toString(): string
    {
        // first line
        $output = $this->buildFirstLine() . self::EOL;

        // add headers
        $output .= $this->headers->toHeaderLines(true);

        // append cookies
        if ($cookie = $this->cookies->toRequestHeader()) {
            $output .= "Cookie: $cookie" . self::EOL;
        }

        $output .= self::EOL;

        return $output . $this->getBody();
    }
59993
protected function getResponseMessage()
    {

        // read the first 4 bytes which include the length of the response
        $lengthEncoded = $this->client->read(4);

        if (strlen($lengthEncoded) < 4) {
            return new Message('', Message::TYPE_RESPONSE_VALUE);
        }

        $lengthInBytes = unpack('V1size', $lengthEncoded)['size'];

        if ($lengthInBytes <= 0) {
            return new Message('', Message::TYPE_RESPONSE_VALUE);
        }

        $responseData = $this->client->read($lengthInBytes);

        // return an empty message if the server did not send any response
        if (null === $responseData) {
            return new Message('', Message::TYPE_RESPONSE_VALUE);
        }

        $responseMessage = new Message();
        $responseMessage->initializeFromRconData($responseData);

        if ($lengthInBytes >= 4000) {
            $this->handleFragmentedResponse($responseMessage);
        }

        return $responseMessage;
    }
671512
public static function applyformatToText() {
    $args = func_get_args();
    $count = func_num_args();

    $text = $args[$count - 1];
    if ($count == 1) { return $text; }

    $mode_texts = array_slice($args, 0, $count - 1);

    return self::buildEscapeCodes($mode_texts).$text.self::buildEscapeCodes('plain');
  }
88222
function toString()
    {
        $uri = '';

        if ($this->getScheme())
            $uri .= $this->getScheme() . ':'. '//';

        $uri .= $this->getAuthority();
        $uri .= parent::toString();

        if ($this->getHost() && (!$this->getQuery()->isEmpty() || $this->getFragment()))
            $uri .= '/';

        $replace = function ($match) { return rawurlencode($match[0]); };
        if (\Poirot\Std\cast($this->getQuery())->toArray()) {
            $regex   = '/(?:[^' .'a-zA-Z0-9_\-\.~' .'!\$&\'\(\)\*\+,;=' .'%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/';
            $uri .= "?" . preg_replace_callback($regex, $replace, $this->getQuery()->toString());
        }

        if ($this->getFragment()) {
            $regex   = '/(?:[^' .'a-zA-Z0-9_\-\.~' .'!\$&\'\(\)\*\+,;=' .'%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/';
            $uri .= "#" . preg_replace_callback($regex, $replace, $this->getFragment());
        }

        return $uri;
    }
769993
private function processResponse()
    {
        $xmlstr = '';
        $record = 0;
        foreach ($this->response as $line) {
            if ($record == 1) {
                $xmlstr .= $line;
            } elseif (substr($line, 0, 1) == '<') {
                $record = 1;
            } elseif (preg_match('/^HTTP\/1.[0-9]{1} ([5-9]{1}[0-9]{2}.*)/', $line, $matches)) {

                throw new ConnectionException($this->host . ': Service not available (' . trim($matches[1]) . ')');
            }
        }
        try {
            libxml_use_internal_errors(true);
            $xml = new SimpleXMLElement($xmlstr);
        } catch (\Exception $error) {

            throw new ConnectionException($error->getMessage());
        }
        if((string)$xml->attributes()->status === 'failed' )
        {
            throw new ApiFailedException($xml->error, intval($xml->error['code']));
        }
        if (!isset($error)) {
            // All is well :)
            return $xml;
        }
    }
225094
public function getText()
    {
        $parameters = func_get_args();

        //set parameter values
        if (count($parameters) > 0) {
            $pageNumber = $parameters[0];
        }


        $strURI = Product::$baseProductUri . '/pdf/' . $this->getFileName() .
            ((isset($parameters[0])) ? '/pages/' . $pageNumber . '/TextItems' : '/TextItems');

        $signedURI = Utils::sign($strURI);

        $responseStream = Utils::processCommand($signedURI, 'GET', '', '');

        $json = json_decode($responseStream);

        $rawText = '';
        foreach ($json->TextItems->List as $textItem) {
            $rawText .= $textItem->Text;
        }
        return $rawText;
    }
543020
function toString()
    {
        $modes = array();
        $levels = array(E_USER_NOTICE  => 'notice',
                        E_USER_WARNING => 'warning',
                        E_USER_ERROR   => 'error');
        if ($this->mode & PEAR_ERROR_CALLBACK) {
            if (is_array($this->callback)) {
                $callback = (is_object($this->callback[0]) ?
                    strtolower(get_class($this->callback[0])) :
                    $this->callback[0]) . '::' .
                    $this->callback[1];
            } else {
                $callback = $this->callback;
            }
            return sprintf('[%s: message="%s" code=%d mode=callback '.
                           'callback=%s prefix="%s" info="%s"]',
                           strtolower(get_class($this)), $this->message, $this->code,
                           $callback, $this->error_message_prefix,
                           $this->userinfo);
        }
        if ($this->mode & PEAR_ERROR_PRINT) {
            $modes[] = 'print';
        }
        if ($this->mode & PEAR_ERROR_TRIGGER) {
            $modes[] = 'trigger';
        }
        if ($this->mode & PEAR_ERROR_DIE) {
            $modes[] = 'die';
        }
        if ($this->mode & PEAR_ERROR_RETURN) {
            $modes[] = 'return';
        }
        return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.
                       'prefix="%s" info="%s"]',
                       strtolower(get_class($this)), $this->message, $this->code,
                       implode("|", $modes), $levels[$this->level],
                       $this->error_message_prefix,
                       $this->userinfo);
    }
290474
protected function getStatusText()
    {
        $code = $this->statusCode;
        if (empty($code)) {
            $code = 200;
        }

        return "HTTP/1.1 $code " . $this->getHttpResponseMessage($code);
    }
1160541
final public function createSendableMessage(): string
    {
        $variableHeader = $this->createVariableHeader();
        $this->logger->debug('Created variable header', ['variableHeader' => base64_encode($variableHeader)]);
        $payload = $this->createPayload();
        $this->logger->debug('Created payload', ['payload' => base64_encode($payload)]);
        $fixedHeader = $this->createFixedHeader(strlen($variableHeader . $payload));
        $this->logger->debug('Created fixed header', ['fixedHeader' => base64_encode($fixedHeader)]);

        return $fixedHeader . $variableHeader . $payload;
    }
200066
public function get_content_plain() {
		return wc_get_template_html( $this->template_plain, [
			'order'         => $this->object,
			'email_heading' => $this->get_heading(),
			'sent_to_admin' => false,
			'plain_text'    => true,
			'email'			=> $this,
		] );
	}
1234470
public function asText() : string
    {
        static $wktWriter;

        if ($wktWriter === null) {
            $wktWriter = new WKTWriter();
        }

        return $wktWriter->write($this);
    }
932455
public function as_text()
    {
        $output = '';
        $exts   = array();
        $idx    = 0;

        if (!empty($this->vars)) {
            if (in_array('variables', (array)$this->supported)) {
                $has_vars = true;
                array_push($exts, 'variables');
            }
            foreach ($this->vars as $var) {
                if (empty($has_vars)) {
                    // 'variables' extension not supported, put vars in comments
                    $output .= sprintf("# %s %s\n", $var['name'], $var['value']);
                }
                else {
                    $output .= 'set ';
                    foreach (array_diff(array_keys($var), array('name', 'value')) as $opt) {
                        $output .= ":$opt ";
                    }
                    $output .= self::escape_string($var['name']) . ' ' . self::escape_string($var['value']) . ";\n";
                }
            }
        }

        $imapflags = in_array('imap4flags', $this->supported) ? 'imap4flags' : 'imapflags';
        $notify    = in_array('enotify', $this->supported) ? 'enotify' : 'notify';

        // rules
        foreach ($this->content as $rule) {
            $script    = '';
            $tests     = array();
            $i         = 0;

            // header
            if (!empty($rule['name']) && strlen($rule['name'])) {
                $script .= '# rule:[' . $rule['name'] . "]\n";
            }

            // constraints expressions
            if (!empty($rule['tests'])) {
                foreach ($rule['tests'] as $test) {
                    $tests[$i] = '';
                    switch ($test['test']) {
                    case 'size':
                        $tests[$i] .= ($test['not'] ? 'not ' : '');
                        $tests[$i] .= 'size :' . ($test['type']=='under' ? 'under ' : 'over ') . $test['arg'];
                        break;

                    case 'true':
                        $tests[$i] .= ($test['not'] ? 'false' : 'true');
                        break;

                    case 'exists':
                        $tests[$i] .= ($test['not'] ? 'not ' : '');
                        $tests[$i] .= 'exists ' . self::escape_string($test['arg']);
                        break;

                    case 'header':
                    case 'string':
                        if ($test['test'] == 'string') {
                            array_push($exts, 'variables');
                        }

                        $tests[$i] .= ($test['not'] ? 'not ' : '');
                        $tests[$i] .= $test['test'];

                        $this->add_index($test, $tests[$i], $exts);
                        $this->add_operator($test, $tests[$i], $exts);

                        $tests[$i] .= ' ' . self::escape_string($test['arg1']);
                        $tests[$i] .= ' ' . self::escape_string($test['arg2']);
                        break;

                    case 'address':
                    case 'envelope':
                        if ($test['test'] == 'envelope') {
                            array_push($exts, 'envelope');
                        }

                        $tests[$i] .= ($test['not'] ? 'not ' : '');
                        $tests[$i] .= $test['test'];

                        if ($test['test'] != 'envelope') {
                            $this->add_index($test, $tests[$i], $exts);
                        }

                        // :all address-part is optional, skip it
                        if (!empty($test['part']) && $test['part'] != 'all') {
                            $tests[$i] .= ' :' . $test['part'];
                            if ($test['part'] == 'user' || $test['part'] == 'detail') {
                                array_push($exts, 'subaddress');
                            }
                        }

                        $this->add_operator($test, $tests[$i], $exts);

                        $tests[$i] .= ' ' . self::escape_string($test['arg1']);
                        $tests[$i] .= ' ' . self::escape_string($test['arg2']);
                        break;

                    case 'body':
                        array_push($exts, 'body');

                        $tests[$i] .= ($test['not'] ? 'not ' : '') . 'body';

                        if (!empty($test['part'])) {
                            $tests[$i] .= ' :' . $test['part'];

                            if (!empty($test['content']) && $test['part'] == 'content') {
                                $tests[$i] .= ' ' . self::escape_string($test['content']);
                            }
                        }

                        $this->add_operator($test, $tests[$i], $exts);

                        $tests[$i] .= ' ' . self::escape_string($test['arg']);
                        break;

                    case 'date':
                    case 'currentdate':
                        array_push($exts, 'date');

                        $tests[$i] .= ($test['not'] ? 'not ' : '') . $test['test'];

                        $this->add_index($test, $tests[$i], $exts);

                        if (!empty($test['originalzone']) && $test['test'] == 'date') {
                            $tests[$i] .= ' :originalzone';
                        }
                        else if (!empty($test['zone'])) {
                            $tests[$i] .= ' :zone ' . self::escape_string($test['zone']);
                        }

                        $this->add_operator($test, $tests[$i], $exts);

                        if ($test['test'] == 'date') {
                            $tests[$i] .= ' ' . self::escape_string($test['header']);
                        }

                        $tests[$i] .= ' ' . self::escape_string($test['part']);
                        $tests[$i] .= ' ' . self::escape_string($test['arg']);

                        break;

                    case 'duplicate':
                        array_push($exts, 'duplicate');

                        $tests[$i] .= ($test['not'] ? 'not ' : '') . $test['test'];

                        $tokens = array('handle', 'uniqueid', 'header');
                        foreach ($tokens as $token)
                            if ($test[$token] !== null && $test[$token] !== '') {
                                $tests[$i] .= " :$token " . self::escape_string($test[$token]);
                            }

                        if (!empty($test['seconds'])) {
                            $tests[$i] .= ' :seconds ' . intval($test['seconds']);
                        }

                        if (!empty($test['last'])) {
                            $tests[$i] .= ' :last';
                        }

                        break;
                    }

                    $i++;
                }
            }

            // disabled rule: if false #....
            if (!empty($tests)) {
                $script .= 'if ' . ($rule['disabled'] ? 'false # ' : '');

                if (count($tests) > 1) {
                    $tests_str = implode(', ', $tests);
                }
                else {
                    $tests_str = $tests[0];
                }

                if ($rule['join'] || count($tests) > 1) {
                    $script .= sprintf('%s (%s)', $rule['join'] ? 'allof' : 'anyof', $tests_str);
                }
                else {
                    $script .= $tests_str;
                }
                $script .= "\n{\n";
            }

            // action(s)
            if (!empty($rule['actions'])) {
                foreach ($rule['actions'] as $action) {
                    $action_script = '';

                    switch ($action['type']) {

                    case 'fileinto':
                        array_push($exts, 'fileinto');
                        $action_script .= 'fileinto ';
                        if ($action['copy']) {
                            $action_script .= ':copy ';
                            array_push($exts, 'copy');
                        }
                        $action_script .= self::escape_string($action['target']);
                        break;

                    case 'redirect':
                        $action_script .= 'redirect ';
                        if ($action['copy']) {
                            $action_script .= ':copy ';
                            array_push($exts, 'copy');
                        }
                        $action_script .= self::escape_string($action['target']);
                        break;

                    case 'reject':
                    case 'ereject':
                        array_push($exts, $action['type']);
                        $action_script .= $action['type'].' '
                            . self::escape_string($action['target']);
                        break;

                    case 'addflag':
                    case 'setflag':
                    case 'removeflag':
                        array_push($exts, $imapflags);
                        $action_script .= $action['type'].' '
                            . self::escape_string($action['target']);
                        break;

                    case 'keep':
                    case 'discard':
                    case 'stop':
                        $action_script .= $action['type'];
                        break;

                    case 'include':
                        array_push($exts, 'include');
                        $action_script .= 'include ';
                        foreach (array_diff(array_keys($action), array('target', 'type')) as $opt) {
                            $action_script .= ":$opt ";
                        }
                        $action_script .= self::escape_string($action['target']);
                        break;

                    case 'set':
                        array_push($exts, 'variables');
                        $action_script .= 'set ';
                        foreach (array_diff(array_keys($action), array('name', 'value', 'type')) as $opt) {
                            $action_script .= ":$opt ";
                        }
                        $action_script .= self::escape_string($action['name']) . ' ' . self::escape_string($action['value']);
                        break;

                    case 'notify':
                        array_push($exts, $notify);
                        $action_script .= 'notify';

                        $method = $action['method'];
                        unset($action['method']);
                        $action['options'] = (array) $action['options'];

                        // Here we support draft-martin-sieve-notify-01 used by Cyrus
                        if ($notify == 'notify') {
                            switch ($action['importance']) {
                                case 1: $action_script .= " :high"; break;
                                //case 2: $action_script .= " :normal"; break;
                                case 3: $action_script .= " :low"; break;
                            }

                            // Old-draft way: :method "mailto" :options "email@address"
                            if (!empty($method)) {
                                $parts = explode(':', $method, 2);
                                $action['method'] = $parts[0];
                                array_unshift($action['options'], $parts[1]);
                            }

                            unset($action['importance']);
                            unset($action['from']);
                            unset($method);
                        }

                        foreach (array('id', 'importance', 'method', 'options', 'from', 'message') as $n_tag) {
                            if (!empty($action[$n_tag])) {
                                $action_script .= " :$n_tag " . self::escape_string($action[$n_tag]);
                            }
                        }

                        if (!empty($method)) {
                            $action_script .= ' ' . self::escape_string($method);
                        }

                        break;

                    case 'vacation':
                        array_push($exts, 'vacation');
                        $action_script .= 'vacation';
                        if (isset($action['seconds'])) {
                            array_push($exts, 'vacation-seconds');
                            $action_script .= " :seconds " . intval($action['seconds']);
                        }
                        else if (!empty($action['days'])) {
                            $action_script .= " :days " . intval($action['days']);
                        }
                        if (!empty($action['addresses']))
                            $action_script .= " :addresses " . self::escape_string($action['addresses']);
                        if (!empty($action['subject']))
                            $action_script .= " :subject " . self::escape_string($action['subject']);
                        if (!empty($action['handle']))
                            $action_script .= " :handle " . self::escape_string($action['handle']);
                        if (!empty($action['from']))
                            $action_script .= " :from " . self::escape_string($action['from']);
                        if (!empty($action['mime']))
                            $action_script .= " :mime";
                        $action_script .= " " . self::escape_string($action['reason']);
                        break;
                    }

                    if ($action_script) {
                        $script .= !empty($tests) ? "\t" : '';
                        $script .= $action_script . ";\n";
                    }
                }
            }

            if ($script) {
                $output .= $script . (!empty($tests) ? "}\n" : '');
                $idx++;
            }
        }

        // requires
        if (!empty($exts)) {
            $exts = array_unique($exts);

            if (in_array('vacation-seconds', $exts) && ($key = array_search('vacation', $exts)) !== false) {
                unset($exts[$key]);
            }

            sort($exts); // for convenience use always the same order

            $output = 'require ["' . implode('","', $exts) . "\"];\n" . $output;
        }

        if (!empty($this->prefix)) {
            $output = $this->prefix . "\n\n" . $output;
        }

        return $output;
    }