Esempio n. 1
0
function getChapter($url, $debug)
{
    $content = extract_id(cURL($url), "storytext", $debug);
    $content = str_replace(array("‘", "’", "“", "”", "–", "—", "…"), array("'", "'", '"', '"', '-', '--', '...'), $content);
    $content = str_replace(array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)), array("'", "'", '"', '"', '-', '--', '...'), $content);
    return $content;
}
Esempio n. 2
0
 function acquire_poll($url)
 {
     // acquire request token and access token for future requests
     $token_string = request_token();
     $token_string2 = access_token($token_string);
     $tokens = form_tokens($token_string, $token_string2);
     
     // retrieve poll's 16-character id
     $id = extract_id($url);
     
     // access this poll
     $poll = access_poll($id, $tokens);
     
     // format poll data
     $xml_array = parse($poll);
     
     // store tokens for future use in submitting poll
     $xml_array['tokens'] = $tokens;
     
     return $xml_array;
 }
Esempio n. 3
0
     // make array containing checked values
     for($i = 1; $i <= $time; $i++)
     {
         // user checked box
         if(isset($_POST["option$i"]))
             $option[$i] = htmlspecialchars($_POST["option$i"]);
         
         // user didn't check box    
         else
             $option[$i] = "0";
     }
 
     // add options to array containing all user input
     $input['option'] = $option;
     $input['tokens'] = $poll['tokens'];
     $input['id'] = extract_id($url);
     
     // generate xml for post request
     $input['xml'] = update_xml($input);
     
     // send request using this input
     $response = submit_poll($input);
     
     // if unknown error...
     if($response == false)
         apologize("Sorry, an unknown error occurred. Please try again.");
     
     /*if user reaches this point, submission successful*/
 }
 
 else
Esempio n. 4
0
function handle_json_rpc($object)
{
    /*
    if ($input == '') {
      $input = file_get_contents('php://input');
    }
    */
    $input = $GLOBALS['HTTP_RAW_POST_DATA'];
    $encoding = mb_detect_encoding($input, 'auto');
    //convert to unicode
    if ($encoding != 'UTF-8') {
        $input = iconv($encoding, 'UTF-8', $input);
    }
    $input = json_decode($input);
    header('Content-Type: text/plain');
    // handle Errors
    if (!$input) {
        if ($GLOBALS['HTTP_RAW_POST_DATA'] == "") {
            echo response(null, 0, array("code" => -32700, "message" => "Parse Error: no data"));
        } else {
            // json parse error
            $error = json_error();
            $id = extract_id();
            echo response(null, $id, array("code" => -32700, "message" => "Parse Error: {$error}"));
        }
        exit;
    } else {
        $method = get_field($input, 'method', null);
        $params = get_field($input, 'params', null);
        $id = get_field($input, 'id', null);
        // json rpc error
        if (!($method && $id)) {
            if (!$id) {
                $id = extract_id();
            }
            if (!$method) {
                $error = "no method";
            } else {
                if (!$id) {
                    $error = "no id";
                } else {
                    $error = "unknown reason";
                }
            }
            echo response(null, $id, array("code" => -32600, "message" => "Invalid Request: {$error}"));
            exit;
        }
    }
    // fix params (if params is null set it to empty array)
    if (!$params) {
        $params = array();
    }
    // if params is object change it to array
    if (is_object($params)) {
        if (count(get_object_vars($params)) == 0) {
            $params = array();
        } else {
            $params = get_object_vars($params);
        }
    }
    // call Service Method
    try {
        $class = get_class($object);
        $methods = get_class_methods($class);
        do_debug($methods);
        if (strcmp($method, 'help') == 0) {
            if (count($params) > 0) {
                if (!in_array($params[0], $methods)) {
                    $no_method = 'There is no ' . $params[0] . ' method';
                    throw new Exception($no_method);
                } else {
                    $static = get_class_vars($class);
                    $help_str_name = $params[0] . "_documentation";
                    //throw new Exception(implode(", ", $static));
                    if (array_key_exists($help_str_name, $static)) {
                        echo response($static[$help_str_name], $id, null);
                    } else {
                        throw new Exception($method . " method has no documentation");
                    }
                }
            } else {
                $url = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
                $msg = 'PHP JSON-RPC - in "' . $url . "\"\n";
                $msg .= "class \"{$class}\" has methods: " . implode(", ", array_slice($methods, 0, -1)) . " and " . $methods[count($methods) - 1] . ".";
                echo response($msg, $id, null);
            }
        } else {
            if (!in_array($method, $methods)) {
                $msg = 'There is no ' . $method . ' method';
                echo response(null, $id, array("code" => -32601, "message" => $msg));
            } else {
                //throw new Exception('x -> ' . json_encode($params));
                $result = call_user_func_array(array($object, $method), $params);
                echo response($result, $id, null);
            }
        }
        exit;
    } catch (Exception $e) {
        //catch all exeption from user code
        $msg = "Internal error: " . $e->getMessage();
        echo response(null, $id, array("code" => -32603, "message" => $msg));
    }
}
Esempio n. 5
0
 function register_step_3($data)
 {
     $message = '';
     # Proceed only if the verification code matches a registered user
     $user = $this->_query_reader->get_row_as_array('get_user_by_id', array('user_id' => extract_id($data['confirmationcode'])));
     if (!empty($user['user_name']) && $user['user_name'] == $this->native_session->get('__user_name')) {
         # Update the user's organization contact
         $result = $this->_query_reader->run('update_organization_contact', array('organization_id' => $this->native_session->get('__organization_id'), 'contact_address' => htmlentities($data['address'], ENT_QUOTES), 'contact_city' => htmlentities($data['city'], ENT_QUOTES), 'contact_region' => htmlentities($data['region'], ENT_QUOTES), 'contact_zipcode' => $data['zipcode'], 'contact_country_id' => $data['contact__countries']));
         # Activate user
         if ($result) {
             $result = $this->_query_reader->run('activate_user_account', array('first_name' => htmlentities($data['firstname'], ENT_QUOTES), 'last_name' => htmlentities($data['lastname'], ENT_QUOTES), 'user_id' => $this->native_session->get('__user_id'), 'organization_id' => $this->native_session->get('__organization_id'), 'organization_type' => $this->native_session->get('organizationtype'), 'status' => $this->native_session->get('organizationtype') == 'provider' ? 'active' : 'pending'));
             if ($result) {
                 if ($this->native_session->get('organizationtype') == 'pde') {
                     $sentResult = $this->_messenger->send($this->types('admin'), array('code' => 'activate_new_pde', 'organization_name' => $this->native_session->get('businessname'), 'first_name' => htmlentities($data['firstname'], ENT_QUOTES), 'last_name' => htmlentities($data['lastname'], ENT_QUOTES)));
                 }
             } else {
                 $message = 'Your saved account could not be approved.';
             }
         } else {
             $message = 'The organization contact could not be saved.';
         }
     } else {
         $message = 'Your code could not be verified.';
     }
     return array('result' => !empty($result) && $result ? 'SUCCESS' : 'FAIL', 'reason' => $message);
 }
