예제 #1
0
 public function read()
 {
     $list = cfg('resources', 'models', $this->name);
     $rels = array('collection', 'model');
     $data = array();
     $pack = array();
     foreach ($list as $model) {
         $cname = \System\Loader::get_class_from_model($model);
         $model = \System\Loader::get_model_from_class($model);
         $schema = $cname::get_visible_schema($this->request->user);
         foreach ($schema['attrs'] as $attr) {
             if (in_array($attr['type'], $rels)) {
                 $rel_cname = \System\Loader::get_class_from_model($attr['model']);
                 $rel_model = \System\Loader::get_model_from_class($attr['model']);
                 if (!array_key_exists($rel_model, $pack)) {
                     $pack[$rel_model] = $rel_cname::get_visible_schema($this->request->user);
                 }
             }
         }
         $pack[$model] = $schema;
     }
     foreach ($pack as $name => $def) {
         $data[] = array("name" => $name, "parents" => array('model'), "static" => $def);
     }
     $this->content = json_encode(array("data" => $data));
 }
예제 #2
0
파일: all.php 프로젝트: just-paja/fudjan
 public static function module_batch()
 {
     \System\Loader::load_all_modules();
     $list = static::get_children_of('System\\Module');
     $data = array();
     foreach ($list as $cname) {
         $data[] = array($cname);
     }
     return $data;
 }
예제 #3
0
 public function request_decode()
 {
     $this->cname = \System\Loader::get_class_from_model($this->req('model'));
     $this->request_decode_pagination();
     $this->filters = $this->request_decode_part('filters');
     $this->sort = $this->request_decode_part('sort');
     $this->joins = $this->request_decode_part('join');
     if (!is_array($this->joins)) {
         $this->joins = array();
     }
 }
예제 #4
0
파일: all.php 프로젝트: just-paja/fudjan
 public static function get_children_of($parent)
 {
     \System\Loader::load_all();
     $list = array();
     $all = get_declared_classes();
     foreach ($all as $cname) {
         if (in_array($parent, class_parents($cname))) {
             $list[] = $cname;
         }
     }
     return $list;
 }
예제 #5
0
 public function run()
 {
     $rq = $this->request;
     $id = $this->req('id');
     $model = $this->req('model');
     $cname = \System\Loader::get_class_from_model($model);
     $response = array('message' => 'not-found', 'status' => 404);
     if (class_exists($cname) && is_subclass_of($cname, '\\System\\Model\\Perm')) {
         if ($item = $cname::find($id)) {
             if ($item->can_be($cname::DROP, $rq->user)) {
                 $item->drop();
                 $response['message'] = 'dropped';
                 $response['status'] = 200;
             } else {
                 $response['message'] = 'denied';
                 $response['status'] = 403;
             }
         }
     }
     $this->partial(null, $response);
 }
예제 #6
0
 public function run()
 {
     $rq = $this->request;
     $res = $this->response;
     $ren = $res->renderer;
     $userClass = \System\Loader::get_class_from_model(\System\Settings::get('godmode', 'userClass'));
     if ($rq->logged_in()) {
         $this->flow->redirect($ren->url('god_home'));
     } else {
         $f = $res->form(array("id" => 'core-user-login'));
         $f->input(array('type' => 'text', 'name' => 'login', 'label' => $ren->trans("gm-login-name"), 'required' => true));
         $f->input(array('type' => 'password', 'name' => 'password', 'label' => $ren->trans("gm-password"), 'required' => true));
         $f->submit($ren->trans('Log in'));
         if ($f->passed()) {
             $p = $f->get_data();
             if ($userClass::startSession($rq, $p['login'], $p['password'])) {
                 $this->flow->redirect($ren->url('god_home'));
             }
         }
         $f->out($this);
     }
 }
예제 #7
0
 public function run()
 {
     $rq = $this->request;
     $res = $this->response;
     $page = 0;
     $per_page = 1;
     $model = $this->req('model');
     $cname = \System\Loader::get_class_from_model($model);
     $exists = class_exists($cname) && is_subclass_of($cname, '\\System\\Model\\Perm');
     $send = array('status' => 404, 'message' => 'schema-not-found');
     if ($exists) {
         try {
             $schema = $cname::get_visible_schema($rq->user);
         } catch (\System\Error\AccessDenied $e) {
             $send['status'] = 403;
             $send['message'] = 'access-denied';
         }
         if ($schema) {
             $send['status'] = 200;
             $send['message'] = 'ok';
             $send['data'] = $schema;
         }
     }
     try {
         $debug = \System\Settings::get('dev', 'debug', 'backend');
     } catch (\System\Error $e) {
         $debug = true;
     }
     if (!$debug) {
         $max_age = \System\Settings::get('cache', 'resource', 'max-age');
         $res->header('Pragma', 'public,max-age=' . $max_age);
         $res->header('Cache-Control', 'public');
         $res->header('Expires', date(\DateTime::RFC1123, time() + $max_age + rand(0, 60)));
         $res->header('Age', '0');
     }
     $this->partial(null, $send);
 }
