Example #1
0
 public function forView($options = [])
 {
     $modelName = get_class($this->model);
     $colInfo = $modelName::getColInfo($this->valueKey);
     $type = !empty($colInfo['colParams']['type']) ? $colInfo['colParams']['type'] : 'string';
     switch ($type) {
         case 'dateTime':
             //fall
         //fall
         case 'date':
             $yy = (int) substr($this->model->{$this->valueKey}, 0, 4);
             $mm = (int) substr($this->model->{$this->valueKey}, 5, 2);
             $dd = (int) substr($this->model->{$this->valueKey}, 8, 2);
             $hours = substr($this->model->{$this->valueKey}, 11, 5);
             $month = array('января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря');
             $yearPosrfix = isset($options['yearPostfix']) ? $options['yearPostfix'] : " г.";
             return ($dd > 0 ? $dd . " " : '') . $month[$mm - 1] . " " . $yy . $yearPosrfix . (empty($options['notime']) ? " " . $hours : '');
         case 'select':
             switch ($colInfo['colParams']['source']) {
                 case 'model':
                     $sourceValue = false;
                     if ($this->model->{$this->valueKey}) {
                         $sourceValue = $colInfo['colParams']['model']::get($this->model->{$this->valueKey});
                     }
                     return $sourceValue ? $sourceValue->name() : 'Не задано';
                 case 'array':
                     return !empty($colInfo['colParams']['sourceArray'][$this->model->{$this->valueKey}]) ? $colInfo['colParams']['sourceArray'][$this->model->{$this->valueKey}] : 'Не задано';
                 case 'method':
                     if (!empty($colInfo['colParams']['params'])) {
                         $values = call_user_func_array([App::$cur->{$colInfo}['colParams']['module'], $colInfo['colParams']['method']], $colInfo['colParams']['params']);
                     } else {
                         $values = $colInfo['colParams']['module']->{$colInfo}['colParams']['method']();
                     }
                     return !empty($values[$this->model->{$this->valueKey}]) ? $values[$this->model->{$this->valueKey}] : 'Не задано';
                 case 'relation':
                     $relations = $colInfo['modelName']::relations();
                     $relValue = $relations[$colInfo['colParams']['relation']]['model']::get($this->model->{$this->valueKey});
                     return $relValue ? $relValue->name() : 'Не задано';
             }
             break;
         case 'image':
             $file = Files\File::get($this->model->{$this->valueKey});
             if ($file) {
                 return '<img src="' . $file->path . '?resize=60x120" />';
             } else {
                 return '<img src="/static/system/images/no-image.png?resize=60x120" />';
             }
         case 'bool':
             return $this->model->{$this->valueKey} ? 'Да' : 'Нет';
         default:
             return $this->model->{$this->valueKey};
     }
 }
Example #2
0
 public function siteConfigAction()
 {
     if (isset($_POST['site_name'])) {
         $config = \App::$primary->config;
         $config['site']['name'] = $_POST['site_name'];
         $config['site']['company_name'] = $_POST['company_name'];
         $config['site']['email'] = $_POST['site_email'];
         $config['site']['keywords'] = $_POST['site_keywords'];
         $config['site']['description'] = $_POST['site_description'];
         $config['site']['domain'] = $_POST['site_domain'];
         if (isset($_POST['metatags'])) {
             $config['site']['metatags'] = $_POST['metatags'];
         }
         if (!empty($_FILES['site_logo']['tmp_name'])) {
             $fileId = $this->Files->upload($_FILES['site_logo'], array('file_code' => 'site_logo'));
             $config['site']['site_logo'] = Files\File::get($fileId)->path;
         }
         Config::save('app', $config);
         Tools::redirect('/admin/dashboard/siteConfig', 'Изменения сохранены', 'success');
     }
     $this->view->setTitle('Общие настройки сайта');
     $this->view->page();
 }
Example #3
0
  <div class="row panel">
    <?php 