Esempio n. 6
0
function handle_json_rpc($object)
{
    try {
        $input = get_json_request();
        header('Content-Type: application/json');
        $method = get_field($input, 'method', null);
        $params = get_field($input, 'params', null);
        $id = get_field($input, 'id', null);
        // json rpc error
        if (!($method && $id)) {
            if (!$id) {
                $id = extract_id();
            }
            if (!$method) {
                $error = "no method";
            } else {
                if (!$id) {
                    $error = "no id";
                } else {
                    $error = "unknown reason";
                }
            }
            throw new JsonRpcExeption(103, "Invalid Request: {$error}");
            //": " . $GLOBALS['HTTP_RAW_POST_DATA']));
        }
        // fix params (if params is null set it to empty array)
        if (!$params) {
            $params = array();
        }
        // if params is object change it to array
        if (is_object($params)) {
            if (count(get_object_vars($params)) == 0) {
                $params = array();
            } else {
                $params = get_object_vars($params);
            }
        }
        // call Service Method
        $class = get_class($object);
        $methods = get_class_methods($class);
        if (strcmp($method, "system.describe") == 0) {
            echo json_encode(service_description($object));
        } else {
            if (!in_array($method, $methods) && !in_array("__call", $methods)) {
                // __call will be called for any method that's missing
                $msg = "Procedure `" . $method . "' not found";
                throw new JsonRpcExeption(104, $msg);
            } else {
                if (in_array("__call", $methods) && !in_array($method, $methods)) {
                    $result = call_user_func_array(array($object, $method), $params);
                    echo response($result, $id, null);
                } else {
                    $method_object = new ReflectionMethod($class, $method);
                    $num_got = count($params);
                    $num_expect = $method_object->getNumberOfParameters();
                    if ($num_got != $num_expect) {
                        $msg = "Wrong number of parameters in `{$method}' method. Got " . "{$num_got} expect {$num_expect}";
                        throw new JsonRpcExeption(105, $msg);
                    } else {
                        //throw new Exception('x -> ' . json_encode($params));
                        $result = call_user_func_array(array($object, $method), $params);
                        echo response($result, $id, null);
                    }
                }
            }
        }
    } catch (JsonRpcExeption $e) {
        // exteption with error code
        $msg = $e->getMessage();
        $code = $e->code();
        if ($code = 101) {
            // parse error;
            $id = extract_id();
        }
        echo response(null, $id, array("code" => $code, "message" => $msg));
    } catch (Exception $e) {
        //catch all exeption from user code
        $msg = $e->getMessage();
        echo response(null, $id, array("code" => 200, "message" => $msg));
    }
    ob_end_flush();
}