本文整理汇总了PHP中formatJSEND函数的典型用法代码示例。如果您正苦于以下问题:PHP formatJSEND函数的具体用法?PHP formatJSEND怎么用?PHP formatJSEND使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了formatJSEND函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Load
public function Load()
{
if (!file_exists(DATA . "/settings.php")) {
saveJSON('settings.php', array($this->username => array('codiad.username' => $this->username)));
}
$settings = getJSON('settings.php');
echo formatJSEND("success", $settings[$this->username]);
}
示例2: Run
public function Run()
{
$filepath = "{$this->root}/{$this->get['filepath']}";
$tmpfname = tempnam("/tmp", "shipshape-results-");
$fp = fopen($tmpfname, "w");
fclose($fp);
$ret = runShellCommand("shipshape --categories='go vet,JSHint,PyLint' --json_output={$tmpfname}" . " {$this->escapeShellArg($filepath)}");
echo formatJSEND('success', json_decode(file_get_contents($tmpfname)));
unlink($tmpfname);
}
示例3: Run
public function Run()
{
$filepath = "{$this->root}/{$this->get['filepath']}";
// Truncate the output json file.
$fp = fopen("/tmp/shipshape-results.json", "w");
fclose($fp);
$ret = runShellCommand("shipshape --categories='go vet,JSHint,PyLint'" . " --json_output=/tmp/shipshape-results.json" . " {$this->escapeShellArg($filepath)}");
if ($ret->exit_code != 0) {
// If for any reason shipshape command failed, we don't want to show error message.
// The reason could be simply that there is no reference at the requested position.
echo formatJSEND('success', 'Running shipshape failed.');
return;
}
echo formatJSEND('success', json_decode(file_get_contents('/tmp/shipshape-results.json')));
}
示例4: GetUserCount
public function GetUserCount()
{
/* Array */
$cur_users = array();
foreach ($this->actives as $data) {
if (is_array($data) && isset($data['username']) && $data['username'] != $this->username && $data['path'] == $this->path) {
$cur_users[] = $data['username'];
}
}
/* Prepare the return data. */
/* Array */
$data = array();
$data['count'] = count($cur_users);
echo formatJSEND("success", $data);
}
示例5: Execute
public function Execute()
{
$macrolist = $this->Load();
$command = $macrolist[$this->id]['c'];
if (!$this->isAbsPath($this->path)) {
$this->path = WORKSPACE . '/' . $this->path;
}
if (is_file($this->path)) {
$command = str_replace('%FILE%', $this->path, $command);
$command = str_replace('%FOLDER%', dirname($this->path), $command);
$command = str_replace('%NAME%', basename($this->path), $command);
} else {
$command = str_replace('%FOLDER%', $this->path, $command);
$command = str_replace('%NAME%', basename($this->path), $command);
}
shell_exec($command);
echo formatJSEND("success", null);
}
示例6: pull
public function pull()
{
$cli_params = array();
$cli_params[] = "--non-interactive";
if ($this->username != '') {
$cli_params[] = "--username " . $this->username;
}
if ($this->password != '') {
//Need to clean up the password so it can be passed to the cli, If anyone find's or thinks of more let me know tholum@couleetechlink.com
$this->password = str_replace(array("*", "^", "&", '"'), array('\\*', '\\^', '\\&', '\\"'), $this->password);
$cli_params[] = "--password " . $this->password;
}
if ($this->svnrepo) {
if (!$this->isAbsPath($this->path)) {
if (!file_exists(WORKSPACE . '/' . $this->path)) {
$this->command_exec = "cd " . WORKSPACE . " && svn co \"" . $this->svnrepo . "\" " . $this->path . " " . implode(" ", $cli_params);
} else {
die(formatJSEND("success", array("message" => "Folder already exists")));
}
} else {
if (!file_exists($this->path)) {
$this->command_exec = "cd " . WORKSPACE . " && svn co \"" . $this->svnrepo . "\" " . $this->path . " " . implode(" ", $cli_params);
} else {
die(formatJSEND("success", array("message" => "Folder already exists")));
}
}
if ($this->newproject) {
$this->projects = getJSON('projects.php');
$this->projects[] = array("name" => $this->name, "path" => $this->path);
saveJSON('projects.php', $this->projects);
}
$this->ExecuteCMD();
echo formatJSEND("success", array("message" => "Repo cloned"));
} else {
echo formatJSEND("error", array("message" => "No Repo specified"));
}
}
示例7: pull
public function pull()
{
if ($this->gitrepo) {
if (!$this->isAbsPath($this->path)) {
if (!file_exists(WORKSPACE . '/' . $this->path)) {
mkdir(WORKSPACE . '/' . $this->path);
$this->command_exec = "cd " . WORKSPACE . '/' . $this->path . " && git init && git pull " . $this->gitrepo . " " . $this->gitbranch;
} else {
die(formatJSEND("success", array("message" => "Folder already exists")));
}
} else {
if (!file_exists($this->path)) {
mkdir($this->path);
$this->command_exec = "cd " . $this->path . " && git init && git pull " . $this->gitrepo . " " . $this->gitbranch;
} else {
die(formatJSEND("success", array("message" => "Folder already exists")));
}
}
$this->ExecuteCMD();
echo formatJSEND("success", array("message" => "Repo cloned"));
} else {
echo formatJSEND("error", array("message" => "No Repo specified"));
}
}
示例8: formatJSEND
}
} else {
// Set the session username.
$_SESSION['user'] = $User->username;
}
// Set the session language, if given, or set it to english as default.
if (isset($_POST['language'])) {
$_SESSION['lang'] = $_POST['language'];
} else {
$_SESSION['lang'] = "en";
}
// Set the session theme and project.
$_SESSION['theme'] = $_POST['theme'];
$_SESSION['project'] = $_POST['project'];
// Respond by sending verification tokens on success.
echo formatJSEND("success", array('username' => $User->username));
header("Location: " . $_SERVER['PHP_SELF'] . "?action=verify");
}
} elseif ($count > 1) {
// We returned too many results. Error as such.
die(formatJSEND("error", "A server error occurred: LDAP filter result is non-unique. Please ensure this is a unique identifier within its context.\n\t\t\t\t\t If the problem persists, please contact the webmaster. If you are the webmaster, please check the LDAP filter used."));
} else {
// Invalid login.
die(formatJSEND("error", "Incorrect user name or password."));
}
} else {
// The server is having issues connecting to the LDAP server. Error as such.
die(formatJSEND("error", "An error occurred: Cannot connect to LDAP server. Please contact the webmaster. \n If you are the webmaster, please contact your LDAP server administrator or check if your LDAP server is running."));
}
}
}
示例9: ListBranches
public function ListBranches()
{
$repo = Common::GetProjectRoot();
$ret = runShellCommand("git -C {$this->escapeShellArg($repo)} branch --no-color " . " | awk -F ' +' '! /\\(no branch\\)/ {print \$2}' ");
if ($ret->exit_code != 0 || count($ret->output) == 0) {
echo formatJSEND('error', 'No branches in this project.');
return;
}
$branches = $ret->output;
$currentBranch = $this->GetCurrentBranchName();
$result = new stdClass();
$result->current_branch = trim($currentBranch);
$result->branches = $branches;
echo formatJSEND('success', $result);
}
示例10: Check
public function Check()
{
$local = $this->getLocalVersion();
$remote = $this->getRemoteVersion("check", $local[0]['version']);
$nightly = true;
$archive = Common::getConstant('ARCHIVEURL', $this->archive);
$latest = '';
foreach ($remote as $tag) {
if ($latest == '') {
$latest = $tag["name"];
$archive = $tag["zipball_url"];
}
if ($local[0]['version'] == $tag["commit"]["sha"]) {
$local[0]['version'] = $tag["name"];
$nightly = false;
break;
}
}
$search = array("\r\n", "\n", "\r");
$replace = array(" ", " ", " ");
$message = '';
$merge = '';
$commits = json_decode(file_get_contents(Common::getConstant('COMMITURL', $this->commits)), true);
foreach ($commits as $commit) {
if ($local[0]['version'] != $commit["sha"]) {
if (strpos($commit["commit"]["message"], "Merge") === false) {
$message .= '- ' . str_replace($search, $replace, $commit["commit"]["message"]) . '<br/>';
} else {
$merge .= '- ' . str_replace($search, $replace, $commit["commit"]["message"]) . '<br/>';
}
} else {
break;
}
}
if ($message == '') {
$message = $merge;
}
return "[" . formatJSEND("success", array("currentversion" => $local[0]['version'], "remoteversion" => $latest, "message" => $message, "archive" => $archive, "nightly" => $nightly, "name" => $local[0]['name'])) . "]";
}
示例11: die
//////////////////////////////////////////////////////////////////
// Change Password
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'password') {
if (!isset($_POST['username']) || !isset($_POST['password'])) {
die(formatJSEND("error", "Missing username or password"));
}
if (checkAccess() || $_POST['username'] == $_SESSION['user']) {
$User->username = $_POST['username'];
$User->password = $_POST['password'];
$User->Password();
}
}
//////////////////////////////////////////////////////////////////
// Change Project
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'project') {
if (!isset($_GET['project'])) {
die(formatJSEND("error", "Missing project"));
}
$User->username = $_SESSION['user'];
$User->project = $_GET['project'];
$User->Project();
}
//////////////////////////////////////////////////////////////////
// Verify User Account
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'verify') {
$User->username = $_SESSION['user'];
$User->Verify();
}
示例12: Project
public function Project()
{
$revised_array = array();
foreach ($this->users as $user => $data) {
if ($this->username == $data['username']) {
$revised_array[] = array("username" => $data['username'], "password" => $data['password'], "project" => $this->project);
} else {
$revised_array[] = array("username" => $data['username'], "password" => $data['password'], "project" => $data['project']);
}
}
// Save array back to JSON
saveJSON('users.php', $revised_array);
// Response
echo formatJSEND("success", null);
}
示例13: GetDebuggee
public function GetDebuggee($repo_name, $revision_id)
{
$token = $this->GetAccessToken();
$project_num = $this->GetCloudProjectNum();
// Call API to get a list of all (active) debugees.
$opts = array('http' => array('header' => "Authorization: Bearer {$token}\r\n"));
$resp = $this->FileGetContents("{$this->gapi_prefix}/debuggees?project={$project_num}", $opts);
if ($resp['code'] !== '200') {
throw new Exception('Cannot list debuggees for this Google Cloud project.', $resp['code']);
}
$resp_json = json_decode($resp['body']);
// Debuggees may disappear even if an application is currently deployed,
// e.g, if an application has gone offline.
if (empty($resp_json->debuggees) || !is_array($resp_json->debuggees) || count($resp_json->debuggees) === 0) {
throw new Exception('No debuggee exists in this Google Cloud project.');
}
// Try to find a best match with the (numeric) project id, repo name, and revision id.
foreach ($resp_json->debuggees as $debuggee) {
// 'sourceContexts' may not always exist.
if ($debuggee->project === $project_num && !empty($debuggee->sourceContexts)) {
foreach ($debuggee->sourceContexts as $context) {
if (!empty($context->cloudRepo->repoId->projectRepoId)) {
$repo = $context->cloudRepo->repoId->projectRepoId;
if ($repo->repoName === $repo_name && $context->cloudRepo->revisionId === $revision_id) {
// Found a perfect match. Return its id. Return the entire debuggee list together
// anyway so that users may manually select one if they wish to.
echo formatJSEND('success', array('id' => $debuggee->id, 'list' => $resp_json->debuggees));
return;
}
}
}
}
}
// Did not find a matching debuggee. Return the entire debuggee list anyway.
echo formatJSEND('success', array('list' => $resp_json->debuggees));
}
示例14: Update
public function Update($type, $name)
{
function rrmdir($path)
{
return is_file($path) ? @unlink($path) : @array_map('rrmdir', glob($path . '/*')) == @rmdir($path);
}
function cpy($source, $dest, $ign)
{
if (is_dir($source)) {
$dir_handle = opendir($source);
while ($file = readdir($dir_handle)) {
if (!in_array($file, $ign)) {
if (is_dir($source . "/" . $file)) {
if (!file_exists($dest . "/" . $file)) {
mkdir($dest . "/" . $file);
}
cpy($source . "/" . $file, $dest . "/" . $file, $ign);
} else {
copy($source . "/" . $file, $dest . "/" . $file);
}
}
}
closedir($dir_handle);
} else {
copy($source, $dest);
}
}
if (file_exists(BASE_PATH . '/' . $type . '/' . $name . '/' . rtrim($type, "s") . '.json')) {
$data = json_decode(file_get_contents(BASE_PATH . '/' . $type . '/' . $name . '/' . rtrim($type, "s") . '.json'), true);
if (substr($data[0]['url'], -4) == '.git') {
$data[0]['url'] = substr($data[0]['url'], 0, -4);
}
$data[0]['url'] .= '/archive/master.zip';
$ign = array(".", "..");
if (isset($data[0]['exclude'])) {
foreach (explode(",", $data[0]['exclude']) as $exclude) {
array_push($ign, $exclude);
}
}
if (file_exists(BASE_PATH . '/' . $type . '/_' . session_id()) || mkdir(BASE_PATH . '/' . $type . '/_' . session_id())) {
if (file_put_contents(BASE_PATH . '/' . $type . '/_' . session_id() . '/' . $name . '.zip', fopen($data[0]['url'], 'r'))) {
$zip = new ZipArchive();
$res = $zip->open(BASE_PATH . '/' . $type . '/_' . session_id() . '/' . $name . '.zip');
// open downloaded archive
if ($res === true) {
// extract archive
if ($zip->extractTo(BASE_PATH . '/' . $type . '/_' . session_id() . '') === true) {
$zip->close();
$srcname = $name;
if (substr($srcname, -6) != "master") {
$srcname = $srcname . '-master';
}
cpy(BASE_PATH . '/' . $type . '/_' . session_id() . '/' . $srcname, BASE_PATH . '/' . $type . '/' . $name, $ign);
} else {
die(formatJSEND("error", "Unable to open " . $name . ".zip"));
}
} else {
die(formatJSEND("error", "ZIP Extension not found"));
}
rrmdir(BASE_PATH . '/' . $type . '/_' . session_id());
// Response
echo formatJSEND("success", null);
} else {
die(formatJSEND("error", "Unable to download " . $repo));
}
} else {
die(formatJSEND("error", "Unable to create temp dir "));
}
} else {
echo formatJSEND("error", "Unable to find " . $name);
}
}
示例15: array
// Save array back to JSON and set the session username.
$User->users[] = array('username' => $User->username, 'password' => null, 'project' => "");
saveJSON("users.php", $User->users);
$_SESSION['user'] = $User->username;
} else {
// Deny login and send message, the user doesn't exist within users.php.
die(formatJSEND("error", "User " . $User->username . " does not exist within Codiad."));
}
} else {
// Set the session username.
$_SESSION['user'] = $User->username;
}
// Set the session language, if given, or set it to english as default.
if (isset($_POST['language'])) {
$_SESSION['lang'] = $_POST['language'];
} else {
$_SESSION['lang'] = "en";
}
// Set the session theme and project.
$_SESSION['theme'] = $_POST['theme'];
$_SESSION['project'] = $_POST['project'];
// Respond by sending verification tokens on success.
echo formatJSEND("success", array('username' => $User->username));
header("Location: " . $_SERVER['PHP_SELF'] . "?action=verify");
} else {
// Invalid login.
die(formatJSEND("error", "Invalid user name or password."));
}
}
}
}