function main() { $program_start_time = microtime(true); $arguments = validate_arguments($_GET, array('platform' => 'int', 'metric' => 'int', 'testGroup' => 'int?', 'startTime' => 'int?', 'endTime' => 'int?')); $platform_id = $arguments['platform']; $metric_id = $arguments['metric']; $start_time = $arguments['startTime']; $end_time = $arguments['endTime']; if (!!$start_time != !!$end_time) { exit_with_error('InvalidTimeRange', array('startTime' => $start_time, 'endTime' => $end_time)); } $db = new Database(); if (!$db->connect()) { exit_with_error('DatabaseConnectionFailure'); } $fetcher = new MeasurementSetFetcher($db); if (!$fetcher->fetch_config_list($platform_id, $metric_id)) { exit_with_error('ConfigurationNotFound', array('platform' => $platform_id, 'metric' => $metric_id)); } $cluster_count = 0; while (!$fetcher->at_end()) { $content = $fetcher->fetch_next_cluster(); $cluster_count++; if ($fetcher->at_end()) { $cache_filename = "measurement-set-{$platform_id}-{$metric_id}.json"; $content['clusterCount'] = $cluster_count; $content['elapsedTime'] = (microtime(true) - $program_start_time) * 1000; } else { $cache_filename = "measurement-set-{$platform_id}-{$metric_id}-{$content['endTime']}.json"; } $json = success_json($content); generate_data_file($cache_filename, $json); } echo $json; }
function main($path) { if (count($path) != 1) { exit_with_error('InvalidRequest'); } $parts = explode('-', $path[0]); if (count($parts) != 2) { exit_with_error('InvalidRequest'); } $db = new Database(); if (!$db->connect()) { exit_with_error('DatabaseConnectionFailure'); } $platform_id = intval($parts[0]); $metric_id = intval($parts[1]); $config_rows = $db->query_and_fetch_all('SELECT * FROM test_configurations WHERE config_metric = $1 AND config_platform = $2', array($metric_id, $platform_id)); if (!$config_rows) { exit_with_error('ConfigurationNotFound'); } $test_group_id = array_get($_GET, 'testGroup'); $should_cache = array_get($_GET, 'cache'); if ($test_group_id) { $test_group_id = intval($test_group_id); } else { if ($should_cache) { // Only v1 UI needs caching. $maxage = config('jsonCacheMaxAge'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $maxage) . ' GMT'); header("Cache-Control: maxage={$maxage}"); } } $generator = new RunsGenerator($config_rows); foreach ($config_rows as $config) { if ($test_group_id) { $raw_runs = fetch_runs_for_config_and_test_group($db, $config, $test_group_id); } else { $raw_runs = fetch_runs_for_config($db, $config); } $generator->add_runs($config['config_type'], $raw_runs); } $content = success_json($generator->results()); if (!$test_group_id) { generate_data_file("{$platform_id}-{$metric_id}.json", $content); } echo $content; }
function main() { $program_start_time = microtime(true); $arguments = validate_arguments($_GET, array('platform' => 'int?', 'metric' => 'int?', 'analysisTask' => 'int?')); $platform_id = $arguments['platform']; $metric_id = $arguments['metric']; $task_id = $arguments['analysisTask']; if (!($platform_id && $metric_id && !$task_id || $task_id && !$platform_id && !$metric_id)) { exit_with_error('AmbiguousRequest'); } $db = new Database(); if (!$db->connect()) { exit_with_error('DatabaseConnectionFailure'); } if ($task_id) { $fetcher = new AnalysisResultsFetcher($db, $task_id); exit_with_success($fetcher->fetch()); } $fetcher = new MeasurementSetFetcher($db); if (!$fetcher->fetch_config_list($platform_id, $metric_id)) { exit_with_error('ConfigurationNotFound', array('platform' => $platform_id, 'metric' => $metric_id)); } if ($fetcher->at_end()) { header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); exit(404); } $cluster_count = 0; while (!$fetcher->at_end()) { $content = $fetcher->fetch_next_cluster(); $cluster_count++; if ($fetcher->at_end()) { $cache_filename = "measurement-set-{$platform_id}-{$metric_id}.json"; $content['clusterCount'] = $cluster_count; $content['elapsedTime'] = (microtime(true) - $program_start_time) * 1000; } else { $cache_filename = "measurement-set-{$platform_id}-{$metric_id}-{$content['endTime']}.json"; } $json = success_json($content); generate_data_file($cache_filename, $json); } echo $json; }
* @author Shahriar * @version 1.0.1 */ $data = json_decode(file_get_contents("php://input")); if (!$data) { die; } $sub = mysql_real_escape_string($data->sub); if ($sub == 'addDoa') { // Add New Doa $args = array('doa_name' => $data->doaName, 'doa_details' => $data->doaDet, 'doa_lang' => $data->doaLang, 'doa_type' => $data->doaType); $chk = insert_data('q_doa', $args); if ($chk) { echo success_json(); } else { echo err_json(); } } elseif ($sub == 'getDoa') { // Get all Doa list print_r(table_data('q_doa', '1', 'doa_id,doa_name,doa_type,doa_lang')); } elseif ($sub == 'delDoa') { // Delete Doa $chk = delete_data('q_Doa', "doa_id='{$data->doaID}'"); if ($chk) { success_json(); } else { echo err_json(); } } else { echo err_json(); }
*/ $data = json_decode(file_get_contents("php://input")); if (!$data) { die; } $sub = mysql_real_escape_string($data->sub); if ($sub == 'addName') { // Add New Name $args = array('name_details' => $data->nameName, 'name_lang' => $data->nameLang); $chk = insert_data('q_allah_name', $args); if ($chk) { echo success_json(); } else { echo err_json(); } } else { if ($sub == 'getName') { // Get All Names print_r(table_data('q_allah_name')); } else { if ($sub == 'delName') { // Delete Name $chk = delete_data('q_allah_name', "name_id='" . $data->nameID . "'"); if ($chk) { echo success_json(); } else { echo err_json(); } } } }
/** * User login function * @param object */ function login_user($data) { $chk = sql_data("users", "email='" . $data->email . "' and password='******'"); if ($chk) { $_SESSION['logged'] = 1; $_SESSION['name'] = $chk['username']; $_SESSION['uid'] = $chk['id']; echo success_json('Success!'); } }
<?php $data = json_decode(file_get_contents("php://input")); if (!$data) { die; } $auth = mysql_real_escape_string($data->auth); if (isset($auth) && $auth == 'true') { echo success_json('Registration successful.'); } else { echo err_json('Registration failed!'); }
} if ($_GET['type'] == 'bwlist') { $dbh = $settings->getDatabase(); $statement = $dbh->prepare("SELECT * FROM bwlist;"); $statement->execute(); success_json($statement->fetchAll(PDO::FETCH_OBJ)); } if ($_GET['type'] == 'spamsettings') { $dbh = $settings->getDatabase(); $statement = $dbh->prepare("SELECT * FROM spamsettings;"); $statement->execute(); $result = array_map(function ($r) { $r['settings'] = json_decode($r['settings']); return $r; }, $statement->fetchAll(PDO::FETCH_ASSOC)); success_json($result); } panic('Unsupported API call'); function panic($message) { http_response_code(503); header('Content-Type: application/json; charset=UTF-8'); die(json_encode(array('error' => $message))); } function success_json($data) { header('Content-Type: application/json; charset=UTF-8'); die(json_encode($data)); } function success_text($data) {
function exit_with_success($details = array()) { echo success_json($details); exit(0); }
* @author Shahriar * @version 1.0.1 */ $data = json_decode(file_get_contents("php://input")); if (!$data) { die; } $sub = mysql_real_escape_string($data->sub); if ($sub == 'addHadith') { // Add new hadith $args = array('hadith_book' => $data->hadithBook, 'hadith_ref' => $data->hadithRef, 'hadith_details' => $data->hadithDet, 'hadith_lang' => $data->hadithLang, 'hadith_type' => $data->hadithType); $chk = insert_data('q_hadith', $args); if ($chk) { echo success_json('Successfully added!'); } else { echo err_json('Insert failed!'); } } elseif ($sub == 'getHadith') { // Get all hadith list print_r(table_data('q_hadith', '1', 'hadith_id,hadith_book,hadith_ref,hadith_type,hadith_lang')); } elseif ($sub == 'delHadith') { // Delete hadith $chk = delete_data('q_hadith', "hadith_id='" . $data->hadithID . "'"); if ($chk) { echo success_json('Deleted!'); } else { echo err_json('Deletion failed!'); } } else { echo err_json(); }
<?php $data = json_decode(file_get_contents("php://input")); if (!$data) { echo err_json('You are unauthorized!'); die; } $auth = $data->code; if (isset($auth) && $auth == 1) { session_start(); $_SESSION['logged'] = $data->userinfo->id; $_SESSION['hash'] = $data->hash; $_SESSION['type'] = $data->userinfo->type; echo success_json('Login successful.'); } else { if (isset($auth) && $auth == 7) { session_start(); $response = array(); $response['hash'] = $_SESSION['hash']; print_r(json_encode($response)); } else { echo err_json('Login failed!'); } }
if (isset($_POST['post_id'])) { $postId = (int) $_POST['post_id']; $chk = single_post($postId); $uid = (int) $var['uid']; if ($chk) { $json = array(); $json['data'] = json_decode($chk, true); $arr = json_decode($json['data'][0]['post_like']); if (in_array($uid, $arr)) { echo err_json('Already liked!'); } else { array_push($arr, $uid); $args = array('post_like' => json_encode($arr)); $chk = update_data("forum_post", $args, "post_id='{$postId}'"); if ($chk) { echo success_json('Posts liked!'); } else { err_json('Like disabled!'); } } } else { echo err_json('No posts found!'); } } else { err_json('Post ID not found!'); } } else { echo err_json('Please login!'); } // } else {