if (!empty($_FILES['file'])) {
    App::$cur->files->upload($_FILES['file'], ['upload_code' => 'editorManager']);
}
$form = new Ui\Form();
$form->begin();
$form->input('file', 'file', 'Загрузить файл');
echo '<div class="form-group"><button class ="btn btn-primary btn-sm">Загузить</button></div>';
$form->end(false);
?>
  </div>
  <h2>Последние файлы</h2>
  <div class="row">
    <?php 
$files = Files\File::getList(['where' => ['upload_code', 'editorManager'], 'limit' => 12, 'order' => ['date_create', 'DESC']]);
$i = 0;
foreach ($files as $file) {
    ?>
        <div class="col-xs-6 col-sm-2 fileChooser" onclick="OpenFile('<?php 
    echo $file->path;
    ?>
');
                      return false;">
          <div class="thumbnail">
            <?php 
    if ($file->type->group == 'image') {
        echo "<img class='img-responsive' src ='{$file->path}?resize=200x200' />";
    } else {
        echo "<img class='img-responsive' src ='/static/moduleAsset/Files/images/formats/" . pathinfo($file->path, PATHINFO_EXTENSION) . ".png' />";
    }
Example #4
0
 public function giveFile($file)
 {
     if (!file_exists($file) && file_exists(mb_convert_encoding($file, 'Windows-1251', 'UTF-8'))) {
         $file = mb_convert_encoding($file, 'Windows-1251', 'UTF-8');
     }
     if (!file_exists($file)) {
         header('HTTP/1.1 404 Not Found');
         exit;
     }
     $fileinfo = pathinfo($file);
     if (empty($fileinfo['extension'])) {
         header('HTTP/1.1 404 Not Found');
         exit;
     }
     if (!empty($_GET['resize'])) {
         $allow_resize = false;
         if (App::$cur->db->connect) {
             $type = Files\Type::get($fileinfo['extension'], 'ext');
             $allow_resize = $type->allow_resize;
         }
         if (!$type && in_array(strtolower($fileinfo['extension']), array('png', 'jpg', 'jpeg', 'gif'))) {
             $allow_resize = true;
         }
         if ($allow_resize) {
             $sizes = explode('x', $_GET['resize']);
             $sizes[0] = intval($sizes[0]);
             if (isset($sizes[1])) {
                 $sizes[1] = intval($sizes[1]);
             } else {
                 $sizes[1] = 0;
             }
             if (!$sizes[0] || !$sizes[1]) {
                 header('HTTP/1.1 404 Not Found');
                 exit;
             } elseif ($sizes[0] > 2000 || $sizes[1] > 2000) {
                 header('HTTP/1.1 404 Not Found');
                 exit;
             } else {
                 $dir = App::$primary->path;
                 if (!empty($_GET['resize_crop'])) {
                     if (in_array($_GET['resize_crop'], array('q', 'c'))) {
                         $crop = $_GET['resize_crop'];
                     } else {
                         $crop = 'c';
                     }
                 } elseif (!empty($_GET['resize_quadro'])) {
                     $crop = 'q';
                 } else {
                     $crop = '';
                 }
                 $pos = 'center';
                 if (!empty($_GET['resize_pos']) && in_array($_GET['resize_pos'], array('top', 'center'))) {
                     $pos = $_GET['resize_pos'];
                 }
                 $dirnoslash = str_replace('/', '', substr($fileinfo['dirname'], strpos($fileinfo['dirname'], '/static')));
                 $path = $dir . '/static/cache/' . $dirnoslash . $fileinfo['filename'] . '.' . $sizes[0] . 'x' . $sizes[1] . $crop . $pos . '.' . $fileinfo['extension'];
                 if (!file_exists($path)) {
                     Tools::createDir($dir . '/static/cache/');
                     copy($file, $path);
                     Tools::resizeImage($path, $sizes[0], $sizes[1], $crop, $pos);
                 }
                 $file = $path;
             }
         }
     }
     $request = getallheaders();
     if (isset($request['If-Modified-Since'])) {
         // Разделяем If-Modified-Since (Netscape < v6 отдаёт их неправильно)
         $modifiedSince = explode(';', $request['If-Modified-Since']);
         // Преобразуем запрос клиента If-Modified-Since в таймштамп
         $modifiedSince = strtotime($modifiedSince[0]);
     } else {
         // Устанавливаем время модификации в ноль
         $modifiedSince = 0;
     }
     header("Cache-control: public");
     header("Accept-Ranges: bytes");
     header("Pragma: public");
     header("Content-Length: " . filesize($file));
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($file)) . ' GMT');
     header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 60 * 60 * 24 * 256) . ' GMT');
     if (filemtime($file) <= $modifiedSince && (!isset($_SERVER['HTTP_CACHE_CONTROL']) || $_SERVER['HTTP_CACHE_CONTROL'] != 'no-cache')) {
         // Разгружаем канал передачи данных!
         header('HTTP/1.1 304 Not Modified');
         exit;
     }
     //if( strpos( $file, '/static/doc' ) !== false ) {
     header('Content-Description: File Transfer');
     //}
     if (isset($this->mimes[strtolower($fileinfo['extension'])])) {
         header("Content-Type: " . $this->mimes[strtolower($fileinfo['extension'])]);
     }
     if (isset($_GET['frustrate_dl']) || in_array($fileinfo['extension'], array('doc', 'docx', 'xls', 'xlsx'))) {
         $fileName = $fileinfo['filename'] . '.' . $fileinfo['extension'];
         if (App::$cur->db->connect) {
             $fileObj = Files\File::get(['path', '%/' . $fileinfo['filename'] . '.' . $fileinfo['extension'], 'LIKE']);
             if ($fileObj) {
                 $fileName = $fileObj->original_name;
             }
         }
         header('Content-Disposition: attachment; filename="' . $fileName . '"');
     }
     header('Content-Transfer-Encoding: binary');
     //}
     readfile($file);
     exit;
 }
