Example #1
0
						<?php 
        if ($file['file_info']['file_type'] == 'image') {
            ?>
							<span class="preview">
							<a class="fancybox" download="<?php 
            echo $file['file_info']['name'];
            ?>
" title="<?php 
            echo $file['file_info']['name'];
            ?>
" href="<?php 
            echo $file['value'];
            ?>
">
								<img style="max-width: 80px; max-height: 80px;" src="<?php 
            echo Helpers_File::image2thumb($file['value']);
            ?>
">
							</a>
							</span>
						<?php 
        }
        ?>
					</td>
					<td>
						<p class="name">
							<a target="_blank" title="<?php 
        echo $file['file_info']['name'];
        ?>
" href="<?php 
        echo $file['value'];
Example #2
0
 protected function after_submit()
 {
     $plugin_orm = null;
     foreach ($this->_plugins as $plugin) {
         $class = get_class($plugin);
         if ($class == 'CM_Form_Plugin_Orm') {
             $plugin_orm = $plugin;
         }
     }
     if (!is_null($plugin_orm)) {
         if (!$this->_model->loaded() && $_POST) {
             $this->_model->save();
         }
         $oldModel = ORM::factory(ucfirst($this->_model->object_name()))->where('id', '=', $this->_model->id)->find();
         foreach ($this->get_field_names() as $field_name) {
             if ($plugin_orm->is_field_ignored($field_name)) {
                 continue;
             }
             if ($this->get_field($field_name)->get_type() == 'file') {
                 $value = $this->get_field($field_name)->get_value()->get_raw();
                 if (preg_match('%/temp/%', $value) || !strlen($value)) {
                     $path = str_replace('//', '/', urldecode(PUBLIC_ROOT . $value));
                     $fileInformation = Helpers_File::getInformation($path);
                     if (is_object($value) || $oldModel->{$field_name} && !preg_match('%/temp/%', $oldModel->{$field_name})) {
                         $oldFile = str_replace('//', '/', PUBLIC_ROOT . $oldModel->{$field_name});
                         if (is_file($oldFile)) {
                             @unlink($oldFile);
                         }
                         $thumbFile = str_replace($this->_model->object_name() . '/' . $this->_model->id, $this->_model->object_name() . '/' . $this->_model->id . '/thumb', $oldFile);
                         if (is_file($thumbFile)) {
                             @unlink($thumbFile);
                         }
                     }
                     $newFileName = md5($fileInformation['filename'] . time());
                     if ($fileInformation['extension']) {
                         $newFileName .= '.' . $fileInformation['extension'];
                     }
                     $objectName = $this->_model->object_name();
                     $uploadDirectory = PUBLIC_ROOT . 'files/' . $objectName . '/' . $this->_model->id;
                     Helpers_File::recursiveCreateDirectory($uploadDirectory);
                     if (!is_dir($path) && file_exists($path)) {
                         copy($path, $uploadDirectory . '/' . $newFileName);
                     }
                     if ($fileInformation['is_image']) {
                         $thumbDirectory = $uploadDirectory . '/' . 'thumb';
                         Helpers_File::recursiveCreateDirectory($thumbDirectory);
                         $thumb = Image::factory($uploadDirectory . '/' . $newFileName);
                         $thumb->resize(80, 80, Image::AUTO)->save($thumbDirectory . '/' . $newFileName);
                     }
                     if (!is_dir($path) && file_exists($path)) {
                         $this->_model->{$field_name} = '/files/' . $objectName . '/' . $this->_model->id . '/' . $newFileName;
                     } else {
                         $this->_model->{$field_name} = "";
                     }
                 }
             }
             if ($this->get_field($field_name)->get_type() == 'multifile') {
                 $multiFiles = array();
                 $value = $this->get_field($field_name)->get_value()->get_raw();
                 $files = array_filter(explode(',', $value), function ($file) {
                     return !!$file;
                 });
                 if (!$files) {
                     $files = array();
                 }
                 $oldFiles = json_decode($oldModel->{$field_name});
                 if (is_array($oldFiles)) {
                     foreach ($oldFiles as $oldFile) {
                         if (!in_array($oldFile, $files)) {
                             if (is_file(PUBLIC_ROOT . $oldFile)) {
                                 @unlink(PUBLIC_ROOT . $oldFile);
                             }
                             $thumbFile = PUBLIC_ROOT . str_replace($this->_model->object_name() . '/' . $this->_model->id, $this->_model->object_name() . '/' . $this->_model->id . '/thumb', $oldFile);
                             if (is_file($thumbFile)) {
                                 @unlink($thumbFile);
                             }
                         }
                     }
                 }
                 foreach ($files as $file) {
                     $path = str_replace('//', '/', urldecode(PUBLIC_ROOT . $file));
                     $fileInformation = Helpers_File::getInformation($path);
                     if (preg_match('%/temp/%', $file)) {
                         $newFileName = md5($fileInformation['filename'] . time());
                         if ($fileInformation['extension']) {
                             $newFileName .= '.' . $fileInformation['extension'];
                         }
                         $objectName = $this->_model->object_name();
                         $uploadDirectory = PUBLIC_ROOT . 'files/' . $objectName . '/' . $this->_model->id;
                         Helpers_File::recursiveCreateDirectory($uploadDirectory);
                         if (!is_dir($path) && file_exists($path)) {
                             copy($path, $uploadDirectory . '/' . $newFileName);
                         }
                         if ($fileInformation['is_image']) {
                             $thumbDirectory = $uploadDirectory . '/' . 'thumb';
                             Helpers_File::recursiveCreateDirectory($thumbDirectory);
                             $thumb = Image::factory($uploadDirectory . '/' . $newFileName);
                             $thumb->resize(80, 80, Image::AUTO)->save($thumbDirectory . '/' . $newFileName);
                         }
                         $multiFiles[] = '/files/' . $objectName . '/' . $this->_model->id . '/' . $newFileName;
                     } elseif ($file) {
                         $multiFiles[] = $file;
                     }
                 }
                 if (isset($multiFiles)) {
                     $this->_model->{$field_name} = json_encode($multiFiles);
                 }
             }
             if ($this->get_field($field_name)->get_type() == 'url') {
                 if ($this->_model->name) {
                     if (!$this->_model->url) {
                         $url = Text::translit($this->_model->name);
                         $url = preg_replace("/[^a-zA-ZА-Яа-я0-9\\s]/", " ", $url);
                         $url = trim($url);
                         $url = preg_replace('%\\s%', '-', $url);
                         $url = preg_replace('%-+%', '-', $url);
                         $url = mb_strtolower($url);
                         $this->_model->url = $url;
                     }
                 }
             }
         }
         $this->_model->save();
     }
 }
