Ejemplo n.º 1
0
 public function __construct()
 {
     $this->key = Instance::get('SECRETKEY');
     if (!$this->key) {
         throw new Exception(self::E_Key);
     }
     if (strlen($this->key) != 64) {
         throw new Exception(self::E_Invalid);
     }
 }
Ejemplo n.º 2
0
 public static function isAdmin()
 {
     return (bool) Instance::get('SESSION.admin');
 }
Ejemplo n.º 3
0
 private function pageTitle($prepend, $hypen = true)
 {
     Instance::set('pageTitle', $prepend . ' ' . ($hypen ? '- ' : '') . Instance::get('pageTitle'));
 }
Ejemplo n.º 4
0
 /**
  *   Hydrate mapper object using hive array variable
  *   @return NULL
  *   @param $key string
  *   @param $func callback
  **/
 public function copyfrom($key, $func = NULL)
 {
     $var = is_array($key) ? $key : Instance::get($key);
     if ($func) {
         $var = call_user_func($func, $var);
     }
     foreach ($var as $key => $val) {
         !isset($this->_properties['fields'][$key]) || $this->set($key, $val);
     }
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * Parse body from PUT method
  * @source https://gist.github.com/chlab/4283560
  *
  * @return array data and files
  */
 function parseBody()
 {
     $result = array('data' => array(), 'files' => array());
     // read incoming data
     $input = Instance::get('BODY');
     // grab multipart boundary from content type header
     preg_match('/boundary=(.*)$/', $_SERVER['CONTENT_TYPE'], $matches);
     // content type is probably regular form-encoded
     if (!count($matches)) {
         // we expect regular puts to containt a query string containing data
         parse_str($input, $result['data']);
     } else {
         $boundary = $matches[1];
         // split content by boundary and get rid of last -- element
         $a_blocks = preg_split("/-+{$boundary}/", $input);
         array_pop($a_blocks);
         // loop data blocks
         foreach ($a_blocks as $id => $block) {
             if (empty($block)) {
                 continue;
             }
             // you'll have to var_dump $block to understand this and maybe replace \n or \r with a visibile char
             // parse uploaded files
             if (strpos($block, 'application/octet-stream') !== FALSE) {
                 // match "name", then everything after "stream" (optional) except for prepending newlines
                 // preg_match("/name=\"([^\"]*)\".*stream[\n|\r]+([^\n\r].*)?$/s", $block, $matches);
                 // $a_data['files'][$matches[1]] = isset($matches[2])?$matches[2]:null;
             } else {
                 // match "name" and optional value in between newline sequences
                 if (strpos($block, 'filename="') === false) {
                     preg_match('/name=\\"([^\\"]*)\\"[\\n|\\r]+([^\\n\\r].*)?\\r$/s', $block, $matches);
                     $result['data'][$matches[1]] = isset($matches[2]) ? $matches[2] : null;
                 } else {
                     preg_match('/; name=\\"([^\\"]*)\\"; filename=\\"([^\\"]*)\\"\\s*Content\\-Type: ([\\w\\/]+)[\\n|\\r]+([^\\n\\r].*)?\\r$/s', $block, $matches);
                     $result['files'][$matches[1]] = array('name' => $matches[2], 'type' => $matches[3], 'tmp_name' => tempnam(ini_get('upload_tmp_dir'), 'php'), 'error' => UPLOAD_ERR_OK, 'size' => 0);
                     $result['files'][$matches[1]]['size'] = file_put_contents($result['files'][$matches[1]]['tmp_name'], $matches[4]);
                     $result['files'][$matches[1]]['size'] !== false || ($result['files'][$matches[1]]['error'] = UPLOAD_ERR_CANT_WRITE);
                 }
             }
         }
     }
     return $result;
 }