/
Articles.php
executable file
·194 lines (153 loc) · 5.82 KB
/
Articles.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/**
* @copyright Copyright © Gogodigital Srls
* @company Gogodigital Srls - Wide ICT Solutions
* @website http://www.gogodigital.it
* @github https://github.com/cinghie/yii2-articles
* @license GNU GENERAL PUBLIC LICENSE VERSION 3
* @package yii2-articles
* @version 0.6.6
*/
namespace cinghie\articles;
use Yii;
use dektrium\user\models\User;
use yii\base\InvalidParamException;
use yii\base\Module;
use yii\i18n\PhpMessageSource;
class Articles extends Module
{
// Select User Class
public $userClass = User::class;
// Select Article Languages
public $languages = [ 'en-GB' => 'en-GB' ];
// Select Article Language for all other languages
public $languageAll = 'en-GB';
// Show Only Default Language in List Views
public $languageShowOnlyDefault = false;
// Set Google Translate API KEY
public $googleTranslateApiKey = '';
// Select Date Format
public $dateFormat = 'd F Y';
// Select Editor: no-editor, ckeditor, imperavi, tinymce, markdown
public $editor = 'imperavi';
// Select Editor Path To Upload Image
public $editorImagePath = '@webroot/img/articles/';
// Select Editor URL To Upload Image
public $editorImageURL = '@web/img/articles/';
// Select Path To Upload Category Image
public $categoryImagePath = '@webroot/img/articles/categories/';
// Select URL To Upload Category Image
public $categoryImageURL = '@web/img/articles/categories/';
// Select Path To Upload Category Thumb
public $categoryThumbPath = '@webroot/img/articles/categories/thumb/';
// Select URL To Upload Category Image
public $categoryThumbURL = '@web/img/articles/categories/thumb/';
// Select Path To Upload Item Image
public $itemImagePath = '@webroot/img/articles/items/';
// Select URL To Upload Item Image
public $itemImageURL = '@web/img/articles/items/';
// Select Path To Upload Item Thumb
public $itemThumbPath = '@webroot/img/articles/items/thumb/';
// Select URL To Upload Item Thumb
public $itemThumbURL = '@web/img/articles/items/thumb/';
// Select Image Name: categoryname, original, casual
public $imageNameType = 'categoryname';
// Select Image Types allowed
public $imageType = ['png','jpg','jpeg'];
// Select Path To Upload Attachments
public $attachPath = '@webroot/attachments/';
// Select URL To Upload Attachment
public $attachURL = '@web/attachments/';
// Select Attachment Types allowed
public $attachType = ['jpg','jpeg','gif','png','csv','pdf','txt','doc','docs'];
// Active AdvancedTranslation
public $advancedTranslation = true;
// Tab Menu Source
public $tabMenu = '@vendor/cinghie/yii2-articles/views/default/_menu.php';
// Filter Language Default
public $filterLanguageDefault = 'all';
// Model map
public $modelMap = [];
// Show Titles in the views
public $showTitles = true;
// Slugify Options
public $slugifyOptions = [
'separator' => '-',
'lowercase' => true,
'trim' => true,
'rulesets' => [
'default'
]
];
// Thumbnails Options
public $thumbOptions = [
'small' => ['quality' => 100, 'width' => 200, 'height' => 150],
'medium' => ['quality' => 100, 'width' => 300, 'height' => 200],
'large' => ['quality' => 100, 'width' => 400, 'height' => 300],
'extra' => ['quality' => 100, 'width' => 600, 'height' => 400],
];
// Url Rules
public $urlRules = [
'<id:\d+>/<alias:[A-Za-z0-9 -_.]+>' => 'articles/categories/view',
'<cat>/<id:\d+>/<alias:[A-Za-z0-9 -_.]+>' => 'articles/items/view',
'<tags>/<id:\d+>/<alias:[A-Za-z0-9 -_.]+>' => 'articles/tags/view',
];
/**
* @inheritdoc
*
* @throws InvalidParamException
*/
public function init()
{
parent::init();
$this->registerTranslations();
$this->setupImageDirectory();
Yii::$container->set($this->userClass);
}
/**
* Translating module message
*/
public function registerTranslations()
{
if (!isset(Yii::$app->i18n->translations['articles*']))
{
Yii::$app->i18n->translations['articles*'] = [
'class' => PhpMessageSource::class,
'basePath' => __DIR__ . '/messages',
];
}
}
/**
* Setup image directory if it's not exist yet
*
* @throws InvalidParamException
*/
protected function setupImageDirectory()
{
if(!file_exists(Yii::getAlias($this->categoryImagePath))) {
if ( ! mkdir( Yii::getAlias( $this->categoryImagePath ), 0755, true ) && ! is_dir( Yii::getAlias( $this->categoryImagePath ) ) ) {
throw new \RuntimeException( sprintf( 'Directory "%s" was not created', Yii::getAlias( $this->categoryImagePath ) ) );
}
}
if(!file_exists(Yii::getAlias($this->categoryThumbPath))) {
if ( ! mkdir( Yii::getAlias( $this->categoryThumbPath ), 0755, true ) && ! is_dir( Yii::getAlias( $this->categoryThumbPath ) ) ) {
throw new \RuntimeException( sprintf( 'Directory "%s" was not created', Yii::getAlias( $this->categoryThumbPath ) ) );
}
}
if(!file_exists(Yii::getAlias($this->itemImagePath))) {
if ( ! mkdir( Yii::getAlias( $this->itemImagePath ), 0755, true ) && ! is_dir( Yii::getAlias( $this->itemImagePath ) ) ) {
throw new \RuntimeException( sprintf( 'Directory "%s" was not created', Yii::getAlias( $this->itemImagePath ) ) );
}
}
if(!file_exists(Yii::getAlias($this->itemThumbPath))) {
if ( ! mkdir( Yii::getAlias( $this->itemThumbPath ), 0755, true ) && ! is_dir( Yii::getAlias( $this->itemThumbPath ) ) ) {
throw new \RuntimeException( sprintf( 'Directory "%s" was not created', Yii::getAlias( $this->itemThumbPath ) ) );
}
}
if(!file_exists(Yii::getAlias($this->attachPath))) {
if ( ! mkdir( Yii::getAlias( $this->attachPath ), 0755, true ) && ! is_dir( Yii::getAlias( $this->attachPath ) ) ) {
throw new \RuntimeException( sprintf( 'Directory "%s" was not created', Yii::getAlias( $this->attachPath ) ) );
}
}
}
}