Пример #1
0
 public static function get()
 {
     $response = new XMLElement('response');
     foreach (self::$_sections as $section) {
         $section_xml = new XMLElement('section');
         $meta = $section->get();
         foreach ($meta as $key => $value) {
             $section_xml->setAttribute(Lang::createHandle($key), $value);
         }
         $fields = $section->fetchFields();
         foreach ($fields as $field) {
             $meta = $field->get();
             unset($meta['field_id']);
             $field_xml = new XMLElement($meta['element_name'], null);
             foreach (self::$_field_attributes as $attr) {
                 $field_xml->setAttribute(Lang::createHandle($attr), $meta[$attr]);
             }
             foreach ($meta as $key => $value) {
                 if (in_array($key, self::$_field_attributes)) {
                     continue;
                 }
                 $value = General::sanitize($value);
                 if ($value != '') {
                     $field_xml->appendChild(new XMLElement(Lang::createHandle($key), General::sanitize($value)));
                 }
             }
             $section_xml->appendChild($field_xml);
         }
         $response->appendChild($section_xml);
     }
     REST_API::sendOutput($response);
 }
Пример #2
0
 public static function get()
 {
     $url_parts = REST_API::getRequestURI();
     $author_url = $url_parts[0];
     $response = new XMLElement('response');
     if (isset($author_url)) {
         if (is_numeric($author_url)) {
             $author = AuthorManager::fetchByID($author_url);
         } else {
             $author = AuthorManager::fetchByUsername($author_url);
         }
         if (!$author) {
             REST_API::sendError('Author not found.', 404);
         }
         $response->appendChild(self::__buildAuthorXML($author));
     } else {
         $authors = AuthorManager::fetch();
         foreach ($authors as $author) {
             $response->appendChild(self::__buildAuthorXML($author));
         }
     }
     REST_API::sendOutput($response);
 }
Пример #3
0
<?php

// set up Symphony
define('DOCROOT', rtrim(dirname(__FILE__), '/') . '/../..');
if (file_exists(DOCROOT . '/vendor/autoload.php')) {
    require_once DOCROOT . '/vendor/autoload.php';
}
require_once DOCROOT . '/symphony/lib/boot/bundle.php';
require_once CORE . '/class.frontend.php';
// include the extension core
require_once EXTENSIONS . '/rest_api/lib/class.rest_api.php';
REST_API::init();
Пример #4
0
                            header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
                            $this->sendJson(array('error' => true));
                        } else {
                            if (isset($ret['__raw']) && $ret['__raw']) {
                                unset($ret['__raw']);
                                $this->sendJson($ret);
                            }
                            $this->sendJson(array('error' => false, 'data' => $ret));
                        }
                    }
                    header($_SERVER["SERVER_PROTOCOL"] . " 405 Method Not Allowed");
                    $this->sendJson(array('error' => true, 'message' => '405 Method Not Allowed'));
                }
            }
            header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
            $this->sendJson(array('error' => true, 'message' => '404 Not Found'));
        }
        echo "Restfull API 1.0";
    }
}
//create api instance
$a = str_replace('\\', '/', realpath($_SERVER['SCRIPT_FILENAME']));
$b = str_replace('\\', '/', realpath(__FILE__));
if ($a === $b) {
    //@ini_set('display_errors', 'Off');
    global $api;
    global $norm;
    $norm = NotORM::getInstance();
    $api = new REST_API();
    $api->start();
}
Пример #5
0
 public static function sendOutput($xml)
 {
     switch (REST_API::getHTTPMethod()) {
         case 'get':
             $xml = $xml->getChildrenByName('response');
             if (is_array($xml)) {
                 $xml = reset($xml);
             }
             REST_API::sendOutput($xml);
             break;
         case 'post':
             $xml = $xml->getChildrenByName('events');
             if (is_array($xml)) {
                 $xml = reset($xml);
             }
             $xml = $xml->getChildrenByName('response');
             if (is_array($xml)) {
                 $xml = reset($xml);
             }
             REST_API::sendOutput($xml);
             break;
     }
 }
Пример #6
0
 public function frontendOutputPreGenerate($context)
 {
     if (class_exists('REST_API') && class_exists('REST_Entries') && REST_API::isFrontendPageRequest()) {
         REST_Entries::sendOutput($context['xml']);
     }
 }
    }
    /**
     * Execute a specific event
     */
    public function run_event($request)
    {
        // Parse request for details needed to identify the event to execute
        // `$timestamp` is, unsurprisingly, the Unix timestamp the event is scheduled for
        // `$action` is the md5 hash of the action used when the event is registered
        // `$instance` is the md5 hash of the event's arguments array, which Core uses to index the `cron` option
        $event = $request->get_json_params();
        $timestamp = isset($event['timestamp']) ? absint($event['timestamp']) : null;
        $action = isset($event['action']) ? trim(sanitize_text_field($event['action'])) : null;
        $instance = isset($event['instance']) ? trim(sanitize_text_field($event['instance'])) : null;
        return rest_ensure_response(Events::instance()->run_event($timestamp, $action, $instance));
    }
    /**
     * Check if request is authorized
     */
    public function check_secret($request)
    {
        $body = $request->get_json_params();
        // For now, mimic original plugin's "authentication" method. This needs to be better.
        if (!isset($body['secret']) || !hash_equals(\WP_CRON_CONTROL_SECRET, $body['secret'])) {
            return new \WP_Error('no-secret', __('Secret must be specified with all requests', 'automattic-cron-control'), array('status' => 400));
        }
        return true;
    }
}
REST_API::instance();
Пример #8
0
 public static function sendError($message = NULL, $code = 200, $format = NULL)
 {
     if ($format) {
         self::$_output_type = $format;
     }
     $response = new XMLElement('response', NULL, array('result' => 'error', 'code' => $code));
     $response->appendChild(new XMLElement('error', $message));
     self::sendOutput($response, $code);
 }