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); } }
public static function logout() { Instance::clear('SESSION'); return true; }
public function __construct() { $this->initSelect(); $pk = $this->primaryKey(); $this->_properties['primary_key'] = is_array($pk) ? $pk : [$pk]; $default = array(); foreach ($this->schema() as $key => $value) { is_array($value) || ($value = [$value]); $field = array_shift($value); $filter = array_shift($value); is_array($filter) || ($filter = [$filter]); $filter = array_filter($filter, array($this, 'filterRule')); $this->_properties['fields'][$key] = $field; $this->_schema['filter'][$key] = $filter; $this->_schema['values'][$key] = null; $default[$key] = array_shift($value); } foreach ($default as $key => $value) { $this->_schema['init'][$key] = is_callable($value) ? call_user_func($value) : (strpos($value, '->') === false ? $value : Instance::call($value)); } if (!$this->isView && !array_filter($this->_properties['fields'], array($this, 'filterRule'))) { throw new Exception(sprintf(self::E_Schema, get_called_class()), 1); } $this->_schema['config']['validation'] = count(array_filter($this->_schema['filter'] ?: array(), array($this, 'filterRule'))) > 0; }
private function pageTitle($prepend, $hypen = true) { Instance::set('pageTitle', $prepend . ' ' . ($hypen ? '- ' : '') . Instance::get('pageTitle')); }
/** * 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; }
public function needAdmin() { Auth::isAdmin() || Auth::logout() && Instance::reroute('@admin_login'); }