function iVolunteer_buildSidebar(&$buf) { $rc = 1; // Reset to 0 on success // Get the iVolunteer local events list -- returned as XML if (($response = iVolunteer_cURL()) == FALSE) { // This can happen when the site is found, but the API is down // -- just exit printf("No opportunities found -- please try later.<br />"); } elseif (strpos($response, "Not Found")) { // This can happen when the site is NOT found -- just exit printf("No opportunities found - please try later.<br />"); } else { // Instantiate JSON object $json_iVolunteer = new Moxiecode_JSON(); // Decode the returned JSON if (($consolidated = $json_iVolunteer->decode($response)) == 0) { // No data came back printf("No opportunities found, please try later.<br />"); } else { // Parse JSON and load sidebar buf parse_json($consolidated, $buf); $rc = 0; } // NULL the object $json_iVolunteer = 0; } return $rc; }
function parse_json($arr, &$result, $params) { $jarr = json_decode($arr, true); foreach ($jarr as $str => $val) { if (is_array($val)) { parse_json(json_encode($val), $result, $params); } else { foreach ($params as $key => $method) { if ($str == $key) { if (isset($val)) { if (isset($result[$key][$val])) { if ($method == 'count') { $result[$key][$val] = $result[$key][$val] + 1; } elseif ($method == 'sum') { // sum echo $val . '<br>'; $result[$key][$val] = $result[$key][$val] + $val; } else { // here average } } else { if ($method == 'count') { $result[$key][$val] = 1; } elseif ($method == 'sum') { $result[$key][$val] = 0; } else { // here average $result[$val] = 0; } } } } } } } }
public function SaveFacebook() { $item = FormUtils::form2dbhash($_REQUEST, 'access_token id email first_name last_name name username gender link locale timezone verified'); #TODO better validate if (!$item['access_token'] || !$item['id']) { throw new ApplicationException("Wrong facebook data", 1); } /* $fb = new Facebook(array( 'appId' => $GLOBALS['FACEBOOK_APP_ID'], 'secret' => $GLOBALS['FACEBOOK_APP_SECRET'], )); $fb_user_id = $facebook->getUser(); $user_profile = $facebook->api('/me'); */ #check if such user exists $users_id = 0; #first - check by email $hU = $this->model->one_by_email($item['email']); if ($hU['id']) { $users_id = $hU['id']; } if (!$users_id) { #now check by facebook email $hU = db_row("select * from users where fb_email=" . dbq($item['email'])); if ($hU['id']) { $users_id = $hU['id']; } } if (!$users_id) { #now check by facebook id $hU = db_row("select * from users where fb_id=" . dbq($item['id'])); if ($hU['id']) { $users_id = $hU['id']; } } if ($users_id) { #update user's missing data from facebook $vars = array('fb_access_token' => $item['access_token']); if ($hU['sex'] != ($item['gender'] == 'male' ? 1 : 0)) { $vars['sex'] = $item['gender'] == 'male' ? 1 : 0; } if (!$hU['fname']) { $vars['fname'] = $item['first_name']; } if (!$hU['lname']) { $vars['lname'] = $item['last_name']; } if ($hU['fb_email'] != $item['email'] && $item['email']) { $vars['fb_email'] = $item['email']; } if (!$hU['fb_id']) { $vars['fb_id'] = $item['id']; } if (!$hU['fb_link']) { $vars['fb_link'] = $item['link']; } if (!$hU['fb_locale']) { $vars['fb_locale'] = $item['locale']; } if (!$hU['fb_name']) { $vars['fb_name'] = $item['name']; } if (!$hU['fb_timezone']) { $vars['fb_timezone'] = $item['timezone']; } if (!$hU['fb_username']) { $vars['fb_username'] = $item['username']; } if (!$hU['fb_verified']) { $vars['fb_verified'] = $item['verified'] == 'true' ? 1 : 0; } if (!$hU['fb_picture_url']) { $vars['fb_picture_url'] = 'http://graph.facebook.com/' . $item['username'] . '/picture'; } db_update('users', $vars, $users_id); } else { #register user first if new $users_id = $this->model->add(array('email' => $item['email'], 'nick' => $item['name'], 'sex' => $item['gender'] == 'male' ? 1 : 0, 'fname' => $item['first_name'], 'lname' => $item['last_name'], 'fb_id' => $item['id'], 'fb_link' => $item['link'], 'fb_locale' => $item['locale'], 'fb_name' => $item['name'], 'fb_timezone' => $item['timezone'], 'fb_username' => $item['username'], 'fb_verified' => $item['verified'] == 'true' ? 1 : 0, 'fb_picture_url' => 'http://graph.facebook.com/' . $item['username'] . '/picture', 'fb_access_token' => $item['access_token'])); } #automatically login the user $_SESSION['is_just_registered'] = 1; $this->model->do_login($users_id); $ps = array('status' => 0, 'err_msg' => ''); parse_json($ps); }
require CLIENT_PATH . 'includes/lib_struct.php'; // 结构库文件 // json类文件 require ROOT_PATH . 'includes/cls_json.php'; /* 对用户传入的变量进行转义操作。*/ if (!get_magic_quotes_gpc()) { $_COOKIE = addslashes_deep($_COOKIE); } /* 兼容ECShopV2.5.1版本 */ if (!defined('EC_CHARSET')) { define('EC_CHARSET', 'utf-8'); } /* 初始化JSON对象 */ $json = new JSON(); /* 分析JSON数据 */ parse_json($json, $_POST['Json']); /* 初始化包含文件 */ require ROOT_PATH . 'includes/inc_constant.php'; require ROOT_PATH . 'includes/cls_ecshop.php'; require ROOT_PATH . 'includes/lib_time.php'; require ROOT_PATH . 'includes/lib_main.php'; require ROOT_PATH . 'includes/lib_insert.php'; require ROOT_PATH . 'includes/lib_goods.php'; /* 创建 ECSHOP 对象 */ $ecs = new ECS($db_name, $prefix); /* 初始化数据库类 */ $db = new cls_mysql($db_host, $db_user, $db_pass, $db_name); $db->set_disable_cache_tables(array($ecs->table('sessions'), $ecs->table('sessions_data'), $ecs->table('cart'))); $db_host = $db_user = $db_pass = $db_name = null; /* 载入系统参数 */ $_CFG = load_config();
include_once '/home/minecraft/server/bin/websend.php'; $feed_url = "http://search.twitter.com/search.json?q=from:uncoveryme&rpp=1&include_entities=true"; function parse_json($feed) { $out = json_decode($feed, true); if (!isset($out['results'][0])) { var_dump($out); } $result = $out['results'][0]; $text = $result['text']; var_dump($out); if (isset($result['entities']['urls'][0])) { $urls = $result['entities']['urls'][0]; $good_url = $urls['expanded_url']; $bad_url = $urls['url']; $text = str_replace($bad_url, $good_url, $text); } return $text; } $tweet = parse_json(file_get_contents($feed_url)); $last_tweet_file = "/home/minecraft/server/bin/tweet/last-tweet.txt"; if (file_exists($last_tweet_file) && file_get_contents($last_tweet_file) == $tweet) { //echo "No change."; } else { $fh = fopen($last_tweet_file, "w") or die("Cannot open file!"); fwrite($fh, $tweet); fclose($fh); $command = "chsay announce {$tweet} ;"; //umc_exec_command($command); }
$query3 = mysqli_query($connect, "SELECT * FROM temperate_weight_" . $user . " "); $query4 = mysqli_query($connect, "SELECT * FROM temperate_height_" . $user . " "); $query5 = mysqli_fetch_array($query3); $query6 = mysqli_fetch_array($query4); $_SESSION['auth_pin'] = $user; include 'pages/profile/index.html'; } } } } session_unset('auth_pin'); } if ($var[0] == "login") { if (isset($_SESSION['temperate_uid'])) { header("Location: ./"); } else { if (isset($_POST['username']) && isset($_POST['password'])) { login($connect, $_POST['username'], sha1($_POST['password'])); } else { include "pages/login/index.html"; } } exit; } if ($var[0] == "jsonparse") { parse_json($connect, $_POST['json']); } if ($var[0] == "logout") { session_destroy(); header("Location: ./login"); }
public static function fromJson($json) { $obj = parse_json($json); if (isset($obj->where)) { $obj->where = (array) $obj->where; } if ($obj) { return copy_new($obj, "Clips\\Pagination"); } return null; }
public function setUp() { $mute = getenv('MUTE_PHPUNIT'); $ref = new \ReflectionClass($this); $func = $this->getName(); if (!$mute && $func != 'testStub') { echo "\n----------" . $ref->name . " | " . $func . "----------\n"; } $this->tool =& get_clips_tool(); $this->tool->helper('fake'); $this->clips = new Engine(); $re = new \Addendum\ReflectionAnnotatedClass($this); foreach (array($re, $re->getMethod($func)) as $m) { foreach ($m->getAnnotations() as $a) { switch (get_class($a)) { case "Clips\\Rules": // We need to load the rules before test execution $this->clips->clear(); // We should clear the clips every time $rules = get_default($a, 'rules', array()); $templates = get_default($a, 'templates', array()); // Load the templates foreach ($templates as $t) { $this->clips->template($t); } // Load the rules foreach ($rules as $r) { $this->clips->load($r); } break; case "Clips\\FakeModel": $ds = $this->tool->library('dataSource'); $fake = $this->tool->library('fakeDataSource'); $ds->fake = $fake; if (valid_obj($this, 'Clips\\Interfaces\\FakeDataSourceHandler')) { $fake->handler = $this; } else { if (!$a->value) { $a->value = 'expectFakeDataSourceHandler'; } $fake->handler = $this->tool->library($a->value); $this->fake_handler = $fake->handler; } $ds->_datasources = array('fake'); break; case "Clips\\TestData": case "Clips\\DataGenerator": $this->data = $this->tool->enhance($a); break; case "Clips\\TestValue": if (isset($a->json)) { $a->file = $a->json; } if (isset($a->file)) { $test_config_dir = clips_config('test_data_dir'); if (!$test_config_dir) { $test_config_dir = clips_config('test_dir'); $test_config_dir = path_join($test_config_dir[0], 'data'); } else { $test_config_dir = $test_config_dir[0]; } $p = path_join($test_config_dir, $a->file); if (\file_exists($p)) { $this->value = \file_get_contents($p); if (isset($a->json)) { $this->value = parse_json($this->value); } } } else { if (isset($a->context)) { $this->value = clips_context($a->context); } else { if (isset($a->value)) { $this->value = $a->value; } } } break; default: $this->tool->annotationEnhance($a, $this); } } } $this->doSetUp(); }
public function parser() { global $CONFIG; $args = func_get_args(); $basedir = ''; $controller = $this->route['controller']; if ($this->route['prefix']) { $basedir .= '/' . $this->route['prefix']; $controller = preg_replace('/^' . preg_quote($this->route['prefix']) . '/i', '', $controller); } $basedir .= '/' . $controller . '/' . $this->route['action']; $basedir = strtolower($basedir); $layout = $this->page_layout; $ps = array(); $out_filename = ''; if (!count($args)) { $ps = array(); } elseif (count($args) == 1 && is_array($args[0])) { $ps =& $args[0]; } elseif (count($args) == 2 && is_string($args[0]) && is_array($args[1])) { $basedir =& $args[0]; $ps =& $args[1]; } elseif (count($args) >= 3 && is_string($args[0]) && is_string($args[1]) && is_array($args[2])) { $basedir =& $args[0]; $layout =& $args[1]; $ps =& $args[2]; if (count($args) == 4) { $out_filename =& $args[3]; } } else { throw Exception("parser - wrong call"); } $out_format = $this->get_response_expected_format(); if ($out_format == 'json') { //TODO!!! - output MUST be filtered out (per controller or per method? or just enable/disable json per controller/action and filter in action?) //because hf may contain full data read from db like plain passwords, etc... parse_json($ps, ''); } else { if ($out_format == 'pjax') { $layout = $CONFIG['PAGE_TPL_PJAX']; } if (!array_key_exists('ERR', $ps)) { $ps["ERR"] = $this->G['ERR']; #add errors if any } logger("basedir=[{$basedir}], layout=[{$layout}] to [{$out_filename}]"); return parse_page($basedir, $layout, $ps, $out_filename); } }
/** * The interactive wizzard function, will take the options to run. * * The options is something like this(the generate widget option): * * <code> * { * "header": "Clips Widget Generator v1.0", * "steps": [ * { * "prompt": "The name of the widget:", * "field": "widget", * "rules": { * "minlength": 4, * "maxlength": 10 * } * }, * { * "prompt": "Widget Author:", * "field": "author", * "default": "!Clips\\current_user" * }, * { * "prompt": "Widget Version:", * "default": "1.0", * "field": "version" * }, * { * "prompt": "Widget Doc:", * "field": "doc" * }, * { * "prompt": "The widget configuration is:", * "call": "dump" * }, * { * "prompt": "Are you sure:", * "confirm": true, * "condition": { * "cancel": [{"jump": 0}] * } * } * ] * } * </code> * * Concept in details: * * 1. Step: The interactive step, can be 2 types [step, confirm] * 2. Operation: Only support 2 kind of operations by this version call and jump, for call * operation, will call the method from callback, for jump operation, will jump to the step * it set, like this {"jump":0} * 3. Confirm Step: This step will prompt a question to user, and let the user to choose, * use the condition part to add operation to the interactive console * 4. Field: If step has this settings, will prompt to get the user input using readline, and set * the input as field of the return object. * 5. Default: If no input is there, use this as default value, support method call, like this !time, * do not support arguments for this version */ function interactive($config, $callback = null) { if (is_string($config)) { // This is the config location $conf_dir = clips_config('config_dir'); foreach ($conf_dir as $dir) { $p = try_path(path_join($dir, $config . '.json')); if ($p) { break; } } $config = parse_json(file_get_contents($p)); } $prompt = get_default($config, 'prompt', '$'); if (isset($config->header)) { echo $config->header . "\n"; } $tool =& get_clips_tool(); $ret = array(); $validator = new Validator(); for ($i = 0; $i < count($config->steps); $i++) { $step = $config->steps[$i]; $operations = array(); $default = null; if (isset($step->field)) { if (isset($step->default)) { $default = $step->default; if (strpos($default, '!') === 0) { $default = call_user_func('\\' . str_replace('!', '', $default)); } } if (isset($step->prompt)) { $field = readline($step->prompt . (isset($default) ? ' (' . $default . ') ' : ' ')); } else { $field = readline($prompt . isset($default) ? ' (' . $default . ') ' : ' '); } if (!$field) { if (isset($default)) { $field = $default; } } if (isset($step->rules)) { // TODO Add the validation } $ret[$step->field] = $field; } else { if (isset($step->confirm)) { // This is the confirm step if (isset($step->confirm->options)) { $options = $step->confirm->options; } else { $options = array('yes', 'no'); } if (isset($step->prompt)) { $confirm = readline($step->prompt . ' [' . implode(', ', $options) . ']' . ' '); } else { $confirm = readline($prompt . ' '); } if (!is_array($step->confirm)) { $result_array = array('', 'y', 'Y', 'yes', 'Yes'); } else { $result_array = $step->confirm; } if (array_search($confirm, $result_array) !== false) { $condition = 'confirm'; } else { $condition = 'cancel'; } if (isset($step->condition)) { if (isset($step->condition->{$condition})) { $operations = array_merge($operations, $step->condition->{$condition}); } } } else { echo $step->prompt . "\n"; // Just print the prompt } } if (isset($step->jump)) { $operations[] = (object) array('jump' => $step->jump); } if (isset($step->call)) { $operations[] = (object) array('call' => $step->call); } if ($operations) { foreach ($operations as $operation) { if (isset($operation->jump)) { $i = $operation->jump - 1; } if ($callback && isset($operation->call)) { \call_user_func_array(array($callback, $operation->call), array($ret)); } } } } return (object) $ret; }