Example #1
0
 /**
  * Вывод скриптов
  */
 public function output()
 {
     if ($this->glue) {
         echo HTML::style(File::pathToUri($this->glue()));
     } else {
         foreach ($this as $style) {
             echo HTML::style(File::pathToUri($style)) . "\n";
         }
     }
 }
Example #2
0
 /**
  * Upload one Files
  *
  * @param array $file
  * @return type
  */
 private function uploadOne($path)
 {
     $file = new Core_ArrayObject();
     event('file_url.preupload', $file);
     $file['errors'] = array();
     $file->source = $path;
     $file->ext = pathinfo($path, PATHINFO_EXTENSION);
     strpos($this->options->path, ROOT) !== FALSE or $this->options->path = UPLOADS . DS . $this->options->path;
     if (!($data = file_get_contents($path))) {
         $file->errors[] = t('Не удаётся загрузить файл с указанного URL.');
     } else {
         File::mkdir($this->path);
         if (!is_dir($this->path)) {
             $file['errors'][] = t('Папка загрузки <b>%s</b> не существует.', $this->options->path);
         }
         $file->name = $this->prepareFileName($this->rename ? $this->rename : basename($path));
         $file->path = $this->path . DS . $file->name;
         if ($size = file_put_contents($file->path, $data)) {
             $file->size = $size;
             if ($this->options->allowed_types) {
                 $types = is_string($this->options->allowed_types) ? new Core_ArrayObject(preg_split('#[^a-z]#', $this->options->allowed_types, -1, PREG_SPLIT_NO_EMPTY)) : $this->options->allowed_types;
                 $ext = pathinfo($file->name, PATHINFO_EXTENSION);
                 $result = FALSE;
                 foreach ($types as $type) {
                     $type == $ext && ($result = TRUE);
                 }
                 !$result && ($file['errors'][] = t('Разрешены только следующие типы файлов: <b>%s</b>.', NULL, $types->toString('</b>, <b>')));
             }
             $this->options->maxsize && $this->checkMaxSize($file['size'], $this->options->maxsize);
             if (!$this->options->path) {
                 $file['errors'][] = t('Путь для загрузки файла не указан.');
             }
             if ($file['errors']) {
                 unlink($file->path);
                 return $file;
             } else {
                 $this->uploaded = TRUE;
                 $file->uri_full = File::pathToUri($file->path, ROOT);
                 $file->uri = File::pathToUri($file->path, UPLOADS);
                 return $file;
             }
         }
     }
     return FALSE;
 }
Example #3
0
 /**
  * Сохраняет изображение
  *
  * @return  mixed
  */
 public function result()
 {
     if ($result = $this->image->upload()) {
         $this->is_fetched = TRUE;
         $this->image = $this->image->getInfo();
         $result = File::pathToUri($result->path, UPLOADS);
     } else {
         $this->errors = $this->image->getErrors();
         $this->notices = $this->image->getNotices();
     }
     if ($this->validate()) {
         if ($result) {
             return $result;
         }
         return $this->errors ? FALSE : NULL;
     }
     return FALSE;
 }
Example #4
0
 /**
  * Process elements value from request
  *
  * @return
  */
 public function result()
 {
     $file = new File_Upload($this->options);
     if ($result = $file->upload()) {
         $this->is_fetched = TRUE;
         $result = File::pathToUri($result->path, UPLOADS);
     } else {
         $this->errors = $file->getErrors();
     }
     if (cogear()->input->post($this->name)) {
         return '';
     }
     if ($this->validate()) {
         if ($result) {
             return $result;
         }
         return $this->errors ? FALSE : NULL;
     }
     return FALSE;
 }
Example #5
0
<?php