Example #5
0
 public function viewAction()
 {
     $args = func_get_args();
     $alias = trim(implode('/', $args));
     $material = false;
     if ($alias) {
         if (is_numeric($alias)) {
             $material = Materials\Material::get($alias);
         }
         if (!$material) {
             $material = Materials\Material::get($alias, 'alias');
             if (!$material) {
                 Tools::header('404');
                 $this->view->page(['content' => '404', 'data' => ['text' => 'Такой страницы не найдено']]);
                 exit;
             }
         }
     }
     if ($material->keywords) {
         $this->view->addMetaTag(['name' => 'keywords', 'content' => $material->keywords]);
     }
     if ($material->description) {
         $this->view->addMetaTag(['name' => 'description', 'content' => $material->description]);
     }
     $this->view->addMetaTag(['property' => 'og:title', 'content' => $material->name]);
     $this->view->addMetaTag(['property' => 'og:url', 'content' => 'http://' . idn_to_utf8(INJI_DOMAIN_NAME) . '/' . $material->alias]);
     if ($material->description) {
         $this->view->addMetaTag(['property' => 'og:description', 'content' => 'http://' . idn_to_utf8(INJI_DOMAIN_NAME) . '/' . $material->description]);
     }
     if ($material->image) {
         $this->view->addMetaTag(['property' => 'og:image', 'content' => 'http://' . idn_to_utf8(INJI_DOMAIN_NAME) . $material->image->path]);
     } elseif ($logo = Files\File::get('site_logo', 'code')) {
         $this->view->addMetaTag(['property' => 'og:image', 'content' => 'http://' . idn_to_utf8(INJI_DOMAIN_NAME) . $logo->path]);
     }
     $this->view->setTitle($material->name);
     $bread[] = ['text' => $material->name, 'href' => '/' . $material->alias];
     $this->view->page(['page' => $material->resolveTemplate(), 'content' => $material->resolveViewer(), 'data' => compact('material', 'bread')]);
 }
