示例#1
0
/**
 * Main function of this module which outputs csv as attachment or json/jsonp.
 */
function OutputCSI($id, $testPath, $run, $cached, $runs, $format)
{
    // Check whether a test-id and test-path are available.
    if (is_null($id) || is_null($testPath)) {
        header('HTTP/1.0 404 Not Found');
        return;
    }
    $data = null;
    if ($format == 'csv') {
        OutputCsvHeaders('csi.csv');
    } else {
        if ($format == 'json') {
            $data = array();
        }
    }
    // If it is for a particular run specified by the $run variable, then output
    // csi only for that run. Else, output for all.
    if (!is_null($_GET['run'])) {
        ParseCsiForRun($id, $testPath, $run, $cached, $data);
    } else {
        if ($runs) {
            for ($run = 1; $run <= $runs; $run++) {
                // First-view.
                ParseCsiForRun($id, $testPath, $run, FALSE, $data);
                // Repeat-view.
                ParseCsiForRun($id, $testPath, $run, TRUE, $data);
            }
        }
    }
    if ($format == 'json') {
        json_response($data);
    }
}
示例#2
0
文件: auth.php 项目: diplix/Monocle
function require_login_json(&$app)
{
    if ($user = current_user()) {
        return $user;
    }
    json_response($app, array('error' => 'not_logged_in'));
    return false;
}
示例#3
0
 function index()
 {
     //
     cxp_update_cache($this->site_id);
     // $this->output->set_output('success');
     // $this->load->view('alert', $this->template_data);
     json_response(array('success' => FALSE, 'msg' => 'Success'));
 }
function json_success($result, $id)
{
    $object = new stdClass();
    $object->error = null;
    $object->result = $result;
    $object->id = $id;
    json_response($object);
}
 /**
  * Deletes a specific post based on ID.
  *
  * @param $id
  * @param Http $http
  *
  * @return \Herbert\Framework\Response
  *
  * @throws HttpErrorException
  */
 public function deletePost($id, Http $http)
 {
     $this->allowed($http->ip());
     $deleted = ApiPost::query()->where('ID', $id)->delete();
     if ($deleted) {
         return json_response(['Success']);
     }
     return response('Nothing deleted', 404);
 }
示例#6
0
文件: Login.php 项目: ishawge/cxpcms
 function change_password()
 {
     if (strtoupper($_SERVER['REQUEST_METHOD']) === 'POST') {
         $this->load->helper(array('server'));
         $this->form_validation->set_rules('password', 'New Password', 'trim|required');
         $this->form_validation->set_rules('confirmpassword', 'Confirm New Password', 'trim|required');
         if ($this->form_validation->run() === FALSE) {
             json_response(array('success' => FALSE, 'msg' => validation_errors()));
         } else {
             $user_id = intval($this->input->post('user_id'));
             $password = trim($this->input->post('password'));
             if ($user_id) {
                 $this->db->where('id', $user_id);
                 $data = array('password' => password_hash($password, PASSWORD_BCRYPT));
                 $this->db->update('users', $data);
                 json_response(array('success' => TRUE, 'msg' => 'Update Password Success'));
             } else {
                 json_response(array('success' => FALSE, 'msg' => 'Invalid'));
             }
         }
     } else {
         $user_id = intval($this->input->get('user_id'));
         $token_code = trim($this->input->get('token_code'));
         if ($user_id && $token_code) {
             $this->db->where('user_id', $user_id);
             $this->db->where('random_string', $token_code);
             $row = $this->db->get('forget_pwd')->row();
             if ($row) {
                 // valid link
                 // delete used rendom_string
                 $this->db->where('id', $row->id);
                 $this->db->delete('forget_pwd');
                 $data['success'] = TRUE;
                 $data['message'] = '';
                 $data['user_id'] = $row->user_id;
             } else {
                 //
                 $data['success'] = FALSE;
                 $data['message'] = 'Invalid Link';
             }
         } else {
             // invalid
             $data['success'] = FALSE;
             $data['message'] = 'Invalid Link';
         }
         $this->load->view('changepassword', $data);
     }
 }
示例#7
0
function OT_customFShare()
{
    $link = $_POST['link'];
    $like_array = json_response('http://graph.facebook.com/fql?q=SELECT%20url,%20share_count%20FROM%20link_stat%20WHERE%20url="' . $link . '"');
    if ($like_array != false) {
        if (isset($like_array->data[0]->share_count)) {
            $like_count = intval($like_array->data[0]->share_count);
        } else {
            $like_count = 0;
        }
        if (is_int($like_count)) {
            echo $like_count;
        } else {
            echo 0;
        }
    }
    die;
}
示例#8
0
/**
 * An Error json response
 * @param $title
 * @param $content
 * @return \Illuminate\Http\JsonResponse
 */