if ($value) {
    $path = File::pathToUri($value);
    echo icon('download') . ' ' . HTML::a($path, $path);
    ?>
    <label class="checkbox"><input type="checkbox" name="<?php 
    echo $element->name;
    ?>
" value=""/> <?php 
    echo t('Удалить');
    ?>
</label>

    <?php 
} else {
    if ($element->options->multiple) {
        $name = $element->options->name . '[]';
    } else {
        $name = $element->options->name;
    }
    ?>
    <input id="<?php 
    echo $element->id;
    ?>
" type="file" name="<?php 
    echo $name;
    ?>
" <?php 
    if ($element->options->multiple) {
        echo ' multiple';
Example #6
0
    echo template('Errors/templates/empty')->render();
} else {
    ?>
                            <ul class="thumbnails">
                                        <?php 
    foreach ($themes as $theme) {
        if ($theme->theme == $default->theme) {
            continue;
        }
        ?>
                                    <li class="span4">
                                        <div class="thumbnail">
                                            <?php 
        $screenshot = $theme->getScreenshot();
        $info = getimagesize($screenshot);
        $thumbnail = File::pathToUri($screenshot);
        ?>
                                            <a target="_blank" href="<?php 
        echo l() . '?theme=' . $theme->theme;
        ?>
" class="thumbnail" title="<?php 
        echo t('Посмотреть');
        ?>
"><img src="<?php 
        echo $thumbnail;
        ?>
" <?php 
        echo $info[3];
        ?>
/></a>
                                            <div class="caption">
Example #7
0
<?php

$thumb = File::pathToUri(image_preset('image.thumb', UPLOADS . DS . $file->path));
?>
<a class="fancybox sh" href="<?php 
echo $file->getLink();
?>
" class="file-<?php 
echo $file->info->getExtension();
?>
">
    <img src="<?php 
echo $thumb;
?>
">
</a>
Example #8
0
 /**
  * Сохранение индекса
  *
  * @param type $path
  */
 public function save_action()
 {
     $this->hookAdminMenu(1);
     $this->hookAdminMenu(2);
     if ($index = session('admin.lang.index')) {
         if ($path = session('admin.lang.scan.path')) {
             $path .= $this->prepareFilePath();
             $this->updateLangFile($path, $index);
             flash_success(t('Индекс успешно записан в файл <b>%s</b>!', File::pathToUri($path)));
             flash_info(t('Индекс удалён.'));
             cogear()->session->remove('admin.lang.scan.path');
         } else {
             flash_error(t('Не указан путь файла, в который необходимо записать индекс.'));
         }
     } else {
         flash_error(t('Индекс пуст.'));
     }
     back();
 }
Example #9
0
 /**
  * Генерирует код для изображения
  *
  * @param string $file
  */
 public static function getCode($file)
 {
     $file = ROOT . DS . $file;
     $info = getimagesize($file);
     return '<img src="' . File::pathToUri($file) . '" ' . $info[3] . ' alt="">';
 }
Example #10
0
 /**
  * Настройки внешнего вида
  */
 public function admin_settings()
 {
     $this->hookAdminMenu();
     $form = new Form(array('#name' => 'admin.theme.settings', 'title' => array('label' => icon('cogs') . ' ' . t('Настройки')), 'background' => array('#type' => 'fieldset', '#label' => t('Задний фон'), 'background_image' => array('type' => 'image', 'allowed_types' => array('jpg', 'png'), 'maxsize' => '500Kb', 'rewrite' => TRUE, 'rename' => 'background', 'path' => UPLOADS . DS . 'theme', 'label' => t('Изображение'), 'value' => config('theme.background'))), 'save' => array()));
     if ($result = $form->result()) {
         $file = THEMES . DS . config('theme.current') . DS . 'css' . DS . 'background.css';
         if ($this->input->post('background_image')) {
             unlink(UPLOADS . DS . config('theme.background'));
             unlink($file);
             cogear()->set('theme.background', '');
         } else {
             cogear()->set('theme.background', File::pathToUri($result->background_image));
             File::mkdir(dirname($file));
             file_put_contents($file, "body{\r\n                    background: url('/uploads" . config('theme.background') . "') repeat top left;\r\n}");
         }
         flash_success(t('Настройки успешно сохранены!'));
         reload();
     }
     $form->show();
 }
Example #11
0
 /**
  * Process upload
  *
  * @return string
  */
 protected function process($file)
 {
     if (file_exists($file->path) && $this->options->overwrite == FALSE) {
         $filename = pathinfo($file->name, PATHINFO_FILENAME);
         $file->path = str_replace($filename, time() . '_' . $filename, $file->path);
     }
     if (move_uploaded_file($file->tmp_name, $file->path)) {
         $this->uploaded = TRUE;
         $file->uri_full = File::pathToUri($file->path, ROOT);
         $file->uri = File::pathToUri($file->path, UPLOADS);
     }
     return $file;
 }
Example #12
0
<?php

if ($value && file_exists(UPLOADS . $value)) {
    ?>
<div class="image-preview"><img src="<?php 
    echo File::pathToUri($element->options->preset ? image_preset($element->options->preset, UPLOADS . $value) : UPLOADS . $value);
    ?>
"></div>
<label class="checkbox"><input type="checkbox" name="<?php 
    echo $element->name;
    ?>
" value=""/> <?php 
    echo t('Удалить');
    ?>
</label>
<?php 
} else {
    echo HTML::input($element->options);
}
?>