Example #6
0
                    if (!empty($colInfo['colParams']['params'])) {
                        $values = call_user_func_array([App::$cur->{$colInfo}['colParams']['module'], $colInfo['colParams']['method']], $colInfo['colParams']['params']);
                    } else {
                        $values = App::$primary->{$colInfo}['colParams']['module']->{$colInfo}['colParams']['method']();
                    }
                    $value = !empty($values[$item->{$colName}]) ? $values[$item->{$colName}] : 'Не задано';
                    break;
                case 'relation':
                    $relations = $colInfo['modelName']::relations();
                    $relValue = $relations[$colInfo['colParams']['relation']]['model']::get($item->{$colName});
                    $value = $relValue ? "<a href='/admin/" . str_replace('\\', '/view/', $relations[$colInfo['colParams']['relation']]['model']) . "/" . $relValue->pk() . "'>" . $relValue->name() . "</a>" : 'Не задано';
                    break;
            }
            break;
        case 'image':
            $file = Files\File::get($item->{$colName});
            if ($file) {
                $value = '<img src="' . $file->path . '?resize=60x120" />';
            } else {
                $value = '<img src="/static/system/images/no-image.png?resize=60x120" />';
            }
            break;
        case 'bool':
            $value = $item->{$colName} ? 'Да' : 'Нет';
            break;
        default:
            $value = $item->{$colName};
            break;
    }
    $table->addRow([!empty($modelName::$labels[$colName]) ? $modelName::$labels[$colName] : $colName, $value]);
}
Example #7
0
 /**
  * Retrun value for view
  * 
  * @param Model $item
  * @param string $colName
  * @param boolean $manageHref
  * @return string
  */
 public static function resloveTypeValue($item, $colName, $manageHref = false)
 {
     $modelName = get_class($item);
     $colInfo = $modelName::getColInfo($colName);
     $type = !empty($colInfo['colParams']['type']) ? $colInfo['colParams']['type'] : 'string';
     $value = '';
     switch ($type) {
         case 'select':
             switch ($colInfo['colParams']['source']) {
                 case 'model':
                     $sourceValue = '';
                     if ($item->{$colName}) {
                         $sourceValue = $colInfo['colParams']['model']::get($item->{$colName});
                     }
                     $value = $sourceValue ? $sourceValue->name() : 'Не задано';
                     break;
                 case 'array':
                     $value = !empty($colInfo['colParams']['sourceArray'][$item->{$colName}]) ? $colInfo['colParams']['sourceArray'][$item->{$colName}] : 'Не задано';
                     if (is_array($value) && $value['text']) {
                         $value = $value['text'];
                     }
                     break;
                 case 'bool':
                     return $item->{$colName} ? 'Да' : 'Нет';
                 case 'method':
                     if (!empty($colInfo['colParams']['params'])) {
                         $values = call_user_func_array([App::$cur->{$colInfo}['colParams']['module'], $colInfo['colParams']['method']], $colInfo['colParams']['params']);
                     } else {
                         $values = $colInfo['colParams']['module']->{$colInfo}['colParams']['method']();
                     }
                     $value = !empty($values[$item->{$colName}]) ? $values[$item->{$colName}] : 'Не задано';
                     break;
                 case 'void':
                     if (!empty($modelName::$cols[$colName]['value']['type']) && $modelName::$cols[$colName]['value']['type'] == 'moduleMethod') {
                         return \App::$cur->{$modelName::$cols[$colName]['value']['module']}->{$modelName::$cols[$colName]['value']['method']}($item, $colName, $modelName::$cols[$colName]);
                     }
                     break;
                 case 'relation':
                     $relations = $colInfo['modelName']::relations();
                     $relValue = $relations[$colInfo['colParams']['relation']]['model']::get($item->{$colName});
                     $relModel = $relations[$colInfo['colParams']['relation']]['model'];
                     $relModel = strpos($relModel, '\\') === 0 ? substr($relModel, 1) : $relModel;
                     if ($manageHref) {
                         $value = $relValue ? "<a href='/admin/" . str_replace('\\', '/view/', $relModel) . "/" . $relValue->pk() . "'>" . $relValue->name() . "</a>" : 'Не задано';
                     } else {
                         $value = $relValue ? $relValue->name() : 'Не задано';
                     }
                     break;
             }
             break;
         case 'image':
             $file = Files\File::get($item->{$colName});
             if ($file) {
                 $value = '<img src="' . $file->path . '?resize=60x120" />';
             } else {
                 $value = '<img src="/static/system/images/no-image.png?resize=60x120" />';
             }
             break;
         case 'bool':
             $value = $item->{$colName} ? 'Да' : 'Нет';
             break;
         case 'void':
             if (!empty($colInfo['colParams']['value']['type']) && $colInfo['colParams']['value']['type'] == 'moduleMethod') {
                 return \App::$cur->{$colInfo['colParams']['value']['module']}->{$colInfo['colParams']['value']['method']}($item, $colName, $colInfo['colParams']);
             }
             break;
         case 'dynamicType':
             switch ($colInfo['colParams']['typeSource']) {
                 case 'selfMethod':
                     $type = $item->{$colInfo['colParams']['selfMethod']}();
                     if (is_array($type)) {
                         if (strpos($type['relation'], ':')) {
                             $relationPath = explode(':', $type['relation']);
                             $relationName = array_pop($relationPath);
                             $curItem = $item;
                             foreach ($relationPath as $path) {
                                 $curItem = $curItem->{$path};
                             }
                             $itemModel = get_class($curItem);
                             $relation = $itemModel::getRelation($relationName);
                             $sourceModel = $relation['model'];
                         } else {
                             $relation = static::getRelation($type['relation']);
                             $sourceModel = $relation['model'];
                         }
                         $inputType = 'select';
                         $value = $sourceModel::get($item->{$colName});
                         if ($value) {
                             $value = $value->name();
                         } else {
                             $value = $item->{$colName};
                         }
                     } else {
                         $value = $item->{$colName};
                     }
                     break;
             }
             break;
         default:
             $value = $item->{$colName};
             break;
     }
     return $value;
 }