Example #3
0
                									<th>#</th>
                									<th>' . __('TYPE') . '</th>
                									<th>' . __('NAME') . '</th>
                									<th>' . __('SIZE') . '</th>
                									<th>' . __('DATE_ADD') . '</th>
              										<th>' . __('FUNCTION') . '</th>
           										</tr>
        									</thead>
        									<tbody>' . "\n";
        $i = 1;
        foreach ($files_list as $key => $value) {
            echo '<tr>' . "\n";
            echo '<td>' . $i . '</td>' . "\n";
            echo '<td>' . Helpers_File::file_icon($value['file_type']) . '</td>' . "\n";
            echo '<td>' . Helpers_File::preview_file($value['folder_director'], $value['file_name'], $value['file_type']) . '</td>' . "\n";
            echo '<td>' . Helpers_File::size($value['file_size']) . '</td>' . "\n";
            echo '<td>' . $value['file_date_add'] . '</td>' . "\n";
            echo '<td><a href="' . URL::site(Request::current()->param('language') . '/admin/files/delete/' . $value['file_id']) . '">' . __('DELETE') . '</td>' . "\n";
            echo '</tr>' . "\n";
            $i++;
        }
        echo '	</tbody>
        								</table>' . "\n";
    } else {
        echo __('NO_DATA_TO_DISPLAY');
    }
}
?>
        				
		
		</div>