Commit 132699e8 authored by Marcello Pivanti's avatar Marcello Pivanti
Browse files

Initial Commit

parents
### REPO DEPRECATA
# Usare Amos Attachments
\ No newline at end of file
{
"name": "arter/amos-upload",
"description": "Gestione Upload - plugin",
"keywords": [
"amos",
"upload",
"file",
"yii2"
],
"homepage": "http://www.elitedivision.it/",
"type": "component",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"require": {
"php": ">=5.4.0",
"arter/amos-core": "*",
"arter/yii2-filemanager": "*"
},
"config": {
"process-timeout": 1800,
"secure-http": false
},
"autoload": {
"psr-4": {
"elitedivision\\amos\\upload\\": "src"
}
},
"scripts": {
"post-install-cmd": [
"php yii migrate --migrationPath=@vendor/pendalf89/yii2-filemanager/migrations --interactive=0",
"php yii migrate --migrationPath=@vendor/amos-upload/migrations --interactive=0"
]
}
}
\ No newline at end of file
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
*
* @package elitedivision\amos\upload
* @category CategoryName
* @author Elite Division S.r.l.
*/
namespace elitedivision\amos\upload;
use pendalf89\filemanager\Module;
class AmosUpload extends Module
{
public $controllerNamespace = 'elitedivision\amos\upload\controllers';
public function init()
{
parent::init(
// initialize the module with the configuration loaded from config.php
\Yii::configure($this, require(__DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')));
}
}
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
*
* @package elitedivision\amos\upload
* @category CategoryName
* @author Elite Division S.r.l.
*/
return [
];
\ No newline at end of file
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
*
* @package elitedivision\amos\upload\i18n\en-GB
* @category CategoryName
* @author Elite Division S.r.l.
*/
return [
'Aggiorna' => 'Update',
'Are you sure you want to delete this item?' => 'Are you sure you want to delete this item?',
'Crea' => 'Create',
'Create {modelClass}' => 'Create {modelClass}',
'Filemanager Mediafiles' => 'Filemanager Mediafiles',
'Filemanager Owners' => 'Filemanager Owners',
'Generale ' => 'General',
'Reset' => 'Reset',
'Search' => 'Search',
'Update {modelClass}: ' => 'Update {modelClass}:',
'Update' => 'Update',
];
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
*
* @package elitedivision\amos\upload\i18n\en-US
* @category CategoryName
* @author Elite Division S.r.l.
*/
return [
'Aggiorna' => 'Update',
'Are you sure you want to delete this item?' => 'Are you sure you want to delete this item?',
'Crea' => 'Create',
'Create {modelClass}' => 'Create {modelClass}',
'Filemanager Mediafiles' => 'Filemanager Mediafiles',
'Filemanager Owners' => 'Filemanager Owners',
'Generale ' => 'General',
'Reset' => 'Reset',
'Search' => 'Search',
'Update {modelClass}: ' => 'Update {modelClass}:',
'Update' => 'Update',
];
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
*
* @package elitedivision\amos\upload\i18n\it-IT
* @category CategoryName
* @author Elite Division S.r.l.
*/
return [
'Aggiorna' => 'Aggiorna',
'Are you sure you want to delete this item?' => 'Vuoi davvero cancellare questo elemento?',
'Crea' => 'Crea',
'Create {modelClass}' => 'Crea {modelClass}',
'Filemanager Mediafiles' => 'Gestore file multimediali',
'Filemanager Owners' => 'Gestore file proprietari',
'Generale ' => 'Generale',
'Reset' => 'Annulla',
'Search' => 'Cerca',
'Update' => 'Aggiorna',
'Update {modelClass}: ' => 'Aggiorna {modelClass}:',
];
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
*
* @package elitedivision\amos\upload
* @category CategoryName
* @author Elite Division S.r.l.
*/
use yii\db\Schema;
class m150804_000001_create_filemanager_mediafile extends \yii\db\Migration
{
const TABLE = '{{%filemanager_mediafile}}';
public function up()
{
if ($this->db->schema->getTableSchema(self::TABLE, true) === null) {
$this->createTable(self::TABLE, [
'id' => Schema::TYPE_PK,
'filename' => Schema::TYPE_STRING . '(255) NOT NULL',
'type' => Schema::TYPE_STRING . '(255) NOT NULL',
'url' => Schema::TYPE_TEXT . ' NOT NULL',
'alt' => Schema::TYPE_TEXT,
'size' => Schema::TYPE_STRING . '(255) NOT NULL',
'description' => Schema::TYPE_TEXT,
'thumbs' => Schema::TYPE_TEXT,
'created_at' => Schema::TYPE_INTEGER . " NOT NULL COMMENT 'Creato il'",
'updated_at' => Schema::TYPE_INTEGER . " NULL DEFAULT NULL COMMENT 'Aggiornato il'",
], $this->db->driverName === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB AUTO_INCREMENT=1' : null);
}
else{
echo "Nessuna creazione eseguita in quanto la tabella esiste già";
return true;
}
}
public function down()
{
if ($this->db->schema->getTableSchema(self::TABLE, true) !== null) {
$this->dropTable(self::TABLE);
}
else{
echo "Nessuna cancellazione eseguita in quanto la tabella non esiste";
return true;
}
}
}
\ No newline at end of file
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
*
* @package elitedivision\amos\upload
* @category CategoryName
* @author Elite Division S.r.l.
*/
namespace elitedivision\amos\upload\models;
use pendalf89\filemanager\models\Mediafile;
use Yii;
use yii\db\Exception;
use yii\helpers\Inflector;
use yii\helpers\ArrayHelper;
use yii\web\UploadedFile;
class FilemanagerMediafile extends Mediafile {
/**
* Save just uploaded file
* @param array $routes routes from module settings
* @param bool $rename
* @return bool
*/
public function saveUploadedFile(array $routes, $rename = false)
{
$year = date('Y', time());
$month = date('m', time());
$structure = "$routes[baseUrl]/$routes[uploadPath]/$year/$month";
$basePath = Yii::getAlias($routes['basePath']);
$absolutePath = "$basePath/$structure";
// create actual directory structure "yyyy/mm"
if (!file_exists($absolutePath)) {
mkdir($absolutePath, 0777, true);
}
// get file instance
$this->file = UploadedFile::getInstance($this, 'file');
//if a file with the same name already exist append a number
$counter = 0;
do{
if($counter==0)
$filename = Inflector::slug($this->file->baseName).'.'. $this->file->extension;
else{
//if we don't want to rename we finish the call here
if($rename == false)
return false;
$filename = Inflector::slug($this->file->baseName). $counter.'.'. $this->file->extension;
}
$url = "$structure/$filename";
$counter++;
} while(self::findByUrl($url)); // checks for existing url in db
$this->evaluateBlackList(NULL, NULL);
// save original uploaded file
$this->file->saveAs("$absolutePath/$filename");
$this->filename = $filename;
$this->type = $this->file->type;
$this->size = $this->file->size;
$this->url = $url;
$return = $this->save();
if ($return && $this->isImage()) {
$this->createThumbs($routes, \Yii::$app->getModule('upload')->thumbs);
}
return $return;
}
public function saveInstanceFiles(array $routes, $rename = false, $uploadedFile)
{
$year = date('Y', time());
$month = date('m', time());
$structure = "$routes[baseUrl]/$routes[uploadPath]/$year/$month";
$basePath = Yii::getAlias($routes['basePath']);
$absolutePath = "$basePath/$structure";
// create actual directory structure "yyyy/mm"
if (!file_exists($absolutePath)) {
mkdir($absolutePath, 0777, true);
}
// get file instance
$this->file = $uploadedFile;
//if a file with the same name already exist append a number
$counter = 0;
do{
if($counter==0)
$filename = Inflector::slug($this->file->baseName).'.'. $this->file->extension;
else{
//if we don't want to rename we finish the call here
if($rename == false)
return false;
$filename = Inflector::slug($this->file->baseName). $counter.'.'. $this->file->extension;
}
$url = "$structure/$filename";
$counter++;
} while(self::findByUrl($url)); // checks for existing url in db
// save original uploaded file
//$this->file->saveAs("$absolutePath/$filename");
$ret = copy($this->file->tempName, "$absolutePath/$filename");
if ($ret){
unlink($this->file->tempName);
}
$this->filename = $filename;
$this->type = $this->file->type;
$this->size = $this->file->size;
$this->url = $url;
return $this->save();
}
/**
* @return array
*/
public function rules()
{
return ArrayHelper::merge(parent::rules(),[
['file', 'evaluateBlackList'],
]);
}
/**
* @param $attribute
* @param $params
*/
public function evaluateBlackList($attribute, $params)
{
$upload_white_list_file_exts = isset(Yii::$app->params['upload_white_list_file_exts']) ? Yii::$app->params['upload_white_list_file_exts']: [];
$upload_black_list_file_mimes = isset(Yii::$app->params['upload_black_list_file_mimes']) ? Yii::$app->params['upload_black_list_file_mimes'] : [];
$file_ext = explode('.',$this->filename);
if(!in_array(end($file_ext),$upload_white_list_file_exts)
|| in_array($this->file->type,$upload_black_list_file_mimes))
{
throw new Exception('Uploading potentially damaging files');
}
}
}
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
*
* @package elitedivision\amos\upload
* @category CategoryName
* @author Elite Division S.r.l.
*/
use yii\helpers\Html;
use kartik\widgets\ActiveForm;
use kartik\builder\Form;
use kartik\datecontrol\DateControl;
use yii\bootstrap\Tabs;
/**
* @var yii\web\View $this
* @var elitedivision\amos\upload\models\FilemanagerMediafile $model
* @var yii\widgets\ActiveForm $form
*/
?>
<div class="filemanager-mediafile-form">
<?php $form = ActiveForm::begin(['type'=>ActiveForm::TYPE_VERTICAL]); ?>
<div class="form-actions">
<?= Html::submitButton( $model->isNewRecord ?
Yii::t('amosupload', 'Crea') :
Yii::t('amosupload', 'Aggiorna'),
[
'class' => $model->isNewRecord ?
'btn btn-success' :
'btn btn-primary'
]); ?>
</div>
<?php $this->beginBlock('generale'); ?>
<div class="clearfix"></div>
<?php $this->endBlock('generale'); ?>
<?php $itemsTab[] = [
'label' => Yii::t('amosupload', 'Generale '),
'content' => $this->blocks['generale'],
];
?>
<?= Tabs::widget(
[
'encodeLabels' => false,
'items' => $itemsTab
]
);
?>
<?php ActiveForm::end(); ?>
</div>
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
*
* @package elitedivision\amos\upload
* @category CategoryName
* @author Elite Division S.r.l.
*/
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
* @var yii\web\View $this
* @var elitedivision\amos\upload\models\FilemanagerMediafileSearch $model
* @var yii\widgets\ActiveForm $form
*/
?>
<div class="filemanager-mediafile-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'filename') ?>
<?= $form->field($model, 'type') ?>
<?= $form->field($model, 'url') ?>
<?= $form->field($model, 'alt') ?>
<?php // echo $form->field($model, 'size') ?>
<?php // echo $form->field($model, 'description') ?>
<?php // echo $form->field($model, 'thumbs') ?>
<?php // echo $form->field($model, 'created_at') ?>
<?php // echo $form->field($model, 'updated_at') ?>
<div class="form-group">
<?= Html::submitButton(Yii::t('amosupload', 'Search'), ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton(Yii::t('amosupload', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
*
* @package elitedivision\amos\upload
* @category CategoryName
* @author Elite Division S.r.l.
*/
use yii\helpers\Html;
/**
* @var yii\web\View $this
* @var elitedivision\amos\upload\models\FilemanagerMediafile $model
*/
$this->title = Yii::t('amosupload', 'Create {modelClass}', [
'modelClass' => 'Filemanager Mediafile',
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('amosupload', 'Filemanager Mediafiles'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="filemanager-mediafile-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
*
* @package elitedivision\amos\upload
* @category CategoryName
* @author Elite Division S.r.l.
*/
use yii\helpers\Html;
use backend\components\views\AmosGridView;
use yii\widgets\Pjax;
/**
* @var yii\web\View $this
* @var yii\data\ActiveDataProvider $dataProvider
* @var elitedivision\amos\upload\models\FilemanagerMediafileSearch $searchModel
*/
$this->title = Yii::t('amosupload', 'Filemanager Mediafiles');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="filemanager-mediafile-index">
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?php /* echo Html::a(Yii::t('amosupload', 'Nuovo {modelClass}', [
'modelClass' => 'Filemanager Mediafile',
]) , ['create'], ['class' => 'btn btn-success'])*/ ?>
</p>
<?php Pjax::begin(); echo AmosGridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'filename',
'type',
'url:ntext',
'alt:ntext',
// 'size',
// 'description:ntext',
// 'thumbs:ntext',
// 'created_at',
// 'updated_at',
[
'class' => 'backend\components\views\grid\ActionColumn',
],
],
]); Pjax::end(); ?>
</div>
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
*
* @package elitedivision\amos\upload
* @category CategoryName
* @author Elite Division S.r.l.
*/
use yii\helpers\Html;
/**
* @var yii\web\View $this
* @var elitedivision\amos\upload\models\FilemanagerMediafile $model
*/
$this->title = Yii::t('amosupload', 'Update {modelClass}: ', [
'modelClass' => 'Filemanager Mediafile',