浏览代码

Add file uploads 8/...

Visman 2 年之前
父节点
当前提交
f454d3ad10

+ 3 - 3
app/Models/Attachment/Attachments.php

@@ -71,8 +71,8 @@ class Attachments extends Manager
         $file->rename(false)->rewrite(false);
 
         if ($file instanceof Image) {
-            $file->setQuality($this->c->config->i_upload_img_quality ?? 75);
-                //->resize($this->c->config->i_avatars_width, $this->c->config->i_avatars_height)
+            $file->setQuality($this->c->config->i_upload_img_quality ?? 75)
+                ->resize($this->c->config->i_upload_img_axis_limit, $this->c->config->i_upload_img_axis_limit);
         }
 
         $status = $file->toFile($location);
@@ -124,7 +124,7 @@ class Attachments extends Manager
             return;
         }
 
-        \preg_match_all('%' . self::FOLDER . '((\d{4})/(\d+)/[\w-]+?_(\d{3})\.[\w-]+)\b%', $post->message, $matches, \PREG_SET_ORDER);
+        \preg_match_all('%' . self::FOLDER . '((\d{4})/(\d+)/[\w-]+?_(\d{3})\.[\w-]+)\b%', $post->message, $matches, \PREG_SET_ORDER); // ???? проверять html?
 
         $attInPost = [];
 

+ 1 - 0
app/Models/Pages/Admin/Install.php

@@ -1572,6 +1572,7 @@ class Install extends Admin
             's_РЕГИСТР'               => 'Ok',
             'b_upload'                => 1,
             'i_upload_img_quality'    => 75,
+            'i_upload_img_axis_limit' => 1920,
         ];
 
         foreach ($forkConfig as $name => $value) {

+ 3 - 2
app/Models/Pages/Admin/Update.php

@@ -610,8 +610,9 @@ class Update extends Admin
     {
         $config = $this->c->config;
 
-        $config->b_upload             = 1;
-        $config->i_upload_img_quality = 75;
+        $config->b_upload                = 1;
+        $config->i_upload_img_quality    = 75;
+        $config->i_upload_img_axis_limit = 1920;
 
         $config->save();
 

+ 15 - 5
app/Models/Pages/Admin/Uploads.php

@@ -33,17 +33,19 @@ class Uploads extends Admin
             $v = $this->c->Validator->reset()
                 ->addValidators([
                 ])->addRules([
-                    'token'                => 'token:AdminUploads',
-                    'b_upload'             => 'required|integer|in:0,1',
-                    'i_upload_img_quality' => 'required|integer|min:0|max:100',
+                    'token'                   => 'token:AdminUploads',
+                    'b_upload'                => 'required|integer|in:0,1',
+                    'i_upload_img_quality'    => 'required|integer|min:0|max:100',
+                    'i_upload_img_axis_limit' => 'required|integer|min:100|max:20000',
                 ])->addAliases([
                 ])->addArguments([
                 ])->addMessages([
                 ]);
 
             if ($v->validation($_POST)) {
-                $this->c->config->b_upload             = $v->b_upload;
-                $this->c->config->i_upload_img_quality = $v->i_upload_img_quality;
+                $this->c->config->b_upload                = $v->b_upload;
+                $this->c->config->i_upload_img_quality    = $v->i_upload_img_quality;
+                $this->c->config->i_upload_img_axis_limit = $v->i_upload_img_axis_limit;
                 $this->c->config->save();
 
                 return $this->c->Redirect->page('AdminUploads')->message('Data updated redirect', FORK_MESS_SUCC);
@@ -88,6 +90,14 @@ class Uploads extends Admin
                             'caption' => 'Upload quality label',
                             'help'    => 'Upload quality help',
                         ],
+                        'i_upload_img_axis_limit' => [
+                            'type'    => 'number',
+                            'min'     => '100',
+                            'max'     => '20000',
+                            'value'   => $config->i_upload_img_axis_limit,
+                            'caption' => 'Upload axis limit label',
+                            'help'    => 'Upload axis limit help',
+                        ],
                     ],
                 ],
             ],

+ 5 - 0
app/Models/Pages/PM/PMEdit.php

@@ -163,6 +163,11 @@ class PMEdit extends AbstractPM
 
         $this->pms->update(Cnst::PTOPIC, $topic);
 
+        // синхронизация вложений
+        if ($this->userRules->useUpload) {
+            $this->c->attachments->syncWithPost($post, true);
+        }
+
         // антифлуд
         if ($calcUser) {
             $this->user->u_pm_last_post = $now;

+ 5 - 0
app/Models/Pages/PM/PMPost.php

@@ -227,6 +227,11 @@ class PMPost extends AbstractPM
 
         $this->pms->update(Cnst::PTOPIC, $topic->calcStat());
 
+        // синхронизация вложений
+        if ($this->userRules->useUpload) {
+            $this->c->attachments->syncWithPost($post);
+        }
+
         // новый диалог в архив
         if (
             $this->newTopic

+ 6 - 0
app/lang/en/admin_uploads.po

@@ -26,3 +26,9 @@ msgstr "Quality"
 
 msgid "Upload quality help"
 msgstr "Images quality between 0 and 100."
+
+msgid "Upload axis limit label"
+msgstr "Axis limit"
+
+msgid "Upload axis limit help"
+msgstr "The uploaded image will be resized if its width/height is greater than this limit."

+ 6 - 0
app/lang/ru/admin_uploads.po

@@ -26,3 +26,9 @@ msgstr "Качество"
 
 msgid "Upload quality help"
 msgstr "Качество изображений от 0 до 100."
+
+msgid "Upload axis limit label"
+msgstr "Ограничение по оси"
+
+msgid "Upload axis limit help"
+msgstr "К загруженному изображению будет применен ресайз, если его ширина/высота больше этого ограничения."