Issues (1177)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

application/modules/gallery/admin.php (7 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
if (!defined('BASEPATH')) {
4
    exit('No direct script access allowed');
5
}
6
7
/**
8
 * ImageCMS
9
 *
10
 * Gallery Module _Admin_
11
 */
12
//class Admin extends MY_Controller {
13
class Admin extends BaseAdminController
14
{
15
16
    // Gallery config
17
    public $conf = [
18
                    'engine'                  => 'gd2', // Image library. Possible values: GD, GD2, ImageMagick, NetPBM
19
                    'max_file_size'           => 5, // Max file size for upload in Mb.
20
                    'max_archive_size'        => 50,
21
                    'max_width'               => 0, // Max image width.
22
                    'max_height'              => 0, // Max image height.
23
                    'allowed_types'           => 'gif|jpg|jpeg|png|zip', // Allowed image types.
24
                    'allowed_archive_types'   => 'zip',
25
                    'upload_path'             => './uploads/gallery/', // Image upload dir. With ending slash.
26
                    'upload_url'              => 'uploads/gallery/', // Image upload url. With ending slash.
27
                    'cache_path'              => './system/cache/',
28
                    'quality'                 => '90%', // Image quality
29
                    'thumb_width'             => '100', // Thumb width. min. 20px; max 1000px;
30
                    'thumb_height'            => '100', // Thumb height min. 20px; max 1000px;
31
                    'thumb_marker'            => '', // Thumb suffix
32
                    'thumbs_folder'           => '_thumbs', // Thumbs folder name. ! Without ending slash.
33
                    'prev_img_marker'         => '_prev', // Preview image suffix
34
                    'maintain_ratio'          => TRUE, // Specifies whether to maintain the original aspect ratio when resizing.
35
                    'maintain_ratio_prev'     => TRUE, // Specifies whether to maintain the original aspect ratio when resizing prev image.
36
                    'maintain_ratio_icon'     => TRUE, // Specifies whether to maintain the original aspect ratio when resizing icon.
37
                    'crop'                    => TRUE, // Specifies whether to crop image for save the original aspect ratio when resizing.
38
                    'crop_prev'               => TRUE, // Specifies whether to crop image for save the original aspect ratio when resizing prev image.
39
                    'crop_icon'               => TRUE, // Specifies whether to crop image for save the original aspect ratio when resizing icon.
40
                    'prev_img_width'          => '500', // Preview image width
41
                    'prev_img_height'         => '375', // Preview image height
42
        // Watermark params
43
                    'watermark_text'          => '', // Watermark text.
44
                    'watermark_image'         => '', // Path to watermark image.
45
                    'watermark_image_opacity' => '', // Watermark image opacity.
46
                    'watermark_type'          => 'overlay', // Watermark type. Possible values: text/overlay.
47
                    'wm_vrt_alignment'        => 'bottom', // Watermark vertical position. Possible values: top, middle, bottom.
48
                    'wm_hor_alignment'        => 'right', // Watermark horizontal position. Possible values: left, center, right.
49
                    'watermark_font_path'     => './system/fonts/1.ttf', // Path to watermark font.
50
                    'watermark_font_size'     => 16, // Watermark font size.
51
                    'watermark_padding'       => '-5', // Watermark padding.
52
                    'watermark_color'         => 'ffffff', // Watermark font color.
53
                    'watermark_min_width'     => '10', // Min. image width to draw watermark.
54
                    'watermark_min_height'    => '10', // Min. image height to draw watermark.
55
        // Albums
56
                    'order_by'                => 'date', // Albums order. Posiible values: date/name/position.
57
                    'sort_order'              => 'desc',// Sort order. Possible values: desc/asc.
58
                   ];
59
60
    protected $lastnewid;
61
62
    public function __construct() {
63
        parent::__construct();
64
        $lang = new MY_Lang();
65
        $lang->load('gallery');
66
67
        if ($this->dx_auth->is_admin() == FALSE) {
68
            exit;
69
        }
70
71
        $this->lang->load('gallery');
72
73
        $this->load->model('gallery_m');
74
        $this->init_settings();
75
76
        $this->test_uploads_folder($this->conf['upload_path']);
77
        $this->load->helper('file');
78
        $this->load->helper('gallery');
79
    }
80
81
    /**
82
     * Test if gallery upload folder exists.
83
     */
84
    private function test_uploads_folder($path) {
85
        if (!file_exists($path)) {
86
            @mkdir($path);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
87
            @chmod($path, 0777);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
88
        }
89
90
        if (!is_really_writable($this->conf['upload_path']) OR !file_exists($this->conf['upload_path'])) {
91
92
            \CMSFactory\assetManager::create()
93
                ->setData(
94
                    [
95
                     'error' => lang('Create a directory to continue your work with the gallery', 'gallery') . $this->conf['upload_path'] . lang('Set the write access', 'gallery'),
96
                    ]
97
                )
98
                ->renderAdmin('error');
99
            exit;
100
        }
101
    }
102
103
    /**
104
     * Load gallery settings
105
     */
106
    private function init_settings() {
107
        $settings = $this->gallery_m->load_settings();
108
109
        foreach ($settings as $k => $v) {
110
            $this->conf[$k] = $v;
111
        }
112
113
        return TRUE;
114
    }
115
116
    /**
117
     * Display categories list
118
     */
119
    public function index() {
120
121
        $categories = $this->gallery_m->get_categories('position', 'asc');
122
123
        \CMSFactory\assetManager::create()
124
            ->setData(
125
                ['categories' => $categories]
126
            )
127
            ->renderAdmin('categories');
128
    }
129
130
    /**
131
     * Display category albums
132
     */
133
    public function category($id) {
134
        $albums = $this->gallery_m->get_albums('position', 'asc', $id);
135
136
        if ($albums != FALSE) {
137
            $cnt = count($albums);
138
139
            for ($i = 0; $i < $cnt; $i++) {
140
                // Create url to album cover
141
                $albums[$i]['cover_url'] = media_url($upload_url . $albums[$i]['id'] . '/' . $albums[$i]['cover_name'] . $albums[$i]['cover_ext']);
142
143
                $upload_url = $this->conf['upload_url'];
144
145
                if ($albums[$i]['cover_name'] == NULL) {
146
                    $image = $this->gallery_m->get_last_image($albums[$i]['id']);
147
148
                    if ($image != FALSE) {
149
                        $albums[$i]['cover_url'] = media_url($upload_url . $albums[$i]['id'] . '/' . $image['file_name'] . $image['file_ext']);
150
                    } else {
151
                        $albums[$i]['cover_url'] = 'empty';
152
                    }
153
                } else {
154
                    $albums[$i]['cover_url'] = media_url($upload_url . $albums[$i]['id'] . '/' . $albums[$i]['cover_name'] . $albums[$i]['cover_ext']);
155
                }
156
            }
157
158
            $this->template->add_array([]);
159
        }
160
161
        \CMSFactory\assetManager::create()
162
            ->setData(
163
                [
164
                 'albums'   => $albums,
165
                 'category' => $this->gallery_m->get_category($id),
166
                ]
167
            )
168
            ->renderAdmin('album_list');
169
    }
170
171
    /**
172
     * Display settings.tpl and update seetings.
173
     */
174
    public function settings($action = 'show') {
175
176
        switch ($action) {
177
            case 'show':
178
                \CMSFactory\assetManager::create()
179
                    ->setData(
180
                        [
181
                         'settings' => $this->gallery_m->load_settings(),
182
                        ]
183
                    )
184
                    ->renderAdmin('settings');
185
                break;
186
187
            case 'update':
188
189
                $this->load->library('Form_validation');
190
                $val = $this->form_validation;
191
192
                $val->set_rules('max_image_size', lang('File size', 'gallery'), 'required|is_natural');
193
                $val->set_rules('max_width', lang('Maximum width', 'gallery'), 'required|is_natural');
194
                $val->set_rules('max_height', lang('Maximum height', 'gallery'), 'required|is_natural');
195
                $val->set_rules('quality', lang('Quality', 'gallery'), 'required|is_natural');
196
                $val->set_rules('prev_img_width', lang('Pre-image width', 'gallery'), 'required|is_natural');
197
                $val->set_rules('prev_img_height', lang('pre-image height', 'gallery'), 'required|is_natural');
198
                $val->set_rules('thumb_width', lang('Icon width', 'gallery'), 'required|is_natural');
199
                $val->set_rules('thumb_height', lang('Icon height', 'gallery'), 'required|is_natural');
200
                $val->set_rules('watermark_text', lang('Watermark text', 'gallery'), 'max_length[100]');
201
                $val->set_rules('watermark_font_size', lang('Font size', 'gallery'), 'required|is_natural');
202
                $val->set_rules('watermark_image_opacity', lang('Transparency', 'gallery'), 'required|is_natural|min_length[1]|max_length[3]');
203
204
                if ($this->form_validation->run($this) == FALSE) {
205
                    showMessage(validation_errors(), false, 'r');
206
                    break;
207
                }
208
209
                // Check if watermark image exists.
210
                if ($this->input->post('watermark_type') == 'overlay' && !file_exists('.' . $this->input->post('watermark_image'))) {
211
                    showMessage(lang('Specify the correct path to watermark image', 'gallery'), false, 'r');
212
                    break;
213
                }
214
215
                if (file_exists('./uploads/' . $this->input->post('watermark_image'))) {
216
                    $imagePath = './uploads/' . trim($this->input->post('watermark_image'));
217
                } elseif (file_exists('.' . $this->input->post('watermark_image'))) {
218
                    $imagePath = trim('.' . $this->input->post('watermark_image'));
219
                }
220
221
                // Check if watermark font exists.
222
                $params = [
223
                           'max_image_size'          => $this->input->post('max_image_size'),
224
                           'max_width'               => $this->input->post('max_width'),
225
                           'max_height'              => $this->input->post('max_height'),
226
                           'quality'                 => $this->input->post('quality'),
227
                           'maintain_ratio'          => (bool) $this->input->post('maintain_ratio'),
228
                           'maintain_ratio_prev'     => (bool) $this->input->post('maintain_ratio_prev'),
229
                           'maintain_ratio_icon'     => (bool) $this->input->post('maintain_ratio_icon'),
230
                           'crop'                    => (bool) $this->input->post('crop'),
231
                           'crop_prev'               => (bool) $this->input->post('crop_prev'),
232
                           'crop_icon'               => (bool) $this->input->post('crop_icon'),
233
                           'prev_img_width'          => $this->input->post('prev_img_width'),
234
                           'prev_img_height'         => $this->input->post('prev_img_height'),
235
                           'thumb_width'             => $this->input->post('thumb_width'),
236
                           'thumb_height'            => $this->input->post('thumb_height'),
237
                    // watermark settings
238
                           'watermark_text'          => trim($this->input->post('watermark_text')),
239
                           'wm_vrt_alignment'        => $this->input->post('wm_vrt_alignment'),
240
                           'wm_hor_alignment'        => $this->input->post('wm_hor_alignment'),
241
                           'watermark_font_size'     => trim($this->input->post('watermark_font_size')),
242
                           'watermark_color'         => trim($this->input->post('watermark_color')),
243
                           'watermark_padding'       => trim($this->input->post('watermark_padding')),
244
                           'watermark_image'         => $imagePath,
245
                           'watermark_image_opacity' => trim($this->input->post('watermark_image_opacity')),
246
                           'watermark_type'          => trim($this->input->post('watermark_type')),
247
                           'order_by'                => $this->input->post('order_by'),
248
                           'sort_order'              => $this->input->post('sort_order'),
249
                          ];
250
                $uploadPath = './uploads/';
251
                $this->load->library(
252
                    'upload',
253
                    [
254
                     'upload_path'   => $uploadPath,
255
                     'max_size'      => 1024 * 1024 * 2, //2 Mb
256
                        //'allowed_types' => 'ttf|fnt|fon|otf'
257
                     'allowed_types' => '*',
258
                    ]
259
                );
260
                // saving font file, if specified
261
                if (isset($_FILES['watermark_font_path'])) {
262
                    $uploadPath = './uploads/';
263
                    // TODO: there are no mime-types for fonts in application/config/mimes.php
264
                    $allowedTypes = [
265
                                     'ttf',
266
                                     'fnt',
267
                                     'fon',
268
                                     'otf',
269
                                    ];
270
                    $ext = pathinfo($_FILES['watermark_font_path']['name'], PATHINFO_EXTENSION);
271
                    if (in_array($ext, $allowedTypes)) {
272 View Code Duplication
                        if (!$this->upload->do_upload('watermark_font_path')) {
273
                            $this->upload->display_errors('', '');
274
                        } else {
275
                            $udata = $this->upload->data();
276
                            // changing value in the DB
277
                            $params['watermark_font_path'] = $uploadPath . $udata['file_name'];
278
                        }
279
                    }
280
                } else {
281
                    $params['watermark_font_path'] = trim($this->input->post('watermark_font_path_tmp'));
282
                }
283
284
                $postData = $this->input->post();
285
                if ($postData['watermark']['delete_watermark_font_path'] == 1) {
286
                    $path = trim($this->input->post('watermark_font_path_tmp'));
287
                    if (file_exists($path) && !is_dir($path)) {
288
                        chmod($path, 0777);
289
                        unlink($path);
290
                    }
291
292
                    $params['watermark_font_path'] = '';
293
                }
294
295
                $this->db->where('name', 'gallery');
296
                $this->db->update('components', ['settings' => serialize($params)]);
297
298
                $this->lib_admin->log(lang('Gallery settings was edited', 'gallery'));
299
                showMessage(lang('Settings have been saved', 'gallery'));
300
301
                break;
302
        }
303
    }
304
305
    // --------------------------------------------------------------------
306
307
    /**
308
     * Create album
309
     */
310
    public function create_album() {
311
        $this->load->library('Form_validation');
312
313
        $this->form_validation->set_rules('name', lang('Name', 'gallery'), 'required|min_length[3]|max_length[250]');
314
        $this->form_validation->set_rules('email', lang('Description', 'gallery'), 'max_length[500]');
315
        $this->form_validation->set_rules('category_id', lang('Categories', 'gallery'), 'required');
316
317
        if ($this->form_validation->run($this) == FALSE) {
318
            showMessage(validation_errors(), false, 'r');
319
        } else {
320
            $album_id = $this->gallery_m->create_album();
321
322
            // Create album folder
323
            @mkdir($this->conf['upload_path'] . $album_id);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
324
325
            chmod($this->conf['upload_path'] . $album_id, 0777);
326
327
            // Create thumbs folder
328
            @mkdir($this->conf['upload_path'] . $album_id . '/' . $this->conf['thumbs_folder']);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
329
330
            // Create folder for admin thumbs
331
            @mkdir($this->conf['upload_path'] . $album_id . '/_admin_thumbs');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
332
333
            $this->lib_admin->log(lang('Gallery album was created', 'gallery'));
334
            showMessage(lang('Album created', 'gallery'));
335
336
            $this->input->post('action') ? $action = $this->input->post('action') : $action = 'edit';
337
338
            if ($action == 'edit') {
339
                pjax(site_url('admin/components/cp/gallery/edit_album_params/' . $album_id));
340
            }
341
342
            if ($action == 'exit') {
343
                pjax('/admin/components/cp/gallery/category/' . $this->input->post('category_id'));
344
            }
345
        }
346
    }
347
348
    /**
349
     * Update album info
350
     */
351
    public function update_album($id, $locale) {
352
        $this->form_validation->set_rules('name', lang('Name', 'gallery'), 'required');
353
        $tpl_file = $this->input->post('tpl_file');
354
        if (!preg_match('/[a-z]/', $tpl_file) && !empty($tpl_file)) {
355
            showMessage('wrong tpl name', '', 'r');
356
            exit();
357
        }
358
        if ($this->form_validation->run() == false) {
359
            showMessage(validation_errors(), '', 'r');
360
            exit();
361
        } else {
362
            $this->lib_admin->log(lang('Gallery album was updated', 'gallery') . '. Id: ' . $id);
363
            showMessage(lang('Changes have been saved', 'gallery'));
364
        }
365
366
        $data = [
367
                 'category_id' => (int) $this->input->post('cat_id'),
368
            // 'name' => $this->input->post('name'),
369
            // 'description' => trim($this->input->post('description')),
370
                 'position'    => (int) $this->input->post('position'),
371
                 'tpl_file'    => $this->input->post('tpl_file'),
372
                ];
373
374
        $this->gallery_m->update_album($id, $data);
375
376
        $data_locale = [
377
                        'id'          => $id,
378
                        'locale'      => $locale,
379
                        'name'        => $this->input->post('name'),
380
                        'description' => trim($this->input->post('description')),
381
                       ];
382
383 View Code Duplication
        if ($this->db->where('id', $id)->where('locale', $locale)->get('gallery_albums_i18n')->num_rows()) {
384
            $this->db->where('id', $id)->where('locale', $locale);
385
            $this->db->update('gallery_albums_i18n', $data_locale);
386
        } else {
387
            $this->db->insert('gallery_albums_i18n', $data_locale);
388
        }
389
390
        $album = $this->gallery_m->get_album($id);
391
392
        $this->input->post('action') ? $action = $this->input->post('action') : $action = 'edit';
393
394
        if ($action == 'edit') {
395
            pjax('/admin/components/cp/gallery/edit_album_params/' . $id . '/'. $locale);
396
        }
397
398
        if ($action == 'close') {
399
            pjax('/admin/components/cp/gallery/category/' . $album['category_id']);
400
        }
401
    }
402
403
    public function edit_album_params($id, $locale = null) {
404
        if (null === $locale) {
405
            $locale = $this->gallery_m->chose_locale();
406
        }
407
408
        $album = $this->gallery_m->get_album($id, true, false, false, $locale);
409
410
        if ($album != FALSE) {
411
            \CMSFactory\assetManager::create()
412
                ->setData(
413
                    [
414
                     'locale'     => $locale,
415
                     'languages'  => $this->db->get('languages')->result_array(),
416
                     'album'      => $album,
417
                     'categories' => $this->gallery_m->get_categories($album['category_id']),
418
                    ]
419
                )
420
                ->renderAdmin('album_params');
421
        } else {
422
            show_error(lang("Can't load album information", 'gallery'));
423
        }
424
    }
425
426
    /**
427
     * Delete album
428
     */
429
    public function delete_album($id = FALSE, $category = NULL) {
430
        if ($id == FALSE) {
431
            $id = (int) $this->input->post('album_id');
432
        }
433
434
        $album = $this->gallery_m->get_album($id);
435
436
        if ($album != FALSE) {
437
            //            if ($folder != FALSE) {
438
            $this->load->helper('file');
439
440
            // delete images.
441
            delete_files($this->conf['upload_path'] . $album['id'], TRUE);
442
443
            // delete album dir.
444
            exec('rmdir ' . $this->conf['upload_path'] . $album['id']);
445
            //            rmdir($this->conf['upload_path'] . $album['id'], TRUE);
446
            //            }
447
            $this->gallery_m->delete_album($album['id']);
448
            $this->lib_admin->log(lang('Gallery album was removed', 'gallery') . '. Id: ' . $id);
449
            pjax('/admin/components/cp/gallery/category/' . $category);
450
            //            echo 'deleted';
451
            //            exit;
452
        } else {
453
            showMessage(lang("Can't load album information", 'gallery'));
454
        }
455
    }
456
457
    /**
458
     * Display create_album template
459
     */
460
    public function show_crate_album() {
461
        // Select only category id and name for selectbox
462
        // $this->db->select('id, name');
463
        $cats = $this->gallery_m->get_categories('position', 'asc');
464
        $selectCategory = $this->input->get('category_id');
465
466
        \CMSFactory\assetManager::create()
467
            ->setData(
468
                [
469
                 'categories'     => $cats,
470
                 'selectCategory' => $selectCategory,
471
                ]
472
            )
473
            ->renderAdmin('create_album');
474
    }
475
476
    /**
477
     * Show edit album template
478
     */
479
    public function edit_album($id = 0) {
480
        $album = $this->gallery_m->get_album($id);
481
482
        \CMSFactory\assetManager::create()
483
            ->setData(
484
                [
485
                 'album'     => $album,
486
                 'category'  => $this->gallery_m->get_category($album['category_id']),
487
                 'album_url' => $this->conf['upload_url'] . $id,
488
                ]
489
            )
490
            ->renderAdmin('edit_album');
491
    }
492
493
    // --------------------------------------------------------------------
494
495
    public function edit_image($id, $locale = null) {
496
        if ($locale === null) {
497
            $locale = $this->gallery_m->chose_locale();
498
        }
499
        $image = $this->gallery_m->get_image_info($id, $locale);
500
501
        if ($image != FALSE) {
502
            $album = $this->gallery_m->get_album($image['album_id'], FALSE);
503
504
            \CMSFactory\assetManager::create()
505
                ->setData(
506
                    [
507
                     'locale'    => $locale,
508
                     'languages' => $this->db->get('languages')->result_array(),
509
                     'image'     => $image,
510
                     'album'     => $album,
511
                     'category'  => $this->gallery_m->get_category($album['category_id']),
512
                     'album_url' => $this->conf['upload_url'] . $album['id'],
513
                    ]
514
                )
515
                ->renderAdmin('edit_image');
516
        } else {
517
            show_error(lang("Can't load image information", 'gallery'));
518
        }
519
    }
520
521
    /**
522
     * Rename image
523
     */
524
    public function rename_image($id) {
525
        $image = $this->gallery_m->get_image_info($id);
526
527
        if ($image != FALSE) {
528
            $this->load->library('Form_validation');
529
530
            $this->form_validation->set_rules('new_name', lang('New name', 'gallery'), 'trim|required');
531
532
            if ($this->form_validation->run($this) == FALSE) {
533
                showMessage(validation_errors(), false, 'r');
534
            } else {
535
                $album = $this->gallery_m->get_album($image['album_id'], FALSE);
536
                $new_name = $this->input->post('new_name');
537
538
                $file_path = $this->conf['upload_path'] . $album['id'] . '/';
539
540
                // Rename original file
541
                rename($file_path . $image['file_name'] . $image['file_ext'], $file_path . $new_name . $image['file_ext']);
542
543
                // Rename preview file
544
                rename($file_path . $image['file_name'] . $this->conf['prev_img_marker'] . $image['file_ext'], $file_path . $new_name . $this->conf['prev_img_marker'] . $image['file_ext']);
545
546
                // Rename thumb
547
                rename($file_path . $this->conf['thumbs_folder'] . '/' . $image['file_name'] . $image['file_ext'], $file_path . $this->conf['thumbs_folder'] . '/' . $new_name . $image['file_ext']);
548
549
                // Rename admin thumb
550
                rename($file_path . '_admin_thumbs/' . $image['file_name'] . $image['file_ext'], $file_path . '_admin_thumbs/' . $new_name . $image['file_ext']);
551
552
                // Update file name in db
553
                $this->gallery_m->rename_image($id, $new_name);
554
555
                pjax('/admin/components/cp/gallery/edit_image/' . $image['id']);
556
                showMessage(lang('Changes have been saved', 'gallery'));
557
            }
558
        } else {
559
            showMessage(lang("Can't load image information", 'gallery'), false, 'r');
560
        }
561
    }
562
563
    /**
564
     * Delete image files
565
     */
566
    public function delete_image($ids = 0) {
567
        if ($this->input->post('id')) {
568
            $ids = $this->input->post('id');
569
        }
570
571
        foreach ($ids as $key => $id) {
572
            $image = $this->gallery_m->get_image_info($id);
573
            if ($image != FALSE) {
574
                $album = $this->gallery_m->get_album($image['album_id'], FALSE);
575
                $path = $this->conf['upload_path'] . $album['id'] . '/';
576
577
                // Delete image.
578
                //./uploads/gallery/13/53e96a8b7146a2976f6dd3e064de61db.jpeg
579
                unlink($path . $image['file_name'] . $image['file_ext']);
580
581
                // Delete thumb.
582
                //./uploads/gallery/13/_thumbs/53e96a8b7146a2976f6dd3e064de61db.jpeg
583
                unlink($path . $this->conf['thumbs_folder'] . '/' . $image['file_name'] . $image['file_ext']);
584
585
                // Delete preview file.
586
                unlink($path . $image['file_name'] . $this->conf['prev_img_marker'] . $image['file_ext']);
587
588
                // Delete admin thumb.
589
                unlink($path . '_admin_thumbs/' . $image['file_name'] . $image['file_ext']);
590
591
                // Delete image info.
592
                $this->gallery_m->delete_image($image['id']);
593
                $this->lib_admin->log(lang('Album image deleted.', 'gallery') . '. Id: ' . $image['id']);
594
                showMessage(lang('Photos removed', 'gallery'));
595
            }
596
        }
597
    }
598
599
    /**
600
     * Update image description/position
601
     */
602
    public function update_info($id, $locale = null) {
603
604
        if (null === $locale) {
605
            $locale = $this->gallery_m->chose_locale();
606
        }
607
        $image = $this->gallery_m->get_image_info($id);
608
609
        if ($image != FALSE) {
610
            $album = $this->gallery_m->get_album($image['album_id'], FALSE);
611
612
            $data = [
613
                     'description' => trim($this->input->post('description')),
614
                     'title'       => trim($this->input->post('title')),
615
                    ];
616
617
            $this->gallery_m->update_description($id, $data, $locale);
618
619
            $this->gallery_m->update_position($id, trim((int) $this->input->post('position')));
620
621
            if ($this->input->post('cover') == 1) {
622
                $this->gallery_m->set_album_cover($image['album_id'], $image['id']);
623
            } elseif ($this->input->post('cover') != 1 AND $album['cover_id'] == $image['id']) {
624
                $this->gallery_m->set_album_cover($image['album_id'], NULL);
625
            }
626
627
            //showMessage(lang('Changes are saved', 'gallery'));
628
629
            pjax('/admin/components/cp/gallery/edit_album/' . $image['album_id']);
630
        } else {
631
            showMessage(lang("Can't load image information", 'gallery'), false, 'r');
632
        }
633
    }
634
635 View Code Duplication
    public function update_positions() {
636
        $positions = $this->input->post('positions');
637
        foreach ($positions as $key => $value) {
638
            $this->db->where('id', (int) $value)->set('position', $key)->update('gallery_category');
639
        }
640
        showMessage(lang('Positions updated', 'gallery'));
641
    }
642
643 View Code Duplication
    public function update_album_positions() {
644
        $positions = $this->input->post('positions');
645
        foreach ($positions as $key => $value) {
646
            $this->db->where('id', (int) $value)->set('position', $key)->update('gallery_albums');
647
        }
648
        showMessage(lang('Positions updated', 'gallery'));
649
    }
650
651 View Code Duplication
    public function update_img_positions() {
652
        $positions = $this->input->post('positions');
653
        foreach ($positions as $key => $value) {
654
            $this->db->where('id', (int) $value)->set('position', $key)->update('gallery_images');
655
        }
656
        showMessage(lang('Positions updated', 'gallery'));
657
    }
658
659
    /**
660
     * Add uploaded image to album
661
     */
662
    private function add_image($album_id = 0, $file_data = []) {
663
        $this->load->helper('number');
664
665
        $size = $this->get_image_size($file_data['full_path']);
0 ignored issues
show
$size is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
666
667
        $size = byte_format(filesize($file_data['full_path']));
668
669
        $size = str_replace(
670
            [
671
             'bytes',
672
             'kilobyte_abbr',
673
             'megabyte_abbr',
674
             'gigabyte_abbr',
675
             'terabyte_abbr',
676
            ],
677
            [
678
             'B',
679
             'kB',
680
             'MB',
681
             'GB',
682
             'TB',
683
            ],
684
            $size
685
        );
686
687
        $image_info = [
688
                       'album_id'  => $album_id,
689
                       'file_name' => $file_data['raw_name'],
690
                       'file_ext'  => $file_data['file_ext'],
691
                       'file_size' => $size,
692
                       'width'     => $size['width'],
693
                       'height'    => $size['height'],
694
                       'uploaded'  => time(),
695
                       'views'     => 0,
696
                      ];
697
698
        $this->gallery_m->add_image($image_info);
699
    }
700
701
    /**
702
     * Get image width and height
703
     */
704
    private function get_image_size($file_path) {
705
        if (function_exists('getimagesize')) {
706
            $image = @getimagesize($file_path);
707
708
            $size = [
709
                     'width'  => $image[0],
710
                     'height' => $image[1],
711
                    ];
712
713
            return $size;
714
        }
715
716
        return FALSE;
717
    }
718
719
    // --------------------------------------------------------------------
720
    // Categories
721
    // --------------------------------------------------------------------
722
723
    public function show_create_category() {
724
        \CMSFactory\assetManager::create()->renderAdmin('create_category');
725
    }
726
727
    public function create_category() {
728
729
        $locale = $this->gallery_m->chose_locale();
730
731
        $this->load->library('Form_validation');
732
        $val = $this->form_validation;
733
734
        $val->set_rules('name', lang('Name', 'gallery'), 'trim|required|max_length[250]|min_length[1]');
735
        $val->set_rules('position', lang('Position', 'gallery'), 'numeric');
736
737
        if ($val->run() == FALSE) {
738
            showMessage(validation_errors(), false, 'r');
739
        } else {
740
            $data = [
741
                //'name' => $this->input->post('name'),
742
                //'description' => trim($this->input->post('description')),
743
                     'position' => $this->input->post('position'),
744
                     'created'  => time(),
745
                    ];
746
747
            $last_id = $this->gallery_m->create_category($data);
748
749
            $data_locale = [
750
                            'id'          => $last_id,
751
                            'locale'      => $locale,
752
                            'name'        => $this->input->post('name'),
753
                            'description' => trim($this->input->post('description')),
754
                           ];
755
756
            $this->db->insert('gallery_category_i18n', $data_locale);
757
758
            $this->lib_admin->log(lang('Gallery category was created', 'gallery'));
759
            //updateDiv('page', site_url('admin/components/cp/gallery'));
760
            //$this->input->post('action') ? $action = $this->input->post('action') : $action = 'edit';
761
762
            if ($this->input->post('action') == 'close') {
763
                pjax('/admin/components/cp/gallery/index');
764
            } else {
765
                pjax('/admin/components/cp/gallery/edit_category/' . $last_id);
766
            }
767
        }
768
    }
769
770
    public function edit_category($id, $locale = null) {
771
772
        if (null === $locale) {
773
            $locale = $this->gallery_m->chose_locale();
774
        }
775
        $category = $this->gallery_m->get_category($id, $locale);
776
777
        \CMSFactory\assetManager::create()
778
            ->setData(
779
                [
780
                 'category'  => $category,
781
                 'locale'    => $locale,
782
                 'languages' => $this->db->get('languages')->result_array(),
783
                ]
784
            )
785
            ->renderAdmin('edit_category');
786
    }
787
788
    public function update_category($id, $locale) {
789
        $this->load->library('Form_validation');
790
        $val = $this->form_validation;
791
792
        $val->set_rules('name', lang('Name', 'gallery'), 'trim|required|max_length[250]|min_length[1]');
793
        $val->set_rules('position', lang('Position', 'gallery'), 'numeric');
794
795
        if ($val->run() == FALSE) {
796
            showMessage(validation_errors(), false, 'r');
797
        } else {
798
            $data = [
799
                     'position' => $this->input->post('position'),
800
                    ];
801
802
            $this->gallery_m->update_category($data, $id);
803
804
            $data_locale = [
805
                            'id'          => $id,
806
                            'locale'      => $locale,
807
                            'name'        => $this->input->post('name'),
808
                            'description' => trim($this->input->post('description')),
809
                           ];
810
811 View Code Duplication
            if ($this->db->where('id', $id)->where('locale', $locale)->get('gallery_category_i18n')->num_rows()) {
812
                $this->db->where('id', $id)->where('locale', $locale);
813
                $this->db->update('gallery_category_i18n', $data_locale);
814
            } else {
815
                $this->db->insert('gallery_category_i18n', $data_locale);
816
            }
817
818
            $this->lib_admin->log(lang('Gallery category was edited', 'gallery') . '. Id: ' . $id);
819
            showMessage(lang('Changes have been saved', 'gallery'));
820
821
            //updateDiv('page', site_url('admin/components/cp/gallery'));
822
            $this->input->post('action') ? $action = $this->input->post('action') : $action = 'edit';
823
824
            if ($action == 'close') {
825
                pjax('/admin/components/cp/gallery/index');
826
            }
827
            if ($action == 'edit') {
828
                pjax('/admin/components/cp/gallery/edit_category/' . $id .'/' . $locale);
829
            }
830
        }
831
    }
832
833
    public function delete_category() {
834
        foreach ($this->input->post('id') as $id) {
835
836
            // Delete category albums
837
            $albums = $this->gallery_m->get_albums('date', 'desc', $id);
838
839
            if (count($albums) > 0) {
840
                foreach ($albums as $album) {
841
                    $this->delete_album($album['id']);
842
                }
843
            }
844
            $this->gallery_m->delete_category($id);
845
        }
846
        $this->lib_admin->log(lang('Gallery category was removed', 'gallery') . '. Ids: ' . implode(', ', $this->input->post('id')));
847
    }
848
849
    /**
850
     * In CI's class Upload not provided the input's files array (name='somefile[]')
851
     * So the structure of $_FILES must be
852
     * Array (
853
     *      [somefile] => Array (
854
     *            [name] => qwe.jpg
855
     *               ...
856
     *  ))
857
     * But in case of many file it is like this:
858
     * Array (
859
     *      [somefile] => Array (
860
     *            [name] => Array (
861
     *                  [0] => 'qwe.jpg',
862
     *                  [1] => 'asd.jpg',
863
     *                  ...
864
     *            )
865
     *               ...
866
     *  ))
867
     * There is a need to transform $_FILES like each file come from his own input
868
     *
869
     * @param string $field name of the input[name]
870
     */
871
    private function transform_FILES($field = 'userfile') {
872
        if (!array_key_exists($field, $_FILES)) {
873
            return FALSE;
874
        }
875
876
        $newFiles = [];
877
        $count = count($_FILES[$field]['name']);
878
        for ($i = 0; $i < $count; $i++) {
879
            $oneFileData = [];
880
            foreach ($_FILES[$field] as $assocKey => $fileDataArray) {
881
                $oneFileData[$assocKey] = $fileDataArray[$i];
882
            }
883
            $newFiles[$field . '_' . $i] = $oneFileData;
884
        }
885
        $_FILES = $newFiles;
886
        return TRUE;
887
    }
888
889
    /**
890
     * Upload image
891
     *
892
     * Upload image to album folder.
893
     *
894
     */
895
    public function upload_image($album_id = 0) {
896
        $temp_conf = $this->conf;
897
        if (is_array($_FILES['newPic'])) {
898
899
            if (count($_FILES['newPic']['name']) > ini_get('max_file_uploads')) {
900
                showMessage(langf('You can upload only |max_file_uploads| images at once', 'admin', ['max_file_uploads' => ini_get('max_file_uploads')]), lang('Error', 'admin'), 'r');
901
                exit;
902
            }
903
904
            // making transformation of $_FILES array for CodeIgniter's Upload class
905
            $this->transform_FILES('newPic');
906
907
            // configs for Upload
908
            $this->conf['upload_path'] = $this->conf['upload_path'] . $album_id;
909
            if (!is_dir($this->conf['upload_path'])) {
910
                mkdir($this->conf['upload_path']);
911
            }
912
            $config['upload_path'] = $this->conf['upload_path'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$config was never initialized. Although not strictly required by PHP, it is generally a good practice to add $config = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
913
914
            $config['allowed_types'] = $this->conf['allowed_types'];
915
            $config['max_size'] = 1024 * $this->conf['max_image_size'];
916
            $config['encrypt_name'] = TRUE;
917
918
            // init Upload
919
            $this->load->library('upload', $config);
920
921
            // saving each file
922
            $data = [];
923
            $i = 0;
924
            foreach ($_FILES as $fieldName => $filesData) {
925
                if (!$this->upload->do_upload($fieldName)) {
926
                    $error = $filesData['name'] . ' - ' . $this->upload->display_errors('', '') . '<br /> ';
927
                    $data['error'] .= $error;
928
                } else {
929
                    $data[$i] = ['upload_data' => $this->upload->data()];
930
931
                    // Resize Image and create thumb
932
                    $this->resize_and_thumb($data[$i]['upload_data']);
933
                    $this->add_image($album_id, $data[$i]['upload_data']);
934
                }
935
                $buf = $this->conf['upload_path'];
936
                $this->conf = $temp_conf;
937
                $this->conf['upload_path'] = $buf;
938
                $i++;
939
            }
940
941
            if (isset($data['error'])) {
942
                showMessage($data['error'], '', 'r');
943
            } else {
944
                showMessage(lang('Upload success', 'gallery'));
945
                pjax('');
946
            }
947
        }
948
        $this->lib_admin->log(lang('Photos in gallery the album are saved', 'gallery'));
949
    }
950
951
    /**
952
     * Resize image and create thumb
953
     */
954
    private function resize_and_thumb($file = []) {
955
        $this->load->library('image_lib');
956
957
        // Resize image
958
        if ($this->conf['max_width'] > 0 AND $this->conf['max_height'] > 0) {
959
            if ($file['image_width'] > $this->conf['max_width'] OR $file['image_height'] > $this->conf['max_height']) {
960
                $config = [];
961
                $config['image_library'] = $this->conf['engine'];
962
                $config['source_image'] = $file['full_path'];
963
                $config['create_thumb'] = FALSE;
964
                $config['maintain_ratio'] = $this->conf['maintain_ratio'];
965
                $config['width'] = $this->conf['max_width'];
966
                $config['height'] = $this->conf['max_height'];
967
                $config['quality'] = $this->conf['quality'];
968
969 View Code Duplication
                if (($this->conf['maintain_ratio']) AND ($this->conf['crop'])) { // Уменьшаем изображение и обрезаем края
970
                    $size = $this->get_image_size($file['full_path']); // Получаем размеры сторон изображения
971
972
                    $size['width'] >= $size['height'] ? $config['master_dim'] = 'height' : $config['master_dim'] = 'width'; // Задаем master_dim
973
974
                    $this->image_lib->clear();
975
                    $this->image_lib->initialize($config);
976
                    $this->image_lib->resize();
977
978
                    $config['image_library'] = $this->conf['engine'];
979
                    $config['source_image'] = $file['full_path'];
980
                    $config['maintain_ratio'] = FALSE;
981
                    $config['width'] = $this->conf['max_width'];
982
                    $config['height'] = $this->conf['max_height'];
983
984
                    $this->image_lib->clear();
985
                    $this->image_lib->initialize($config);
986
                    $this->image_lib->crop();
987
                } else { // Только уменьшаем
988
                    $this->image_lib->clear();
989
                    $this->image_lib->initialize($config);
990
                    $this->image_lib->resize();
991
                }
992
            }
993
        }
994
        // Create image preview
995
        $config = [];
996
        $prev_img_name = $file['raw_name'] . '_prev' . $file['file_ext'];
997
998
        if ($file['image_width'] > $this->conf['prev_img_width'] OR $file['image_height'] > $this->conf['prev_img_height']) {
999
            $config['image_library'] = $this->conf['engine'];
1000
            $config['source_image'] = $file['full_path'];
1001
            $config['new_image'] = $prev_img_name;
1002
            $config['create_thumb'] = FALSE;
1003
            $config['maintain_ratio_prev'] = $this->conf['maintain_ratio_prev'];
1004
            $config['width'] = $this->conf['prev_img_width'];
1005
            $config['height'] = $this->conf['prev_img_height'];
1006
            $config['quality'] = $this->conf['quality'];
1007
1008 View Code Duplication
            if (($this->conf['maintain_ratio_prev']) AND ($this->conf['crop_prev'])) { // Уменьшаем изображение и обрезаем края
1009
                $size = $this->get_image_size($file['full_path']); // Получаем размеры сторон изображения
1010
1011
                $size['width'] >= $size['height'] ? $config['master_dim'] = 'height' : $config['master_dim'] = 'width'; // Задаем master_dim
1012
1013
                $this->image_lib->clear();
1014
                $this->image_lib->initialize($config);
1015
                $this->image_lib->resize();
1016
1017
                $config['image_library'] = $this->conf['engine'];
1018
                $config['source_image'] = $prev_img_name;
1019
                $config['maintain_ratio'] = FALSE;
1020
                $config['width'] = $this->conf['prev_img_width'];
1021
                $config['height'] = $this->conf['prev_img_height'];
1022
1023
                $this->image_lib->clear();
1024
                $this->image_lib->initialize($config);
1025
                $this->image_lib->crop();
1026
            } else { // Только уменьшаем
1027
                $this->image_lib->clear();
1028
                $this->image_lib->initialize($config);
1029
                $this->image_lib->resize();
1030
            }
1031
        } else {
1032
            $this->load->helper('File');
1033
            $file_data = read_file($file['full_path']);
1034
            write_file($file['file_path'] . $prev_img_name, $file_data);
1035
        }
1036
1037
        // Create thumb file
1038
        $config = [];
1039
        $thumb_name = $this->conf['upload_path'] . '/' . $this->conf['thumbs_folder'] . '/' . $file['raw_name'] . $this->conf['thumb_marker'] . $file['file_ext'];
1040
1041
        if ($file['image_width'] > $this->conf['thumb_width'] OR $file['image_height'] > $this->conf['thumb_height']) {
1042
            $config['image_library'] = $this->conf['engine'];
1043
            $config['source_image'] = $file['full_path'];
1044
            $config['new_image'] = $thumb_name;
1045
            $config['create_thumb'] = FALSE;
1046
            $config['maintain_ratio'] = $this->conf['maintain_ratio_icon'];
1047
            $config['width'] = $this->conf['thumb_width'];
1048
            $config['height'] = $this->conf['thumb_height'];
1049
            $config['quality'] = $this->conf['quality'];
1050
1051
            if (($this->conf['maintain_ratio_icon']) AND ($this->conf['crop_icon'])) { // Уменьшаем изображение и обрезаем края
1052
                $size = $this->get_image_size($file['full_path']); // Получаем размеры сторон изображения
1053
1054
                $size['width'] >= $size['height'] ? $config['master_dim'] = 'height' : $config['master_dim'] = 'width'; // Задаем master_dim
1055
1056
                $this->image_lib->clear();
1057
                $this->image_lib->initialize($config);
1058
                if (!$this->image_lib->resize()) {
1059
                    echo 'fck';
1060
                }
1061
1062
                $config['image_library'] = $this->conf['engine'];
1063
                $config['source_image'] = $thumb_name;
1064
                $config['maintain_ratio'] = FALSE;
1065
                $config['width'] = $this->conf['thumb_width'];
1066
                $config['height'] = $this->conf['thumb_height'];
1067
1068
                $this->image_lib->clear();
1069
                $this->image_lib->initialize($config);
1070
                $this->image_lib->crop();
1071
            } else { // Только уменьшаем
1072
                $this->image_lib->clear();
1073
                $this->image_lib->initialize($config);
1074
                if (!$this->image_lib->resize()) {
1075
                    echo $this->image_lib->display_errors();
1076
                }
1077
            }
1078 View Code Duplication
        } else {
1079
            // copy file to thumbs folder
1080
            $this->load->helper('File');
1081
            $file_data = read_file($file['full_path']);
1082
            write_file($thumb_name, $file_data);
1083
        }
1084
1085
        // Create admin thumb file
1086
        $config = [];
1087
        $thumb_name = $this->conf['upload_path'] . '/_admin_thumbs/' . $file['raw_name'] . $this->conf['thumb_marker'] . $file['file_ext'];
1088
1089
        if ($file['image_width'] > 100 OR $file['image_height'] > 100) {
1090
            $config['image_library'] = $this->conf['engine'];
1091
            $config['source_image'] = $file['full_path'];
1092
            $config['new_image'] = $thumb_name;
1093
            $config['create_thumb'] = FALSE;
1094
            $config['maintain_ratio'] = TRUE;
1095
            $config['width'] = 100;
1096
            $config['height'] = 100;
1097
            $config['quality'] = '80%';
1098
1099
            $this->image_lib->clear();
1100
            $this->image_lib->initialize($config);
1101
            $this->image_lib->resize();
1102 View Code Duplication
        } else {
1103
            $this->load->helper('File');
1104
            $file_data = read_file($file['full_path']);
1105
            write_file($thumb_name, $file_data);
1106
        }
1107
1108
        // Draw watermark.
1109
        if ($file['image_width'] > $this->conf['watermark_min_width'] AND $file['image_height'] > $this->conf['watermark_min_height']) {
1110
            $this->make_watermark($file['full_path']);
1111
            $this->make_watermark($file['file_path'] . $prev_img_name);
1112
        }
1113
1114
        return TRUE;
1115
    }
1116
1117
    /**
1118
     * Watermarking an Image if watermark_text is not empty
1119
     */
1120
    private function make_watermark($file_path) {
1121
        if (!$this->conf['watermark_font_path']) {
1122
            $this->conf['watermark_font_path'] = './uploads/defaultFont.ttf';
1123
        }
1124
1125
        $config = [];
1126
        $config['source_image'] = $file_path;
1127
        $config['wm_vrt_alignment'] = $this->conf['wm_vrt_alignment'];
1128
        $config['wm_hor_alignment'] = $this->conf['wm_hor_alignment'];
1129
        $config['wm_padding'] = $this->conf['watermark_padding'];
1130
1131
        if ($this->conf['watermark_type'] == 'overlay') {
1132
            $config['wm_type'] = 'overlay';
1133
            $config['wm_opacity'] = $this->conf['watermark_image_opacity'];
1134
            $config['wm_overlay_path'] = $this->conf['watermark_image'];
1135
        } else {
1136
            if ($this->conf['watermark_text'] == '') {
1137
                return FALSE;
1138
            }
1139
1140
            $config['wm_text'] = $this->conf['watermark_text'];
1141
            $config['wm_type'] = 'text';
1142
            $config['wm_font_path'] = $this->conf['watermark_font_path'];
1143
            $config['wm_font_size'] = $this->conf['watermark_font_size'];
1144
            $config['wm_font_color'] = $this->conf['watermark_color'];
1145
        }
1146
1147
        $this->image_lib->clear();
1148
        $this->image_lib->initialize($config);
1149
        $this->image_lib->watermark();
1150
    }
1151
1152
}
1153
1154
/* End of file admin.php */