This method is called by CAS_Client::CAS_Client() when running in callback
mode. It stores the PGT and its PGT Iou, prints its output and halts.

@return void
7642
private function _callback()
    {
        phpCAS::traceBegin();
        if (preg_match('/^PGTIOU-[\.\-\w]+$/', $_GET['pgtIou'])) {
            if (preg_match('/^[PT]GT-[\.\-\w]+$/', $_GET['pgtId'])) {
                $this->printHTMLHeader('phpCAS callback');
                $pgt_iou = $_GET['pgtIou'];
                $pgt = $_GET['pgtId'];
                phpCAS::trace('Storing PGT `'.$pgt.'\' (id=`'.$pgt_iou.'\')');
                echo '<p>Storing PGT `'.$pgt.'\' (id=`'.$pgt_iou.'\').</p>';
                $this->_storePGT($pgt, $pgt_iou);
                $this->printHTMLFooter();
                phpCAS::traceExit("Successfull Callback");
            } else {
                phpCAS::error('PGT format invalid' . $_GET['pgtId']);
                phpCAS::traceExit('PGT format invalid' . $_GET['pgtId']);
            }
        } else {
            phpCAS::error('PGTiou format invalid' . $_GET['pgtIou']);
            phpCAS::traceExit('PGTiou format invalid' . $_GET['pgtIou']);
        }

        // Flush the buffer to prevent from sending anything other then a 200
        // Success Status back to the CAS Server. The Exception would normally
        // report as a 500 error.
        flush();
        throw new CAS_GracefullTerminationException();
    }
1084418
public function onReady()
    {
        if ($this->pool->identd) {
            /** @noinspection PhpParamsInspection */
            $this->getSocketName();
            $this->pool->identd->registerPair($this->locAddr, $this->locPort, ['UNIX', $this->user]);
        }
        list($this->nick, $this->realname) = explode('/', $this->path . '/John Doe');
        $this->command('USER', $this->user, 0, '*', $this->realname);
        $this->command('NICK', $this->nick);
        if (mb_orig_strlen($this->password)) {
            $this->message('NickServ', 'IDENTIFY ' . $this->password);
        }
    }
837640
function start_output() {
        $this->started_output = true;
        if ($this->exportclass!==null) {
            $this->exportclass->start_table($this->sheettitle);
            $this->exportclass->output_headers($this->headers);
        } else {
            $this->start_html();
            $this->print_headers();
            echo html_writer::start_tag('tbody');
        }
    }
86492
public function onGenerateAccessToken()
    {
        if (!User::isAccessTokenValid($this->_user->access_token)) {
            $this->_user->generateAccessToken();
            $this->_user->save(false);
        }
    }
326087
private function SetErrCode()
    {
        $connection_status = @pg_connection_status($this->conn);
        $last_error = @pg_last_error($this->conn);
        $result_error = @pg_result_error($this->conn);
        $last_notice = @pg_last_notice($this->conn);

        $_errors = array();

        if ($connection_status) {
            $_errors[] = ($connection_status?$connection_status:'');
        }
        if ($last_error) {
            $_errors[] = ($last_error?$last_error:'');
        }
        if ($result_error) {
            $_errors[] = ($result_error?$result_error:'');
        }
        if ($last_notice) {
            $_errors[] = ($last_notice?$last_notice:'');
        }

        if (count($_errors) > 0) {
            //$this->errStr .= '<div style="border:1px solid black; margin:4px; padding:4px; background-color:#FFDEAD;"><b>Query:</b> '.$this->last_query . '<br />'.implode('<br />', $_errors)."</div>";
            if ($_REQUEST[act]=='api') {
                foreach ($_errors as $_error) {
                    $lines=explode("\n", $_error);
                    $api_errors[]=$lines;
                }
                $err_string=json_encode(['error'=>'DB_error','errors'=>$api_errors]);//exit;
            } else {
                $err_string='<div class="alert alert-error"><h2>DB Error</h2><b>Query:</b> '.$this->last_query . '<br /><pre class="red">'.implode('<br />', $_errors)."</pre></div>";
            }
            $this->errStr .= $err_string;
            //$this->errStr .="<pre>".print_r($GLOBALS)."</pre>";
            $GLOBALS[no_refresh]=1;
        }
    }
1314173
public function display()
    {
        // For a certain unmentionable browser
        if (ini_get('zlib.output_compression')) {
            ini_set('zlib.output_compression', 'Off');
        }

        // Remove php's time limit
        if (!ini_get('safe_mode')) {
            @set_time_limit(0);
        }

        // Mimetype
        // @TODO magic mimetypes
        if ($this->mimetype) {
            header('Content-type: '.$this->mimetype);
        }

        header('Content-Transfer-Encoding: binary');
        header('Accept-Ranges: bytes');

        // Prevent caching
        header('Pragma: public');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Expires: 0');

        // Clear buffer
        while (@ob_end_clean());

        $this->filename = basename($this->filename);

        if (!empty($this->output)) {
            // File body is passed as string

            if (empty($this->filename)) {
                throw new KViewException('No filename supplied');
            }

            $this->_setDisposition();
            $filesize = strlen($this->output);
            header('Content-Length: '.$filesize);
            flush();

            echo $this->output;
        } elseif (!empty($this->path)) {
            // File is read from disk

             if (empty($this->filename)) {
                 $this->filename = basename($this->path);
             }

            $filesize = @filesize($this->path);

            header('Content-Length: '.$filesize);

            $this->_setDisposition();

            flush();

            $this->_readChunked($this->path);
        } else {
            throw new KViewException('No output or path supplied');
        }

        die;
    }