예제 #8
0
파일: attr.php 프로젝트: just-paja/fudjan
 /**
  * Convert model to string
  *
  * @return string
  */
 public function __toString()
 {
     return sprintf('[%s]', \System\Loader::get_model_from_class(get_class($this)));
 }
예제 #9
0
파일: error.php 프로젝트: just-paja/fudjan
 public function get_name()
 {
     return str_replace('system/error/', '', \System\Loader::get_class_file_name(get_class($this)));
 }
예제 #10
0
파일: cli.php 프로젝트: just-paja/fudjan
 public static function show_usage($script)
 {
     self::out('Fudjan system manager');
     self::out();
     self::out('Usage: ' . $script . ' module [command] [params]');
     self::out('Use --help with command to see help for modules');
     self::out();
     \System\Loader::load_all();
     \System\Loader::load_all_helpers();
     $all_classes = get_declared_classes();
     $child_classes = array();
     foreach ($all_classes as $class) {
         if (is_subclass_of('\\' . $class, '\\Helper\\Cli\\Module')) {
             $ref = new \ReflectionClass($class);
             if (!$ref->isAbstract()) {
                 $name = explode('\\', $class);
                 $child_classes[] = strtolower($name[count($name) - 1]);
             }
         }
     }
     sort($child_classes);
     self::out('Modules:');
     self::out_flist(array("list" => $child_classes, "show_keys" => false, "margin" => 4));
 }
예제 #11
0
파일: module.php 프로젝트: just-paja/fudjan
 public static function from_path($path, array $opts)
 {
     $cname = \System\Loader::get_class_from_model('module.' . $path);
     return new $cname($opts);
 }
예제 #12
0
 /** Convert model to string
  * @return string
  */
 public function __toString()
 {
     return sprintf('[%s#%s]', \System\Loader::get_model_from_class(get_class($this)), $this->is_new() ? 'new' : $this->id);
 }
예제 #13
0
파일: cache.php 프로젝트: just-paja/fudjan
 public static function build_modules()
 {
     \System\Loader::load_all_modules();
     \System\File::put(BASE_DIR . \System\Loader::FILE_MODULES, \System\Loader::dump_core(true));
 }
