Beispiel #1
0
 public static function create_blank(array $attrs)
 {
     try {
         $path = cfg('thumbs', 'bad');
     } catch (\System\Error\Config $e) {
         $path = ROOT . '/share/pixmaps/pwf/bad_thumb.jpg';
     }
     $img = \System\Image::from_path($path);
     return self::from_image($img, $attrs);
 }
Beispiel #2
0
 public function resolve()
 {
     $hash = $this->name;
     if (!is_null($thumb = \System\Cache\Thumb::from_hash($hash))) {
         if ($thumb->check()) {
             $this->file_point = \System\Image::from_path(BASE_DIR . $thumb->get_path());
             $this->file_path = $this->file_point->get_path();
             $this->exists = $this->file_point->exists();
         } else {
             throw new \System\Error\File('Failed to generate image thumb.');
         }
     } else {
         $this->exists = false;
     }
 }
Beispiel #3
0
 public function val_get()
 {
     if ($this->resolved_value) {
         $val = $this->resolved_value;
     } else {
         $val = $this->form()->input_value($this->name);
     }
     if (gettype($val) == 'string') {
         $val = \System\Json::decode($val);
     }
     if (is_array($val)) {
         if ($val['method'] == 'url') {
             $val = \System\Image::fetch($val['url'])->temp()->unload();
             $val->temp = false;
             $val->method = 'keep';
         } else {
             if ($val['method'] == 'upload') {
                 $file = $this->form()->request->post($val['upload']);
                 $file = \System\Image::from_tmp($file['tmp_name'], $val['name']);
                 $file->temp();
                 $file->temp = false;
                 $file->method = 'keep';
                 $file->mime = $val['mime'];
                 $val = $file;
             } else {
                 if ($val['method'] == 'save') {
                     $file = \System\Image::from_path($val['path']);
                     $file->read_meta();
                     $val = $file;
                 } else {
                     if ($val['method'] == 'drop') {
                         $val = null;
                     }
                 }
             }
         }
     }
     $this->resolved_value = $val;
     return $val;
 }
Beispiel #4
0
 /** Create guest user
  * @return System\User
  */
 public static function guest()
 {
     return new self(array("user_id" => 0, "nick" => 'Anonymous', "image" => \System\Image::from_path("/share/pixmaps/pwf/anonymous_user.png")));
 }
<?php

$items = \Impro\Event::get_all()->fetch();
$attrs = array('image');
foreach ($items as $item) {
    foreach ($attrs as $attr) {
        if ($item->{$attr}) {
            $opts = $item->{$attr}->get_opts();
            if (empty($opts)) {
                $avatar = $item->{$attr};
                if (strpos($item->{$attr}->path, '/') === 0) {
                    $item->{$attr}->path = BASE_DIR . $item->{$attr}->path;
                }
            } else {
                if (any($opts['file_path'])) {
                    $avatar = \System\Image::from_path($opts['file_path']);
                    if ($avatar) {
                        $avatar->keep = true;
                    }
                } else {
                    $avatar = null;
                }
            }
            if (!is_null($avatar)) {
                try {
                    $avatar->save();
                } catch (Exception $e) {
                    $avatar = null;
                }
            }
            $item->{$attr} = $avatar;
Beispiel #6
0
 public static function get_schema()
 {
     static::check_model();
     $attrs = array();
     $schema = array();
     $cname = get_called_class();
     $list = static::get_attr_list();
     foreach ($list as $name) {
         if ($name == static::get_id_col()) {
             continue;
         }
         $attr = static::get_attr($name);
         $attr['name'] = $name;
         switch ($attr['type']) {
             case 'bool':
                 $attr['type'] = 'boolean';
                 break;
             case 'varchar':
                 $attr['type'] = 'string';
                 break;
             case 'json':
                 $attr['type'] = 'object';
                 break;
             case self::REL_HAS_ONE:
                 $nm = $attr['model'];
                 $attr['type'] = 'model';
                 $attr['subtype'] = 'has_one';
                 $attr['bound_to'] = static::get_rel_bound_to($name);
                 break;
             case self::REL_BELONGS_TO:
                 $attr['type'] = 'model';
                 break;
             case self::REL_HAS_MANY:
                 $rm = $attr['model'];
                 if (empty($attr['is_bilinear'])) {
                     $attr['bound_to'] = static::get_rel_bound_to($name);
                     $attr['foreign_key'] = $rm::get_belongs_to_id($attr['bound_to']);
                 } else {
                     $attr['foreign_key'] = static::get_id_col();
                 }
                 $attr['type'] = 'collection';
                 break;
         }
         // Convert attribute model bindings
         if (isset($attr['model'])) {
             $attr['model'] = \System\Loader::get_model_from_class($attr['model']);
         }
         // Convert attribute value options
         if (isset($attr['options'])) {
             if (isset($attr['options'][0]) && $attr['options'][0] == 'callback') {
                 $opts = $attr['options'];
                 array_shift($opts);
                 $opts = call_user_func($opts);
             } else {
                 $opts = $attr['options'];
             }
             $attr['options'] = array();
             foreach ($opts as $opt_value => $opt_name) {
                 $attr['options'][] = array('name' => $opt_name, 'value' => $opt_value);
             }
         }
         // Word 'default' is keyword in some browsers, so pwf-models use 'def' instead
         if (isset($attr['default'])) {
             $attr['def'] = $attr['default'];
             unset($attr['default']);
             if (in_array($attr['type'], array('image'))) {
                 $attr['def'] = \System\Image::from_path($attr['def'])->to_object();
             } else {
                 if (in_array($attr['type'], array('file', 'sound'))) {
                     $attr['def'] = \System\File::from_path($attr['def'])->to_object();
                 }
             }
         }
         if (is_array($attr)) {
             unset($attr[0]);
             $attrs[] = $attr;
         }
     }
     if (any($cname::$conversions)) {
         $schema['conversions'] = $cname::$conversions;
     }
     $schema['attrs'] = $attrs;
     return $schema;
 }