653991
public function callback() {

        $token = required_param('oauth_token', PARAM_RAW);
        $verifier = required_param('oauth_verifier', PARAM_RAW);
        $secret = $this->flickr->get_request_token_secret(['caller' => 'repository_flickr']);

        // Exchange the request token for the access token.
        $accesstoken = $this->flickr->get_access_token($token, $secret, $verifier);

        // Store the access token and the access token secret in the user preferences.
        set_user_preference('repository_flickr_access_token', $accesstoken['oauth_token']);
        set_user_preference('repository_flickr_access_token_secret', $accesstoken['oauth_token_secret']);
    }
528248
public function write() : void
    {
        if (!$this->features) {
            return;
        }
        $i = 0;
        while (true) {
            $file = sprintf('%s/%s%s.php', $this->config->output, $this->normalize($this->objectUnderTest->getName()), $i ? ".$i" : '');
            if (!file_exists($file)) {
                break;
            }
            ++$i;
        }
        file_put_contents($file, $this->render());
    }
355036
public function init()
    {
        if ($this->isEnabled()) {
            $this->client = \PHPDaemon\Clients\IRC\Pool::getInstance();
        }
    }
748536
public function auth()
    {
        if ($this->phase !== self::PHASE_GOT_INIT) {
            return;
        }
        $this->phase = self::PHASE_AUTH_SENT;
        $this->onResponse->push(function ($conn, $result) {
            if ($conn->onConnected) {
                $conn->connected = true;
                $conn->onConnected->executeAll($conn, $result);
                $conn->onConnected = null;
            }
        });
        $this->clientFlags =
            Pool::CLIENT_LONG_PASSWORD |
            Pool::CLIENT_LONG_FLAG |
            Pool::CLIENT_LOCAL_FILES |
            Pool::CLIENT_PROTOCOL_41 |
            Pool::CLIENT_INTERACTIVE |
            Pool::CLIENT_TRANSACTIONS |
            Pool::CLIENT_SECURE_CONNECTION |
            Pool::CLIENT_MULTI_STATEMENTS |
            Pool::CLIENT_MULTI_RESULTS;

        $this->sendPacket(
            $packet = pack('VVc', $this->clientFlags, $this->pool->maxAllowedPacket, $this->charsetNumber)
                . "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                . $this->user . "\x00"
                . ($this->password === '' ? "\x00" : $this->buildLenEncodedBinary(
                    $this->getAuthToken($this->scramble, $this->password)
                ))
                . ($this->path !== '' ? $this->path . "\x00" : '')
        );
    }
19717
public function output()
    {
        $imageFile = $this->storage->getPath($this);

        if(file_exists($imageFile))
        {
            header('Content-Type: image');
            header('Content-Length: ' . filesize($imageFile));

            readfile($imageFile);
            exit;
        }
    }
876862
public function callback() {
		$timestamp = date('c');

		// To standardize the way of accessing data, objects are translated to arrays
		$this->auth = $this->recursiveGetObjectVars($this->auth);

		$this->auth['provider'] = $this->strategy['strategy_name'];

		$params = array(
			'auth' => $this->auth,
			'timestamp' => $timestamp,
			'signature' => $this->sign($timestamp)
		);

		$this->shipToCallback($params);
	}
475884
private function outputSetup()
    {
        $this->debug->groupCollapsed(__METHOD__);
        $cfg        = $this->form->cfg;
        $persist    = $this->form->persist;
        $this->keyValue = $persist->get('key').'_'.$persist->get('i');
        $this->debug->info('keyValue', $this->keyValue);
        if ($cfg['output']['autofocus']) {
            $autofocusField = null;
            $invalidFields = $this->form->getInvalidFields();
            if ($invalidFields) {
                $this->debug->warn('autofocusing invalid');
                $autofocusField = \current($invalidFields);
            } else {
                foreach ($this->form->currentFields as $k => $field) {
                    // $this->debug->log('field->attribs', $field->attribs);
                    $autofocusable = \in_array($field->tagname, array('input','textarea','select'))
                        && !\in_array($field->attribs['type'], array('button','hidden','reset','submit'));
                    if (isset($field->attribs['autofocus'])) {
                        if ($field->attribs['autofocus']) {
                            $this->debug->log('autofocus attrib explicitly set for', $k);
                            $autofocusField = $field;
                            break;
                        }
                    } elseif (!$autofocusField && $autofocusable) {
                        $autofocusField = $field;
                        // don't break... may find a field that's explicitly autofocused
                    }
                }
            }
            if ($autofocusField) {
                $autofocusField->focus();
            }
        }
        $this->debug->groupEnd();
    }