function json_response_error_alert($title, $content = '')
{
    return json_response($title, $content, 'alert');
}
示例#9
0
文件: Roles.php 项目: ishawge/cxpcms
 function delete()
 {
     check_permission('admin-del-role');
     $id = intval($this->input->get('id'));
     $this->db->trans_begin();
     $this->db->where('roleID', $id);
     $this->db->delete('role_perms');
     $this->db->where('roleID', $id);
     $this->db->delete('user_roles');
     //
     $this->db->where('id', $id);
     $this->db->delete('roles');
     $this->db->trans_complete();
     cxp_update_cache();
     json_response(array('success' => TRUE, 'msg' => 'Delete Role Success'));
 }
示例#10
0
文件: geocode.php 项目: aaronpk/Atlas
        $response = ['latitude' => null, 'longitude' => null, 'locality' => null, 'region' => null, 'country' => null, 'best_name' => null, 'full_name' => null, 'timezone' => null, 'offset' => null, 'seconds' => null, 'localtime' => null];
        if (k($params, 'input')) {
            $adr = p3k\Geocoder::geocode($params['input']);
        } else {
            $lat = (double) $params['latitude'];
            $lng = (double) $params['longitude'];
            $response['latitude'] = $lat;
            $response['longitude'] = $lng;
            $adr = p3k\Geocoder::adrFromLocation($lat, $lng);
        }
        if ($adr) {
            $response['latitude'] = $adr->latitude;
            $response['longitude'] = $adr->longitude;
            $response['locality'] = $adr->localityName;
            $response['region'] = $adr->regionName;
            $response['country'] = $adr->countryName;
            $response['best_name'] = $adr->bestName;
            $response['full_name'] = $adr->fullName;
        }
        $timezone = p3k\Timezone::timezone_for_location($response['latitude'], $response['longitude'], k($params, 'date'));
        if ($timezone) {
            $response['timezone'] = $timezone->name;
            $response['offset'] = $timezone->offset;
            $response['seconds'] = $timezone->seconds;
            $response['localtime'] = $timezone->localtime;
        }
        json_response($app, $response);
    } else {
        json_response($app, ['error' => 'invalid_request', 'error_description' => 'Request was missing parameters'], 400);
    }
});
示例#11
0
/**
* @desc Modifica el orden de las secciones
**/
function changeOrderSections()
{
    global $xoopsSecurity;
    if (!$xoopsSecurity->check()) {
        json_response(__('Session token expired!', 'docs'), 1);
    }
    parse_str(rmc_server_var($_POST, 'items', ''));
    if (empty($list)) {
        json_response(__('Data not valid!', 'docs'), 1);
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $res = '';
    $pos = 0;
    foreach ($list as $id => $parent) {
        $parent = $parent == 'root' ? 0 : $parent;
        if ($parent == 0 && !is_object($res)) {
            $res = new RDSection($id);
        }
        $sql = "UPDATE " . $db->prefix("rd_sections") . " SET parent={$parent}, `order`={$pos} WHERE id_sec={$id}";
        $db->queryF($sql);
        $pos++;
    }
    json_response(__('Sections positions saved!', 'docs'), 0, $res->getVar('id_res'));
}
示例#12
0
<?php

try {
    require "./db.php";
    $REQUEST = get_request_data();
    if (!array_key_exists('cohortid', $REQUEST)) {
        throw new Exception('Did not supply cohortid');
    }
    echo json_response('success', null, get_user_list($REQUEST['cohortid']));
} catch (Exception $e) {
    echo json_response('error', $e->getMessage(), null);
}
示例#13
0
 function delete()
 {
     check_permission('admin-del-event');
     $id = intval($this->input->get('id'));
     $this->db->where('id', $id);
     $this->db->where('user_id', $this->user->id);
     $this->db->delete('events');
     operation_log(array('user_id' => $this->user->id, 'content' => '删除事件:' . $id));
     json_response(array('success' => TRUE, 'msg' => '删除事件成功'));
 }
示例#14
0
        $name = strtolower($details["name"]);
        if (count($details)) {
            foreach ($whitelist as $term) {
                if (strlen($term) > 3 && trim($term)) {
                    if (stristr($name, $term) or stristr($artist, $term)) {
                        return true;
                    }
                }
            }
            foreach ($blacklist as $term) {
                if (strlen($term) > 3 && trim($term)) {
                    if (stristr($name, $term) or stristr($artist, $term)) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
if (!checkBlacklist($details)) {
    json_response(['success' => false, 'reason' => "That song matches the blacklist in this room."]);
}
if (count($details)) {
    $details['success'] = true;
    json_response($details);
}
$response = $video->responseArray();
if (isset($response['error'])) {
    json_response(['success' => false, 'message' => $response['error']['message']]);
}
示例#15
0
文件: logout.php 项目: potch/spenses
<?php

require_once './db.php';
$expire = time() - 3600;
setcookie('user[name]', '', $expire, '/');
setcookie('user[userid]', '', $expire, '/');
setcookie('user[nick]', '', $expire, '/');
setcookie('user[email]', '', $expire, '/');
unset($_COOKIE['user']);
echo json_response('success', null, null);
示例#16
0
文件: api.php 项目: nerea91/vue
function json_response($code, array $data, array $errors = [])
{
    if ($errors) {
        $data['errors'] = $errors;
    }
    http_response_code($code);
    header('Access-Control-Allow-Origin: *');
    header('Content-Type: application/json');
    echo json_encode($data);
    exit;
}
// Emulate a failure on 1/5 of the time
if (time() % 5 == 0) {
    json_response(400, [], ['Random failure emulation', rand(), rand(), rand()]);
}
// Emulate backend routes
switch (trim($_SERVER['QUERY_STRING'], '/')) {
    default:
        json_response(404, [], ['Page Not found']);
    case 'save':
        json_response(200, []);
    case 'getMask':
        json_response(200, [[0, 1, 2]]);
    case 'stats':
        $request = json_decode($_POST['data']);
        $response = ['prob_total' => rand(0, 100), 'groups' => []];
        foreach ($request->groups as $key => $notUsed) {
            $response['groups'][] = (object) ['pN' => rand(0, 100), 'pQ' => rand(0, 100), 'p' => rand(0, 100), 'rN' => rand(0, 100), 'rQ' => rand(0, 100), 'r' => rand(0, 100), 'cada' => rand(0, 1000)];
        }
        json_response(200, $response);
}
        $out = array('name' => $_FILES['attach']['name'], 'size' => $_FILES['attach']['size'], 'type' => $_FILES['attach']['type'], 'error' => strip_tags($msg));
    }
    $res = array('attach' => array($out));
} elseif (isset($_REQUEST['_session'])) {
    if ($MSO->data['session']['session_id'] != $_REQUEST['_session']) {
        $res = array('error' => 'Истекла сессия пользователя!');
        json_response($res);
        die;
    }
    if (!touch(getinfo('uploads_dir') . $folder . '/' . $MSO->data['session']['session_id'] . '.sessid')) {
        $res = array('error' => 'Не получилось обновить время маркера сессии!');
        // На данный момент в плагине можно игнорировать.
        json_response($res);
        die;
    }
    $res = array('success' => true);
    //require( getinfo('plugins_dir').basename(dirname(__FILE__)).'clean.php' ); # чистка мусора
}
json_response($res);
die;
function json_response($resp)
{
    header('Content-type: application/json');
    header('Pragma: no-cache');
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Content-Disposition: inline; filename="attach.json"');
    header('X-Content-Type-Options: nosniff');
    // Prevent Internet Explorer from MIME-sniffing the content-type:
    echo json_encode($resp);
}
# End file
<?php

if (!defined('SH_API_DIR')) {
    exit;
}
$app->get('/posts', function () use($app) {
    $postsObj = new Models\Posts();
    $posts = $postsObj->getAll();
    json_response($posts);
});
示例#19
0
function trigger_json_response($code, $message)
{
    $error = array("code" => $code, "message" => $message);
    $response = json_encode($error, JSON_PRETTY_PRINT);
    json_response($response);
}
示例#20
0
 /**
  * json 成功 响应
  *
  * @param $return
  */
 function json_success($return)
 {
     json_response($return);
 }
示例#21
0
    if ((int) $test[test][fvonly] == 0) {
        $repeatView = array();
        ksort($breakdownRv);
        foreach ($breakdownRv as $domain => $data) {
            $entry = array();
            $entry['domain'] = $domain;
            $entry['bytes'] = $data['bytes'];
            $entry['requests'] = $data['requests'];
            $entry['connections'] = $data['connections'];
            $repeatView[] = $entry;
        }
        $domains['repeatView'] = $repeatView;
    }
    $output = array();
    $output['domains'] = $domains;
    json_response($output);
    exit;
}
?>


<!DOCTYPE html>
<html>
    <head>
        <title>WebPagetest Domain Breakdown<?php 
echo $testLabel;
?>
</title>
        <?php 
$gaTemplate = 'Domain Breakdown';
include 'head.inc';
示例#22
0
function OT_get_google_fonts($sort = "alpha")
{
    $font_list = get_option(THEME_NAME . "_google_font_list");
    $font_list_time = get_option(THEME_NAME . "_google_font_list_update");
    $now = time();
    $interval = 41600;
    if ($font_list) {
        $font_list = $font_list;
    } else {
        if (!$font_list || $now - $font_list_time > $interval) {
            $url = "https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyCpatq_HIaUbw1XUxVAellP4M1Uoa6oibU&sort=" . $sort;
            $result = json_response($url);
            if ($result != false) {
                $font_list = array();
                foreach ($result->items as $font) {
                    $font_list[] .= $font->family;
                }
                update_option(THEME_NAME . "_google_font_list", $font_list);
                update_option(THEME_NAME . "_google_font_list_update", time());
            } else {
                $font_list = false;
            }
        } else {
            $font_list = false;
        }
    }
    return $font_list;
}
示例#23
0
                RestoreTest($test);
                $result['data'][$test] = -1;
                $histogram = GetLastFrameHistogram($test, $run);
                if (isset($histogram)) {
                    if (isset($baseline)) {
                        $result['data'][$test] = CompareHistograms($histogram, $baseline);
                    } else {
                        $result['data'][$test] = 100;
                        $baseline = $histogram;
                    }
                }
            }
        }
    }
}
json_response($result);
function GetLastFrameHistogram($test, $run)
{
    $histogram = null;
    $videoPath = './' . GetTestPath($test) . "/video_{$run}";
    $files = glob("{$videoPath}/*.jpg");
    if ($files) {
        rsort($files);
        $lastFrame = $files[0];
        $histogram = GetImageHistogram($lastFrame);
    }
    return $histogram;
}
// Run a comparison similar to the Speed Index histograms but including all absolute differences
function CompareHistograms($hist1, $hist2)
{
示例#24
0
function error_response($errno, $msg)
{
    json_response(array('exception' => array('errmsg' => $errno . ": " . $msg)));
}
<?php

function json_response($code = 200, $data = null)
{
    $status = array(200 => '200 OK', 400 => '400 Bad Request', 500 => '500 Internal Server Error');
    // clear the old headers
    header_remove();
    // set the header to make sure cache is forced
    header("Cache-Control: no-transform,public,max-age=300,s-maxage=900");
    // treat this as json
    header('Content-Type: application/json');
    // ok, validation error, or failure
    header('Status: ' . $status[$code]);
    // return the encoded json
    return json_encode(array('status' => $code < 300, 'data' => $data));
}
// usage
echo json_response(200, [$_POST, $_FILES]);
exit;
示例#26
0
文件: Users.php 项目: ishawge/cxpcms
 function set_perms()
 {
     if (strtoupper($_SERVER['REQUEST_METHOD']) === 'POST') {
         foreach ($_POST as $k => $v) {
             if (substr($k, 0, 5) == "perm_") {
                 $permID = str_replace("perm_", "", $k);
                 if ($v == 'x') {
                     $strSQL = "DELETE FROM `user_perms` WHERE `userID` = ? AND `permID` = ?";
                     $this->db->query($strSQL, array($_POST['user_id'], floatval($permID)));
                 } else {
                     $strSQL = "REPLACE INTO `user_perms` SET `userID` = ?, `permID` = ?, `value` = ?";
                     $this->db->query($strSQL, array($_POST['user_id'], floatval($permID), $v));
                 }
             }
         }
         cxp_update_cache();
         json_response(array('success' => TRUE, 'msg' => 'change user permission success'));
     } else {
         $user_id = intval($this->input->get('user_id'));
         $this->db->where('id', $user_id);
         $info = $this->db->get('users')->row();
         $this->template_data['info'] = $info;
         $this->template_data['user_id'] = $user_id;
         $this->load->view('set_perms', $this->template_data);
     }
 }
示例#27
0
 function check_permission($permKey, $json = TRUE)
 {
     $CI =& get_instance();
     $user = $CI->load->get_var('user');
     $perms = $user->userPerms;
     if (isset($perms[$permKey]) && $perms[$permKey]) {
     } else {
         if ($json) {
             json_response(array('success' => FALSE, 'msg' => 'You do not have permission to operate:' . $permKey));
         } else {
             // set_status_header(500);
             $data['errorString'] = '500';
             $content = $CI->load->view($CI->admin_theme . 'member/500', $data, TRUE);
             $CI->output->set_output($content);
             $CI->output->_display();
             exit;
         }
     }
 }
 /**
  * Delete an existing preset
  */
 public function deletePreset()
 {
     $image_id = esc_html($_POST['image_id']);
     $size = esc_html($_POST['size']);
     $key = esc_html($_POST['key']);
     if (empty($key)) {
         json_response(['status' => 'error', 'error' => 'Seems that you may have forgotten something.']);
     }
     $presets = get_option('ilab-imgix-presets');
     if ($presets) {
         unset($presets[$key]);
         update_option('ilab-imgix-presets', $presets);
     }
     $sizePresets = get_option('ilab-imgix-size-presets');
     if (!$sizePresets) {
         $sizePresets = [];
     }
     foreach ($sizePresets as $size => $preset) {
         if ($preset == $key) {
             unset($sizePresets[$size]);
             break;
         }
     }
     update_option('ilab-imgix-size-presets', $sizePresets);
     return $this->displayEditUI(1);
 }
示例#29
0
         $ret['data']['testId'] = $test['id'];
         $ret['data']['ownerKey'] = $test['owner'];
         $ret['data']['jsonUrl'] = "{$protocol}://{$host}{$uri}/results.php?test={$test['id']}&f=json";
         if (FRIENDLY_URLS) {
             $ret['data']['xmlUrl'] = "{$protocol}://{$host}{$uri}/xmlResult/{$test['id']}/";
             $ret['data']['userUrl'] = "{$protocol}://{$host}{$uri}/result/{$test['id']}/";
             $ret['data']['summaryCSV'] = "{$protocol}://{$host}{$uri}/result/{$test['id']}/page_data.csv";
             $ret['data']['detailCSV'] = "{$protocol}://{$host}{$uri}/result/{$test['id']}/requests.csv";
         } else {
             $ret['data']['xmlUrl'] = "{$protocol}://{$host}{$uri}/xmlResult.php?test={$test['id']}";
             $ret['data']['userUrl'] = "{$protocol}://{$host}{$uri}/results.php?test={$test['id']}";
             $ret['data']['summaryCSV'] = "{$protocol}://{$host}{$uri}/csv.php?test={$test['id']}";
             $ret['data']['detailCSV'] = "{$protocol}://{$host}{$uri}/csv.php?test={$test['id']}&amp;requests=1";
         }
         $ret['data']['jsonUrl'] = "{$protocol}://{$host}{$uri}/jsonResult.php?test={$test['id']}";
         json_response($ret);
     } else {
         if (count($spofTests) > 1) {
             header("Location: {$protocol}://{$host}{$uri}/video/compare.php?tests=" . implode(',', $spofTests));
         } else {
             // redirect regardless if it is a bulk test or not
             if (FRIENDLY_URLS) {
                 header("Location: {$protocol}://{$host}{$uri}/result/{$test['id']}/");
             } else {
                 header("Location: {$protocol}://{$host}{$uri}/results.php?test={$test['id']}");
             }
         }
     }
 } else {
     if ($xml) {
         header('Content-type: text/xml');
<?php

/*!
 * simple json response
 * @param  integer $code    HTTP Status Code
 * @param  mixed   $message The message to send
 * @return string           JSON encoded string
 */
function json_response($code = 200, $message = null)
{
    // clear the old headers
    header_remove();
    // set the header to make sure cache is forced
    header("Cache-Control: no-transform,public,max-age=300,s-maxage=900");
    // treat this as json
    header('Content-Type: application/json');
    $status = array(200 => '200 OK', 400 => '400 Bad Request', 500 => '500 Internal Server Error');
    // ok, validation error, or failure
    header('Status: ' . $status[$code]);
    // return the encoded json
    return json_encode(array('status' => $code < 300, 'message' => $message));
}
// this function is very simple
// it just uploads a single file with a timestamp prepended
$target_dir = "uploads/";
$target_file = $target_dir . time() . basename($_FILES["file"]["name"]);
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
    echo json_response(200, "The file " . basename($_FILES["file"]["name"]) . " has been uploaded.");
} else {
    echo json_response(500, "Sorry, there was an error uploading your file.");
}