AmyRemoteProject::load_resource PHP Method

load_resource() public static method

public static load_resource ( $project_url, $ticket, $path )
    public static function load_resource($project_url, $ticket, $path)
    {
        $url = fix_parse_url($project_url);
        $response = SimpleHTTP::send('POST', $url['host'], $url['port'], $url['path'], array('a' => 'load_resource', 'ticket' => $ticket, 'path' => $path));
        if ('200' != $response['status_code']) {
            throw new Exception("Invalid status code `{$response['status_code']}' returned from server `{$url['host']}'.");
        }
        $content = trim($response['body']);
        // AmyLogger::logn($content);
        if ('' === $content) {
            throw new Exception("Unable to load project resource, no content returned from `{$url['host']}{$url['path']}'.");
        }
        if (false !== strpos($response['headers']['content-type'], 'text/xml')) {
            return array('flush' => true, 'content' => $content);
        }
        if ('#S#' != substr($content, 0, 3)) {
            throw new Exception("Error while loading project resource: Message from {$url['host']}{$url['path']}: " . substr($content, 3));
        }
        return array('flush' => false, 'content' => substr($content, 3));
    }

Usage Example

Example #1
0
    public function on_collaboration_invite($pars)
    {
        try {
            if ('' == $pars['url'] && isset($pars['content'])) {
                // resource not in the project tree
                $content = $pars['content'];
            } else {
                $content = AmyRemoteProject::load_resource($pars['url'], $pars['ticket'], $pars['path']);
            }
            if (false === ($row = Db::find_first("SELECT * FROM amy.coll_create(" . $this->user->userId . ", '" . Db::quote_literal($pars['url']) . "', '" . Db::quote_literal($pars['path']) . "', '" . Db::quote_literal($content) . "', '" . Db::quote_literal($pars['email']) . "', '" . Db::quote_literal($pars['permission']) . "', '" . Db::quote_literal($pars['message']) . "', '3:00:00')"))) {
                self::raiseError('Unable to invite: ' . Db::last_error());
            }
            $mail = new Mail($this->user->credentials['email'], $pars['email']);
            $body = <<<BODY
Hello, {$this->user->credentials['nickname']} has invited you to collaborate on the document `{$pars['path']}' via the Amy Editor.

----------------------------
{$pars['message']}
----------------------------

You can either visit the link http://www.april-child.com/amy/amy.php?invitation_code={$row['invitation_hash']} or (if you have already Amy Editor open) go to the File > Collaboration > Accept ... menu and enter the code: {$row['invitation_hash']}

Cheers,
Amy Editor.
BODY;
            $mail->send('Amy Editor - Invitation to collaboration on ' . $pars['path'], $body);
            self::setResult($row);
        } catch (Exception $e) {
            self::raiseError($e->getMessage());
        }
    }
All Usage Examples Of AmyRemoteProject::load_resource