Exemple #1
0
 public function route($url = null, $context = null)
 {
     $thumbs_path = fx::path()->http('@thumbs');
     $thumbs_path_trimmed = fx::path()->removeBase($thumbs_path);
     if (substr($url, 0, strlen($thumbs_path_trimmed)) !== $thumbs_path_trimmed) {
         return null;
     }
     $dir = substr($url, strlen($thumbs_path_trimmed));
     preg_match("~/([^/]+)(/.+\$)~", $dir, $parts);
     $config = $parts[1];
     $source_path = $parts[2];
     $source_abs = fx::path($source_path);
     if (!file_exists($source_abs)) {
         return null;
     }
     $target_dir = dirname(fx::path('@home/' . $url));
     if (!file_exists($target_dir) || !is_dir($target_dir)) {
         return null;
     }
     $config = $config . '.async-false.output-true';
     $config = \Floxim\Floxim\System\Thumb::readConfigFromPathString($config);
     fx::image($source_path, $config);
     fx::complete();
     die;
 }
Exemple #2
0
 public function uploadSave($input)
 {
     $path = 'upload';
     $result = fx::files()->saveFile($input['file'], $path);
     if (!$result) {
         $result = array('error_message' => 'Can not load this file');
         fx::http()->status(500);
     }
     if (isset($input['format']) && !empty($input['format']) && isset($result['path'])) {
         $result['formatted_value'] = fx::image($result['path'], $input['format']);
     }
     return $result;
 }
Exemple #3
0
 /**
  * List all content of specified type
  *
  * @param type $input
  */
 public function all($input)
 {
     $content_type = $input['content_type'];
     $list = array('type' => 'list', 'values' => array(), 'labels' => array('id' => 'ID'), 'entity' => 'content');
     if ($content_type === 'content') {
         $list['labels']['type'] = 'Type';
     }
     $com = fx::data('component', $content_type);
     $fields = $com->getAllFields();
     $ib_field = $fields->findOne('keyword', 'infoblock_id');
     if ($ib_field) {
         $list['labels']['infoblock'] = $ib_field['name'];
     }
     $fields->findRemove(function ($f) {
         if ($f['keyword'] === 'parent_id' || $f['keyword'] === 'type' || $f['keyword'] === 'site_id') {
             return false;
         }
         return $f['type_of_edit'] == Field\Entity::EDIT_NONE;
     });
     foreach ($fields as $f) {
         $list['labels'][$f['keyword']] = $f['name'];
     }
     $finder = fx::content($content_type);
     $pager = $finder->createPager(array('url_template' => $input['url_template'], 'current_page' => $input['page'], 'items_per_page' => 100));
     $items = $finder->all();
     $list['pager'] = $pager->getData();
     $ib_ids = $items->getValues('infoblock_id');
     $infoblocks = fx::data('infoblock', $ib_ids)->indexUnique('id');
     foreach ($items as $item) {
         $r = array('id' => $item['id']);
         $r['type'] = $item['type'];
         $c_ib = $infoblocks->findOne('id', $item['infoblock_id']);
         $r['infoblock'] = $c_ib ? $c_ib['name'] : '-';
         foreach ($fields as $f) {
             $val = $item[$f['keyword']];
             switch ($f['type']) {
                 case Field\Entity::FIELD_LINK:
                     if ($val) {
                         $linked = fx::data($f->getRelatedType(), $val);
                         $val = $linked['name'];
                     }
                     break;
                 case Field\Entity::FIELD_STRING:
                 case Field\Entity::FIELD_TEXT:
                     $val = strip_tags($val);
                     $val = mb_substr($val, 0, 150);
                     break;
                 case Field\Entity::FIELD_IMAGE:
                     $val = fx::image($val, 'max-width:100px,max-height:50px');
                     $val = '<img src="' . $val . '" alt="" />';
                     break;
                 case Field\Entity::FIELD_MULTILINK:
                     $val = fx::alang('%d items', 'system', count($val));
                     break;
             }
             $r[$f['keyword']] = $val;
         }
         $list['values'][] = $r;
     }
     $this->response->addButtons(array(array('key' => "delete", 'content_type' => $content_type)));
     return array('fields' => array('list' => $list));
 }