예제 #14
0
 public function run()
 {
     $id = $this->id;
     $new = $this->new;
     def($id);
     def($new, false);
     $model = $this->req('model');
     $rq = $this->request;
     $cname = \System\Loader::get_class_from_model($model);
     $response = array('message' => 'not-found', 'status' => 404);
     if (class_exists($cname) && is_subclass_of($cname, '\\System\\Model\\Perm')) {
         if ($item = $new ? new $cname() : $cname::find($id)) {
             $data = $rq->post();
             foreach ($data as $attr_name => $val) {
                 if ($item::has_attr($attr_name)) {
                     $def = $cname::get_attr($attr_name);
                     if (is_string($val)) {
                         if (preg_match('/^[\\{\\[].*[\\}\\]]$/', $val)) {
                             $val = \System\Json::decode(html_entity_decode($val));
                         }
                     }
                     if (in_array($def['type'], array('file', 'image'))) {
                         $helper_cname = '\\System\\File';
                         if ($def['type'] == 'image') {
                             $helper_cname = '\\System\\Image';
                         }
                         if (is_array($val)) {
                             if (any($val['method']) && any($val[$val['method']])) {
                                 $data = $rq->post($val[$val['method']]);
                                 if ($data) {
                                     $item->{$attr_name} = $helper_cname::from_tmp($data['tmp_name'], $data['name']);
                                 }
                             }
                         }
                     } else {
                         if ($def['type'] == 'password') {
                             $item->{$attr_name} = hash_passwd($val);
                         } else {
                             if ($def['type'] == 'bool') {
                                 if ($val == 'false') {
                                     $val = false;
                                 }
                                 $item->{$attr_name} = $val;
                             } else {
                                 if ($def['type'] == 'date') {
                                     $date = \DateTime::createFromFormat('Y-m-d', $val);
                                     if ($date) {
                                         $tz = new \DateTimeZone(\System\Settings::get('locales', 'timezone'));
                                         $date->setTimeZone($tz);
                                     } else {
                                         $date = null;
                                     }
                                     $item->{$attr_name} = $date;
                                 } else {
                                     if ($def['type'] == 'datetime') {
                                         $date = \DateTime::createFromFormat('Y-m-d\\TH:i:sO', $val);
                                         if ($date) {
                                             $tz = new \DateTimeZone(\System\Settings::get('locales', 'timezone'));
                                             $date->setTimeZone($tz);
                                         } else {
                                             $date = null;
                                         }
                                         $item->{$attr_name} = $date;
                                     } else {
                                         $item->{$attr_name} = $val;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $item->request = $rq;
             if ($item::has_attr('author') && $rq->user) {
                 $item->author = $rq->user;
             }
             try {
                 $item->save();
             } catch (\System\Error $e) {
                 $response['status'] = 500;
                 $response['message'] = $e->get_explanation();
             }
             if ($response['status'] != 500) {
                 $response['message'] = $new ? 'created' : 'saved';
                 $response['status'] = 200;
             }
             $response['data'] = $item->to_object();
         }
     }
     $this->partial(null, $response);
 }
예제 #15
0
파일: router.php 프로젝트: just-paja/fudjan
 public static function get_pattern_test($pat)
 {
     $attrs = self::get_pattern_attrs($pat);
     foreach ($attrs as $attr) {
         $cname = '\\System\\Router\\Arg\\' . \System\Loader::get_class_from_model($attr['type']);
         $test = '/\\{' . $attr['name'] . ':' . $attr['type'];
         if ($attr['required']) {
             $test .= '(:yes)?';
         } else {
             $test .= ':no';
         }
         if (isset($attr['choices'])) {
             $test .= ':' . implode(',', $attr['choices']);
             $sub = '(' . implode('|', $attr['choices']) . ')';
         } else {
             $sub = '(' . $cname::PATTERN . ')' . ($attr['required'] ? '' : '?');
         }
         $test .= '\\}/';
         $pat = preg_replace($test, $sub, $pat);
     }
     return $pat;
 }
예제 #16
0
 /** Get string constant for common attributes
  * @param string $model
  * @param string $attr
  * @return string
  */
 public function get_common_attr_trans_name($model, $attr)
 {
     $key = 'attr-' . $attr;
     $model = \System\Loader::get_model_from_class($model);
     $full = 'model-' . $model . '-' . $key;
     return $this->has_msg($full) ? $full : $key;
 }
예제 #17
0
파일: perm.php 프로젝트: just-paja/fudjan
 public static function get_visible_schema(\System\User $user)
 {
     if (static::can_user(static::VIEW_SCHEMA, $user)) {
         $cname = get_called_class();
         $schema = static::get_schema();
         $res = array();
         $rel_attrs = array('collection', 'model');
         foreach ($schema['attrs'] as $key => $attr) {
             if (in_array($attr['type'], $rel_attrs)) {
                 $rel_cname = \System\Loader::get_class_from_model($attr['model']);
                 if (class_exists($rel_cname) && is_subclass_of($rel_cname, '\\System\\Model\\Perm') && $rel_cname::can_user(static::VIEW_SCHEMA, $user)) {
                     $res[] = $attr;
                 }
             } else {
                 $res[] = $attr;
             }
         }
         $schema['attrs'] = $res;
         return $schema;
     } else {
         throw new \System\Error\AccessDenied();
     }
 }
예제 #18
0
파일: loader.php 프로젝트: just-paja/fudjan
 public static function autoload($class_name)
 {
     $sources = array('/lib/class', '/lib');
     $found = false;
     $file = \System\Loader::get_class_file_name($class_name, true);
     $helper_pos = strpos(\System\Loader::get_link_from_class($class_name), 'helper');
     $is_helper = $helper_pos !== false && $helper_pos <= 1;
     foreach ($sources as $key => $source) {
         $classes = \System\Composer::list_dirs($source);
         foreach ($classes as $dir) {
             if (file_exists($f = $dir . '/' . $file)) {
                 $found = (include_once $f);
                 break;
             }
         }
         if ($found) {
             break;
         }
     }
 }
예제 #19
0
파일: db.php 프로젝트: just-paja/fudjan
 private static function seed_data($data_set_name, $data_set_models)
 {
     \System\Init::full();
     foreach ($data_set_models as $model => $data_set) {
         $extra = array("model" => $model);
         \Helper\Cli::do_over($data_set, function ($key, $tdata, $extra) {
             $model = $extra['model'];
             $obj = null;
             $idc = $model::get_id_col($model);
             if (isset($tdata[$col = 'id']) || isset($tdata[$col = $idc])) {
                 $tdata[$idc] = $tdata[$col];
                 $obj = $model::find($tdata[$col]);
             }
             if ($obj) {
                 $obj->update_attrs($tdata);
             } else {
                 $obj = new $model($tdata);
                 $obj->is_new_object = true;
             }
             $obj->save();
             foreach ($tdata as $attr => $val) {
                 if (is_array($val) && $model::is_rel($attr)) {
                     if ($model::get_attr_type($attr) == $model::REL_HAS_MANY) {
                         $def = $model::get_attr($attr);
                         if (any($def['is_bilinear']) && any($def['is_master'])) {
                             unset($obj->{$attr});
                             $obj->{$attr} = $val;
                         }
                     }
                 }
             }
         }, $data_set_name . ': ' . \System\Loader::get_model_from_class($model), $extra);
     }
 }