public function __construct($id, $adrProperties)
 {
     $properties = (include __DIR__ . "/../../../view/graphic-object-templating/oobject/odcontained/odcontained.config.phtml");
     $parent = parent::__construct($id, trim($adrProperties));
     $properties = array_merge($parent->properties, $properties);
     $this->setProperties($properties);
     $this->setForm($properties['form']);
     $this->setName(empty($properties['name']) ? $properties['id'] : $properties['name']);
     $this->setValue($properties['value']);
     return $this;
 }
Exemplo n.º 2
0
 public function route($path, $params = array(), $direct = FALSE)
 {
     $php_input = file_get_contents("php://input");
     if (!empty($php_input) && empty($params['data'])) {
         if ($_SERVER["CONTENT_TYPE"] === 'application/json') {
             $params = (array) json_decode($php_input);
         } else {
             $params["data"] = $php_input;
         }
     }
     $start_time = microtime(TRUE);
     if (defined('__TIMEZONE__')) {
         date_default_timezone_set(__TIMEZONE__);
     }
     $obj = parent::route($path, $params, $direct);
     // Call the parent class default route function
     /*****************************************************************************************
     
     				1.	Setting the HTTP/1.1 status codes
     
     					Hypertext Transfer Protocol -- HTTP/1.1
     					SRC: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
     
     					(please see source for additional information on how these should be used)
     
     			*****************************************************************************************/
     $status_codes = array(200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported');
     if ($obj->getStatusCode() == 401) {
         if (!empty(__OBRAY_AUTHENTICATION_HEADER__)) {
             header('WWW-Authenticate: Basic realm="' . __APP__ . '"');
         } else {
             if (method_exists($obj, "auth")) {
                 $obj->auth();
             }
         }
     }
     $content_type = $obj->getContentType();
     if (!headers_sent()) {
         header('HTTP/1.1 ' . $obj->getStatusCode() . ' ' . $status_codes[$obj->getStatusCode()]);
     }
     // set HTTP Header
     if ($content_type == 'text/table') {
         $tmp_type = 'text/table';
         $content_type = 'text/html';
     }
     if (!headers_sent()) {
         header('Content-Type: ' . $content_type);
     }
     // set Content-Type
     if (!empty($tmp_type)) {
         $content_type = $tmp_type;
     }
     //if(!headers_sent()){ header('Content-Type: ' . 'application/json' ); }
     //$content_type = 'text/csv';
     //if(!headers_sent()){ header('Access-Control-Allow-Origin: *'); }
     //if(!headers_sent()){ header('Access-Control-Allow-Headers: Obray-Token'); }
     /*****************************************************************************************
     
     				2.	Setting the content-type
     
     			*****************************************************************************************/
     $obj->cleanUp();
     if (PHP_SAPI === 'cli') {
         $content_type = 'console';
     }
     switch ($content_type) {
         // handle OObject content types
         case 'application/json':
             // Handle JSON (default)
             $obj->runtime = (microtime(TRUE) - $start_time) * 1000;
             $json = json_encode($obj, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK);
             if ($json === FALSE) {
                 $json = json_encode($obj, JSON_PRETTY_PRINT);
             }
             if ($json) {
                 echo $json;
             } else {
                 echo 'There was en error encoding JSON.';
             }
             break;
         case "application/msgpack":
             $obj->runtime = (microtime(TRUE) - $start_time) * 1000;
             $msg = msgpack_pack($obj);
             if (!empty($msg)) {
                 echo $msg;
             } else {
                 echo 'There was en error encoding JSON.';
             }
             break;
         case 'text/html':
             // Handle HTML
             $obj->runtime = (microtime(TRUE) - $start_time) * 1000;
             if (!headers_sent()) {
                 header('Server-Runtime: ' . $obj->runtime . 'ms');
             }
             // set header runtime
             echo $obj->html;
             break;
         case 'text/csv':
             $extension = 'csv';
             $separator = ',';
         case 'text/tsv':
             if (empty($extension)) {
                 $extension = 'tsv';
             }
             if (empty($separator)) {
                 $separator = "\t";
             }
             header("Content-disposition: attachment; filename=\"" . $obj->object . "." . $extension . "\"");
             header('Content-Type: application/octet-stream; charset=utf-8;');
             header("Content-Transfer-Encoding: utf-8");
         case 'text/table':
             $withs = array();
             if (!empty($obj->table_definition)) {
                 foreach ($obj->table_definition as $name => $col) {
                     foreach ($col as $key => $prop) {
                         if (!in_array($key, ['primary_key', 'label', 'required', 'data_type', 'type', 'slug_key', 'slug_value'])) {
                             $withs[] = $key;
                         }
                     }
                 }
             }
             if (!empty($extension)) {
                 $fp = fopen('php://output', 'w');
             }
             if (!empty($obj->data)) {
                 $obj->data = $this->getCSVRows($obj->data);
                 $columns = array();
                 $biggest_row = new stdClass();
                 $biggest_row->index = 0;
                 $biggest_row->count = 0;
                 foreach ($obj->data as $i => $array) {
                     $new = array_keys($array);
                     $columns = array_merge($columns, $new);
                     $columns = array_unique($columns);
                 }
                 $path = preg_replace('/with=[^&]*/', '', $path);
                 $path = str_replace('?&', '?', $path);
                 $path = str_replace('&&', '&', $path);
                 if (!empty($extension)) {
                     fputcsv($fp, $columns, $separator);
                 } else {
                     echo '<html>';
                     echo '<head><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"><script src="https://code.jquery.com/jquery-1.11.2.min.js"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script></head>';
                     echo '<body>';
                     $csv_path = str_replace('otable', 'ocsv', $path);
                     $tsv_path = str_replace('otable', 'otsv', $path);
                     $json_path = str_replace(['?otable', '&otable'], '', $path);
                     $col_dropdown = '<div class="btn-group" role="group"><button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Cols <span class="caret"></span></button><ul class="dropdown-menu" role="menu">';
                     foreach ($columns as $col) {
                         $col_dropdown .= '<li><a href="' . $path . '">' . $col . '</a></li>';
                     }
                     $col_dropdown .= '</ul></div>';
                     $with_dropdown = '<div class="btn-group" role="group"><button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">With <span class="caret"></span></button><ul class="dropdown-menu" role="menu">';
                     foreach ($withs as $with) {
                         $with_dropdown .= '<li><a href="' . $path . '&with=' . $with . '">' . $with . '</a></li>';
                     }
                     $with_dropdown .= '</ul></div>';
                     echo '<div class="pull-right"><div class="btn-group">' . $col_dropdown . $with_dropdown . '<a class="btn btn-default" target="_blank" href="' . $csv_path . '">Download CSV</a><a target="_blank" class="btn btn-default" href="' . $tsv_path . '">Download TSV</a><a target="_blank" class="btn btn-default" href="' . $json_path . '">Show JSON</a>&nbsp;</div></div> <h2>' . $obj->object . '</h2> <table class="table table-bordered table-striped table-condensed" cellpadding="3" cellspacing="0">';
                     $this->putTableRow($columns, 'tr', 'th');
                 }
                 foreach ($obj->data as $index => $row_data) {
                     $row = array_fill_keys($columns, '');
                     $row = array_merge($row, $row_data);
                     if (!empty($extension)) {
                         fputcsv($fp, $row, $separator);
                     } else {
                         $this->putTableRow($row);
                     }
                     flush();
                 }
                 if ($content_type = 'text/html') {
                     echo '</table></body>';
                 }
             }
             break;
         case 'console':
             $obj->runtime = (microtime(TRUE) - $start_time) * 1000;
             $this->console("%s", "\n\n****************************************************\n", "WhiteBold");
             $this->console("%s", "\tResponse Object\n", "WhiteBold");
             $this->console("%s", "****************************************************\n\n", "WhiteBold");
             $this->console($obj);
             $this->console("\n");
             break;
         case 'application/xml':
             // Handle XML
             break;
         case 'text/css':
             echo $obj->html;
         case 'image/jpeg':
             echo $obj->html;
             break;
     }
     /*****************************************************************************************
     				
     				3.	Returning the final object for output
     				
     			*****************************************************************************************/
     return $obj;
 }