Example #8
0
 /**
  * Загрузка файлов по урл
  * 
  * $url - адрес файла
  * $options - массив из опций заливки 
  * --	[file_code]: уникальный код для системы медиаданых
  * --	[allow_types]: досупные для заливки типы файлов. Например image (тип форматов из таблицы типов файлов file_type_ext)
  */
 public function uploadFromUrl($url, $options = [])
 {
     $sitePath = App::$primary->path;
     $fileinfo = pathinfo($url);
     if (empty($fileinfo['extension'])) {
         return 0;
     }
     $type = Files\Type::get($fileinfo['extension'], 'ext');
     if (!$type) {
         return 0;
     }
     if (!empty($options['accept_group']) && $options['accept_group'] != $type->group) {
         return 0;
     }
     $fileObject = new Files\File();
     if (!empty($options['file_code'])) {
         $fileObject = Files\File::get($options['file_code'], 'code');
         if (!$fileObject) {
             $fileObject = new Files\File();
             $fileObject->code = $options['file_code'];
         }
     }
     $fileObject->name = $fileinfo['filename'];
     $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension'];
     if ($fileObject->id && file_exists($sitePath . $fileObject->path)) {
         unlink($sitePath . $fileObject->path);
     }
     Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/');
     $file = @file_get_contents($url);
     if ($file === false) {
         return 0;
     }
     file_put_contents($sitePath . $fileObject->path, $file);
     $fileObject->type_id = $type->pk();
     $fileObject->original_name = $fileinfo['basename'];
     $fileObject->upload_code = !empty($options['upload_code']) ? $options['upload_code'] : 'untracked';
     $fileObject->save();
     return $fileObject->id;
 }