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 json_decode($input) { $json = new Moxiecode_JSON(); return $json->decode($input); }
$socket = fsockopen($url['host'], intval($url['port']), $errno, $errstr, 30); if ($socket) { // Send request headers fputs($socket, $req); // Read response headers and data $resp = ""; while (!feof($socket)) { $resp .= fgets($socket, 4096); } fclose($socket); // Split response header/data $resp = explode("\r\n\r\n", $resp); echo $resp[1]; // Output body } die; } // Get JSON data $json = new Moxiecode_JSON(); $input = $json->decode($raw); // Execute RPC if (isset($config['general.engine'])) { $spellchecker = new $config['general.engine']($config); $result = call_user_func_array(array($spellchecker, $input['method']), $input['params']); } else { die('{"result":null,"id":null,"error":{"errstr":"You must choose an spellchecker engine in the config.php file.","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}'); } // Request and response id should always be the same $output = array("id" => $input->id, "result" => $result, "error" => null); // Return JSON encoded string echo $json->encode($output);
/** * Backwards compatible json_decode. * * @param string $data * @param bool $assoc Decode objects as associative arrays. * @return mixed */ function json_decode($data, $assoc = false) { if (function_exists('json_decode')) { return json_decode($data, $assoc); } if (class_exists('Services_JSON')) { $flag = $assoc ? SERVICES_JSON_LOOSE_TYPE : 0; $json = new Services_JSON($flag); return $json->decode($data); } elseif (class_exists('Moxiecode_JSON')) { $json = new Moxiecode_JSON(); return $json->decode($data); } else { trigger_error('No JSON parser available', E_USER_ERROR); return null; } }
/** * Encode JSON objects * * A wrapper for JSON encode methods. Pass in the PHP array and get a string * in return that is formatted as JSON. * * @param $obj - the array to be encoded * * @return string that is formatted as JSON */ public function json_decode($obj) { // Try to use native PHP 5.2+ json_encode // Switch back to JSON library included with Tiny MCE if (function_exists('json_decode')) { return @json_decode($obj); } else { require_once ABSPATH . "/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php"; $json_obj = new Moxiecode_JSON(); $json = $json_obj->decode($obj); return $json; } }
function load_json_file($json_file, $theme_name, $context = '') { $json_error = false; // check that config.json exists if (file_exists($json_file)) { // attempt to read config.json if (!($read_file = fopen($json_file, 'r'))) { $this->log(wp_kses(__('Read json error', 'tvr-microthemer'), array()), '<p>' . sprintf(wp_kses(__('WordPress was not able to read %s. ', 'tvr-microthemer'), array()), $this->root_rel($json_file)) . '. ' . $this->permissionshelp . '</p>'); } else { // get the data $data = fread($read_file, filesize($json_file)); fclose($read_file); } // tap into WordPress native JSON functions if (!class_exists('Moxiecode_JSON')) { require_once $this->thisplugindir . 'includes/class-json.php'; } $json_object = new Moxiecode_JSON(); // convert to array if (!($json_array = $json_object->decode($data))) { $this->log('', '', 'error', 'json-decode', array('json_file', $json_file)); $json_error = true; } // Unitless css values may need to be auto-adjusted $filtered_json = $this->filter_json_css_units($json_array); // do for each MQ too if (!empty($filtered_json['non_section']['m_query']) and is_array($filtered_json['non_section']['m_query'])) { foreach ($filtered_json['non_section']['m_query'] as $m_key => $array) { $filtered_json['non_section']['m_query'][$m_key] = $this->filter_json_css_units($array); } } // check what import method the user specified if ($context == 'Overwrite' or empty($context)) { // attempt to decode json into an array if (!($this->options = $filtered_json)) { $this->log('', '', 'error', 'json-decode', array('json_file', $json_file)); $json_error = true; } } elseif ($context == 'Merge') { // attempt to decode json into an array if (!($this->to_be_merged = $filtered_json)) { $this->log('', '', 'error', 'json-decode', array('json_file', $json_file)); $json_error = true; } else { $this->options = $this->merge($this->options, $this->to_be_merged); } } // json decode was successful if (!$json_error) { $this->log(wp_kses(__('Settings were imported', 'tvr-microthemer'), array()), '<p>' . wp_kses(__('The design pack settings were successfully imported.', 'tvr-microthemer'), array()) . '</p>', 'notice'); // check for new mqs $pref_array['m_queries'] = $this->preferences['m_queries']; // check for new media queries in the import $mq_analysis = $this->analyse_mqs($this->options['non_section']['active_queries'], $pref_array['m_queries']); if ($mq_analysis['new']) { // merge the new queries $pref_array['m_queries'] = array_merge($pref_array['m_queries'], $mq_analysis['new']); $this->log(wp_kses(__('Media queries added', 'tvr-microthemer'), array()), '<p>' . wp_kses(__('The design pack you imported contained media queries that are different from the ones used in your current setup. In order for the design pack settings to function correctly, these additional media queries have been imported into your workspace.', 'tvr-microthemer'), array()) . '</p> <p>' . sprintf(wp_kses(__('Please <span %s>review (and possibly rename) the imported media queries</span>. Note: imported queries are marked with "(imp)", which you can remove from the label name once you\'ve reviewed them.', 'tvr-microthemer'), array('span' => array())), 'class="link show-dialog" rel="edit-media-queries"') . ' </p>', 'warning'); } if ($this->debug_merge) { $debug_file = $this->micro_root_dir . $this->preferences['theme_in_focus'] . '/debug-merge-post.txt'; $write_file = fopen($debug_file, 'w'); $data = ''; $data .= "\n\nThe merged and MQ replaced options\n\n"; $data .= print_r($this->options, true); fwrite($write_file, $data); fclose($write_file); } // save settings in db $this->saveUiOptions($this->options); // update active-styles.css $this->update_active_styles($theme_name, $context); // pass the context so the function doesn't update theme_in_focus // Only update theme_in_focus if it's not a merge if ($context != 'Merge') { $pref_array['theme_in_focus'] = $theme_name; } // update the preferences if not merge or media queries need importing if ($context != 'Merge' or $mq_analysis['new']) { $this->savePreferences($pref_array); } } } else { $this->log(wp_kses(__('Config file missing', 'tvr-microthemer'), array()), '<p>' . sprintf(wp_kses(__('%1$s settings file could not be loaded because it doesn\'t exist in %2$s', 'tvr-microthemer'), array()), $this->root_rel($json_file), '<i>' . $this->readable_name($theme_name) . '</i>.') . '</p>'); } }
function json_decode($str) { $json = new Moxiecode_JSON(); return $json->decode($str); }
function doApiRequest($action, $params, $method = 'POST') { $this->success = false; $url = "{$this->protocol}://{$this->base_url}/{$action}"; if ($method == 'GET' && count($params) > 0) { $url .= "?" . http_build_query($params); } $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, ""); curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}:{$this->key}"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); switch (strtoupper($method)) { case 'POST': curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); break; case 'DELETE': curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); break; case 'PUT': curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); //curl_setopt ($ch, CURLOPT_HTTPHEADER, array ("Content-Type: application/x-www-form-urlencoded\n")); break; } //curl_setopt($ch, CURLOPT_CAINFO, "cacert.pem"); $raw = curl_exec($ch); if ($raw === false) { return false; } //throw new Exception(curl_error($ch), null); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if (function_exists('json_decode')) { $response = json_decode($raw, true); } else { if (class_exists("Moxiecode_JSON")) { $json = new Moxiecode_JSON(); $response = $json->decode($raw); } else { die("DPD Cart API error: No JSON parser is available"); } } if ($http_code != '200') { return false; } $this->success = true; return $response; }