Beispiel #1
0
 /**
  * Send response to client
  * 
  * @param Api_Response $data
  * @return void
  */
 public final function send(Api_Response $response)
 {
     // Modify parser
     $this->executeHooks(Api_Hook_IHook::HOOK_MODIFY_PARSER, array($this->parser));
     // Get content type
     $content_type = $this->parser->content_type;
     // Set the content type
     header("Generator: Advanced API");
     header('HTTP/1.0 ' . $response->getCode() . " " . $this->getStatusCodeMessage($response->getCode()));
     header('Content-type: ' . $content_type);
     // If code is note ok (not 200) then log the returning message
     if ($response->getCode() != 200) {
         $error = reset($response->getErrors());
         if (is_object($error)) {
             $this->logger->log($error->getMessage());
         }
     }
     // Create data array from response
     if (!is_array($response)) {
         $data['code'] = $response->getCode();
         foreach ($response->getErrors() as $error) {
             if (is_object($error)) {
                 $data['errors'][] = $error->getMessage();
             }
         }
         $data['data'] = $response->getData();
     }
     // Parse response array to correct type
     $this->parser->setData($data);
     $this->parser->setParams($this->request->getParams());
     echo $this->parser->parse();
     exit;
 }
Beispiel #2
0
<?php

session_start();
error_reporting(0);
/**
 * Access point for all API calls
 */
set_include_path('.' . PATH_SEPARATOR . './library/MyApi' . PATH_SEPARATOR . './library/Api');
include "library/Api/Bootstrap.php";
include "library/MyApi/MyApi.php";
// Fix json encode for older PHP version than 5.2
include "library/Json/Encoder.php";
// Create request object
$request = new Api_Request("http://192.168.1.101:8080/Source/Projects/PHP/APIFramework/src/Script/");
$request->setParams(array("version", "service", "method"));
$request->analyze();
// Load config
$config = parse_ini_file("config.ini", true);
// Create Custom api instance
$api = new MyApi();
// Add modify config hook
$api->addHook("Api_Hook_ConfigModify", Api_Hook_IHook::HOOK_CONFIG_LOADED);
$api->addHook("Api_Hook_BlockIp", Api_Hook_IHook::HOOK_BEFORE_SERVICE_EXECUTE);
$api->addHook("Api_Hook_RequestLimit", Api_Hook_IHook::HOOK_BEFORE_SERVICE_EXECUTE);
$api->addHook("Api_Hook_ParserModify", Api_Hook_IHook::HOOK_MODIFY_PARSER);
// Handle api request and catch errors
try {
    $api->handle($request, $config);
} catch (Api_Error $error) {
    $response = new Api_Response($error->getCode(), null, $error);
    $api->send($response);
Beispiel #3
0
 public function edit($id)
 {
     $this->load->model("Mdl_Requests");
     $this->load->model("Mdl_Comments");
     $this->load->model("Mdl_Users");
     $req = $this->Mdl_Requests->get($id);
     $requestMediaHTML = "";
     if ($req->type == "REQ_FEED") {
         if ($req->mediatype == "IMG") {
             $requestMediaHTML .= "<img class='req-feed-img' src='" . $req->mediaurl . "''></img>";
         } else {
             if ($req->mediatype == "VIDEO") {
                 $requestMediaHTML .= "<video class='req-feed-vid' controls='' name='media'>";
                 $requestMediaHTML .= "<source src='" . $req->mediaurl . "'' type='video/mp4'>";
                 $requestMediaHTML .= "</video>";
             } else {
                 if ($req->mediatype == "TEXT") {
                     $requestMediaHTML = "No media attached.";
                 }
             }
         }
     } else {
         $requestMediaHTML .= "...";
     }
     $comments = $this->Mdl_Comments->getAll("request", $req->id);
     $commentsHTML = "<div>";
     if (count($comments)) {
         foreach ($comments as $comm) {
             $comm->commenter = $this->Mdl_Users->get($comm->commenter);
             $userLink = site_url("Users/edit/" . $comm->commenter->id);
             $commentsHTML .= "<p class='req-comment'>";
             $commentsHTML .= $comm->comment;
             $commentsHTML .= "<div>Written by <span class='req-commenter'><a href='" . $userLink . "'>" . $comm->commenter->username . "  </a></span> " . $comm->updated_time . "</div>";
             $commentsHTML .= "</p>";
         }
     } else {
         $commentsHTML .= "No comments provided.";
     }
     $commentsHTML .= "</div>";
     parent::initView($this->ctrlName . '/edit.php', 'Pray request', 'Manage media such as images and videos', array("request" => $req, "requestMediaHTML" => $requestMediaHTML, "commentsHTML" => $commentsHTML, "commentCount" => count($comments)));
     parent::loadView();
 }