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; }
/** * callback function for inline note edits */ function rolo_edit_note_callback() { $new_value = $_POST['new_value']; $note_id = $_POST['note_id']; $note_id = substr($note_id, strripos($note_id, "-") + 1); $current_comment = get_comment($note_id, ARRAY_A); $current_comment['comment_content'] = $new_value; wp_update_comment($current_comment); $results = array('is_error' => false, 'error_text' => '', 'html' => $new_value); include_once ABSPATH . 'wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php'; $json = new Moxiecode_JSON(); $results = $json->encode($results); die($results); }
<?php include 'JSON.php'; header('Content-type: application/json'); $files = $_FILES['Filedata']; $json_obj = new Moxiecode_JSON(); /* encode */ $json = $json_obj->encode($files); echo $json;
/** * 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>'); } }
/** * helper function for callback function * @param <type> $new_value * @since 0.1 */ function _rolo_edit_callback_success($new_value) { $results = array('is_error' => false, 'error_text' => '', 'html' => $new_value); include_once ABSPATH . 'wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php'; $json = new Moxiecode_JSON(); $results = $json->encode($results); die($results); }
function return_json($results) { if (isset($_GET['callback'])) { echo addslashes($_GET['callback']) . " ("; } if (function_exists('json_encode')) { echo json_encode($results); } else { // PHP4 version require_once ABSPATH . "wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php"; $json_obj = new Moxiecode_JSON(); echo $json_obj->encode($results); } if (isset($_GET['callback'])) { echo ")"; } }
$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);
require_once "../" . $path; } // Dispatch onAuthenticate event if ($man->isAuthenticated()) { if ($_SERVER["REQUEST_METHOD"] == "GET") { $args = $_GET; // Dispatch event before starting to stream $man->dispatchEvent("onBeforeStream", array($cmd, &$args)); // Check command, do command, stream file. $man->dispatchEvent("onStream", array($cmd, &$args)); // Dispatch event after stream $man->dispatchEvent("onAfterStream", array($cmd, &$args)); } else { if ($_SERVER["REQUEST_METHOD"] == "POST") { $args = array_merge($_POST, $_GET); $json = new Moxiecode_JSON(); // Dispatch event before starting to stream $man->dispatchEvent("onBeforeUpload", array($cmd, &$args)); // Check command, do command, stream file. $result = $man->executeEvent("onUpload", array($cmd, &$args)); $data = $result->toArray(); if (isset($args["chunk"])) { // Output JSON response to multiuploader die('{method:\'' . $method . '\',result:' . $json->encode($data) . ',error:null,id:\'m0\'}'); } else { // Output JSON function echo '<html><body><script type="text/javascript">'; if (isset($args["domain"]) && $args["domain"]) { echo 'document.domain="' . $args["domain"] . '";'; } echo 'parent.handleJSON({method:\'' . $method . '\',result:' . $json->encode($data) . ',error:null,id:\'m0\'});</script></body></html>';
if ($fp) { $raw = ""; while (!feof($fp)) { $raw = fread($fp, 1024); } fclose($fp); } } else { $raw = "" . file_get_contents("php://input"); } } if ($raw == "") { die('{"result":null,"id":null,"error":{"errstr":"Could not get raw post data.","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}'); } // Get JSON data $json = new Moxiecode_JSON(); $input = $json->decode($raw); // Parse prefix and method $chunks = explode('.', $input['method']); $type = $chunks[0]; $input['method'] = $chunks[1]; // Clean up type, only a-z stuff. $type = preg_replace("/[^a-z]/i", "", $type); if ($type == "") { die('{"result":null,"id":null,"error":{"errstr":"No type set.","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}'); } // Include Base and Core and Config. $man = new Moxiecode_ManagerEngine($type); require_once $basepath . "CorePlugin.php"; require_once "../config.php"; $man->dispatchEvent("onPreInit", array($type));
require_once "../" . $path; } // Dispatch onAuthenticate event if ($man->isAuthenticated()) { if ($_SERVER["REQUEST_METHOD"] == "GET") { $args = $_GET; // Dispatch event before starting to stream $man->dispatchEvent("onBeforeStream", array($cmd, &$args)); // Check command, do command, stream file. $man->dispatchEvent("onStream", array($cmd, &$args)); // Dispatch event after stream $man->dispatchEvent("onAfterStream", array($cmd, &$args)); } else { if ($_SERVER["REQUEST_METHOD"] == "POST") { $args = array_merge($_POST, $_GET); $json = new Moxiecode_JSON(); // Dispatch event before starting to stream $man->dispatchEvent("onBeforeUpload", array($cmd, &$args)); // Check command, do command, stream file. $result = $man->executeEvent("onUpload", array($cmd, &$args)); // Flash can't get our nice JSON output, so we need to return something... weird. if (isset($_GET["format"]) && $_GET["format"] == "flash") { if ($result->getRowCount() > 0) { $row = $result->getRow(0); switch ($row["status"]) { case "OK": // No header needed, 200 OK! break; case "DEMO_ERROR": case "ACCESS_ERROR": case "MCACCESS_ERROR":
/** * Creates a JSON string from an array * @param array $array */ function FA_lite_json($array) { if (function_exists('json_encode')) { return json_encode($array); } else { if (file_exists(ABSPATH . '/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php')) { require_once ABSPATH . '/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php'; $json_obj = new Moxiecode_JSON(); return $json_obj->encode($array); } } }
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; }
function modulo_venda_obter_info() { $envio = $_POST['envio']; $pagamento = $_POST['pagamento']; $modulo = array('opcoes-de-envio' => array('PAC' => array('titulo' => 'Encomenda Normal', 'conteudo' => 'o PAC é mais barato que o sedex.<br /> Prazo de entrega: 6 dias úteis. Envio totalmente rastreado.', 'link' => 'http://www.correios.com.br/encomendas/servicos/Pac/default.cfm'), 'Sedex' => array('titulo' => 'Sedex', 'conteudo' => 'Com o Sedex, o tempo médio de entrega é de 48 horas e a encomenda é totalmente rastreável', 'link' => 'http://www.correios.com.br/encomendas/servicos/Sedex/sedex.cfm'), 'Grátis' => array('titulo' => 'Grátis', 'conteudo' => 'O frete está incluído no preço do guia. <br />Prazo de entrega: 6 dias úteis. Envio totalmente rastreado.')), 'opcoes-de-pagamento' => array('Cartão de crédito ou boleto bancário (via pagseguro)' => array('titulo' => 'Pagseguro', 'conteudo' => 'O Pagseguro é um serviço prático e seguro de efetuar pagamentos online. Não é necessário se cadastrar, não tem custo adicional para o comprador e possui as maiorias de formas de pagamento disponíveis no mercado, além de ter o cálculo de frete próprio.', 'link' => 'https://pagseguro.uol.com.br/para_voce/como_funciona.jhtml'), 'Transferência bancária' => array('titulo' => 'Transferência bancária', 'conteudo' => 'Através do Blog você poderá efetuar a compra e o vendedor entrará em contato fornecendo o número da conta. Após o pagamento ser efetuado, a mercadoria é enviada no modo de entrega escolhido. O valor do frete é enviado pelo vendedor'))); $json_obj = new Moxiecode_JSON(); /* encode */ $json = $json_obj->encode($modulo[$pagamento][$envio]); echo $json; die; }
/** * Backwards compatible json_encode. * * @param mixed $data * @return string */ function json_encode($data) { if (function_exists('json_encode')) { return json_encode($data); } if (class_exists('Services_JSON')) { $json = new Services_JSON(); return $json->encodeUnsafe($data); } elseif (class_exists('Moxiecode_JSON')) { $json = new Moxiecode_JSON(); return $json->encode($data); } else { trigger_error('No JSON parser available', E_USER_ERROR); return ''; } }
function return_json($results) { // Check for callback if (isset($_GET['callback'])) { // Add the relevant header header('Content-type: text/javascript'); echo addslashes($_GET['callback']) . " ("; } else { if (isset($_GET['pretty'])) { // Will output pretty version header('Content-type: text/html'); } else { //header('Content-type: application/json'); //header('Content-type: text/javascript'); } } if (function_exists('json_encode')) { echo json_encode($results); } else { // PHP4 version require_once ABSPATH . "wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php"; $json_obj = new Moxiecode_JSON(); echo $json_obj->encode($results); } if (isset($_GET['callback'])) { echo ")"; } }
* language.php * * @package MCManager.stream * @author Moxiecode * @copyright Copyright © 2007, Moxiecode Systems AB, All rights reserved. */ error_reporting(E_ALL ^ E_NOTICE); header("Content-type: text/javascript"); // Load MCManager core require_once "../includes/general.php"; require_once "../classes/ManagerEngine.php"; require_once "../classes/Utils/Error.php"; require_once "../classes/Utils/JSON.php"; $MCErrorHandler = new Moxiecode_Error(false); set_error_handler("JSErrorHandler"); $json = new Moxiecode_JSON(); // NOTE: Remove default value $type = getRequestParam("type", "im"); $format = getRequestParam("format", false); $prefix = getRequestParam("prefix", ""); $code = getRequestParam("code", "en"); if ($type == "") { die("alert('No type set.');"); } // Clean up type, only a-z stuff. $type = preg_replace("/[^a-z]/i", "", $type); // Include Base and Core and Config. $man = new Moxiecode_ManagerEngine($type); require_once $basepath . "CorePlugin.php"; require_once "../config.php"; $man->dispatchEvent("onPreInit", array($type));
/** * Calls the MCError class, returns true. * * @param Int $errno Number of the error. * @param String $errstr Error message. * @param String $errfile The file the error occured in. * @param String $errline The line in the file where error occured. * @param Array $errcontext Error context array, contains all variables. * @return Bool Just return true for now. */ function StreamErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) { global $MCErrorHandler; // Ignore these if ($errno == E_STRICT) { return true; } // Just pass it through to the class. $data = $MCErrorHandler->handleError($errno, $errstr, $errfile, $errline, $errcontext); if ($data['break']) { if ($_SERVER["REQUEST_METHOD"] == "GET") { header("HTTP/1.1 500 Internal server error"); die($errstr); } else { unset($data['break']); unset($data['title']); $data['level'] = "FATAL"; $json = new Moxiecode_JSON(); $result = new stdClass(); $result->result = null; $result->id = 'err'; $result->error = $data; echo '<html><body><script type="text/javascript">parent.handleJSON(' . $json->encode($result) . ');</script></body></html>'; die; } } }
function json_decode($str) { $json = new Moxiecode_JSON(); return $json->decode($str); }
function json_encode($input) { $json = new Moxiecode_JSON(); return $json->encode($input); }
private static function _encode_json($results) { if (function_exists('json_encode')) { return json_encode($results); } else { // PHP4 version require_once ABSPATH . "wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php"; $json_obj = new Moxiecode_JSON(); return $json_obj->encode($results); } }