202039
public function process_stage_confirm() {
        global $CFG, $DB, $OUTPUT;

        $previous = $DB->get_records(
            'portfolio_log',
            array(
                'userid'      => $this->user->id,
                'portfolio'   => $this->instance->get('id'),
                'caller_sha1' => $this->caller->get_sha1(),
            )
        );
        if (isset($this->noexportconfig) && empty($previous)) {
            return true;
        }
        $strconfirm = get_string('confirmexport', 'portfolio');
        $baseurl = $CFG->wwwroot . '/portfolio/add.php?sesskey=' . sesskey() . '&id=' . $this->get('id');
        $yesurl = $baseurl . '&stage=' . PORTFOLIO_STAGE_QUEUEORWAIT;
        $nourl  = $baseurl . '&cancel=1';
        $this->print_header(get_string('confirmexport', 'portfolio'));
        echo $OUTPUT->box_start();
        echo $OUTPUT->heading(get_string('confirmsummary', 'portfolio'), 3);
        $mainsummary = array();
        if (!$this->instance->get_export_config('hideformat')) {
            $mainsummary[get_string('selectedformat', 'portfolio')] = get_string('format_' . $this->instance->get_export_config('format'), 'portfolio');
        }
        if (!$this->instance->get_export_config('hidewait')) {
            $mainsummary[get_string('selectedwait', 'portfolio')] = get_string(($this->instance->get_export_config('wait') ? 'yes' : 'no'));
        }
        if ($previous) {
            $previousstr = '';
            foreach ($previous as $row) {
                $previousstr .= userdate($row->time);
                if ($row->caller_class != get_class($this->caller)) {
                    if (!empty($row->caller_file)) {
                        portfolio_include_callback_file($row->caller_file);
                    } else if (!empty($row->caller_component)) {
                        portfolio_include_callback_file($row->caller_component);
                    } else { // Ok, that's weird - this should never happen. Is the apocalypse coming?
                        continue;
                    }
                    $previousstr .= ' (' . call_user_func(array($row->caller_class, 'display_name')) . ')';
                }
                $previousstr .= '<br />';
            }
            $mainsummary[get_string('exportedpreviously', 'portfolio')] = $previousstr;
        }
        if (!$csummary = $this->caller->get_export_summary()) {
            $csummary = array();
        }
        if (!$isummary = $this->instance->get_export_summary()) {
            $isummary = array();
        }
        $mainsummary = array_merge($mainsummary, $csummary, $isummary);
        $table = new html_table();
        $table->attributes['class'] = 'generaltable exportsummary';
        $table->data = array();
        foreach ($mainsummary as $string => $value) {
            $table->data[] = array($string, $value);
        }
        echo html_writer::table($table);
        echo $OUTPUT->confirm($strconfirm, $yesurl, $nourl);
        echo $OUTPUT->box_end();
        echo $OUTPUT->footer();
        return false;
    }
600055
protected function initializeProxyTicket()
    {
        if (!empty($this->_proxyTicket)) {
            throw new CAS_OutOfSequenceException(
                'Already initialized, cannot initialize again.'
            );
        }
        // Allow usage of a particular CAS_Client for unit testing.
        if (empty($this->_casClient)) {
            phpCAS::initializeProxiedService($this);
        } else {
            $this->_casClient->initializeProxiedService($this);
        }
    }
488326
public function onRead()
    {
        while (($line = $this->readline()) !== null) {
            if ($line === '') {
                continue;
            }
            if (mb_orig_strlen($line) > 512) {
                Daemon::$process->log('IRCClientConnection error: buffer overflow.');
                $this->finish();
                return;
            }
            $line = mb_orig_substr($line, 0, -mb_orig_strlen($this->EOL));
            $p = mb_orig_strpos($line, ' :', 1);
            $max = $p !== false ? substr_count($line, "\x20", 0, $p + 1) + 1 : 18;
            $e = explode("\x20", $line, $max);
            $i = 0;
            $from = IRC::parseUsermask($e[$i]{0} === ':' ? mb_orig_substr($e[$i++], 1) : null);
            $cmd = $e[$i++];
            $args = [];

            for ($s = min(sizeof($e), 14); $i < $s; ++$i) {
                if ($e[$i][0] === ':') {
                    $args[] = mb_orig_substr($e[$i], 1);
                    break;
                }
                $args[] = $e[$i];
            }

            if (ctype_digit($cmd)) {
                $code = (int)$cmd;
                $cmd = isset(IRC::$codes[$code]) ? IRC::$codes[$code] : $code;
            }
            $this->lastLine = $line;
            $this->onCommand($from, $cmd, $args);
        }
        if (mb_orig_strlen($this->buf) > 512) {
            Daemon::$process->log('IRCClientConnection error: buffer overflow.');
            $this->finish();
        }
    }
1076224
protected function begin_transaction() {
        $this->savepointpresent = true;
        $sql = "BEGIN ISOLATION LEVEL READ COMMITTED; SAVEPOINT moodle_pg_savepoint";
        $this->query_start($sql, null, SQL_QUERY_AUX);
        $result = pg_query($this->pgsql, $sql);
        $this->query_end($result);

        pg_free_result($result);
    }