1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
|
5
|
|
|
class ImagesWithStyleCMSAPI extends Object |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
public static function add_links_to_folder_field($formField, $folderOrImagesWithStyleList) |
8
|
|
|
{ |
9
|
|
|
$folder = null; |
10
|
|
|
if ($folderOrImagesWithStyleList instanceof ImagesWithStyleSelection) { |
11
|
|
|
if ($folderOrImagesWithStyleList->PlaceToStoreImagesID) { |
|
|
|
|
12
|
|
|
$folder = $folderOrImagesWithStyleList->PlaceToStoreImages(); |
|
|
|
|
13
|
|
|
} |
14
|
|
|
} elseif ($folderOrImagesWithStyleList instanceof Folder) { |
15
|
|
|
$folder = $folderOrImagesWithStyleList; |
16
|
|
|
} else { |
17
|
|
|
user_error('folderOrImagesWithStyleList param needs to be Folder or ImagesWithStyleSelection'); |
18
|
|
|
} |
19
|
|
|
if ($folder && $folder->exists()) { |
20
|
|
|
$rightFieldTitle = $formField->RightTitle(); |
21
|
|
|
$rightFieldTitle .= ' |
22
|
|
|
<h5>Quick Links</h5> |
23
|
|
|
You can <a href="/admin/assets/add/?ID='.$folder->ID.'" target="_blank">add images directly</a> to the <a href="/admin/assets/show/'.$folder->ID.'/" target="_blank">folder</a>. |
24
|
|
|
<br /><strong>To see the latest updates to this folder, you may need to click save below.</strong>'; |
25
|
|
|
$formField->setRightTitle($rightFieldTitle); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
private static $_folder_cache = []; |
30
|
|
|
|
31
|
|
|
public static function folder_change_start($object, $key, $folderName) |
32
|
|
|
{ |
33
|
|
View Code Duplication |
if (!isset(self::$_folder_cache[$object->ClassName.'_'.$object->ID])) { |
|
|
|
|
34
|
|
|
self::$_folder_cache[$object->ClassName.'_'.$object->ID] = []; |
35
|
|
|
} |
36
|
|
View Code Duplication |
if (!isset(self::$_folder_cache[$object->ClassName.'_'.$object->ID][$key])) { |
|
|
|
|
37
|
|
|
self::$_folder_cache[$object->ClassName.'_'.$object->ID][$key] = []; |
38
|
|
|
} |
39
|
|
|
self::$_folder_cache[$object->ClassName.'_'.$object->ID][$key]['before'] = $folderName; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public static function folder_change_end($object, $key, $folderName, $list = null) |
43
|
|
|
{ |
44
|
|
|
self::$_folder_cache[$object->ClassName.'_'.$object->ID][$key]['after'] = $folderName; |
45
|
|
|
self::check_for_folder_changes_and_migrate_images( |
46
|
|
|
self::$_folder_cache[$object->ClassName.'_'.$object->ID][$key], |
47
|
|
|
$list |
48
|
|
|
); |
49
|
|
|
self::$_folder_cache[$object->ClassName.'_'.$object->ID][$key]['before'] = $folderName; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
protected static function check_for_folder_changes_and_migrate_images($keyDetail, $list) |
54
|
|
|
{ |
55
|
|
|
if ($keyDetail['before'] !== $keyDetail['after']) { |
56
|
|
|
$oldFolder = Folder::find_or_make($keyDetail['before']); |
57
|
|
|
$newFolder = Folder::find_or_make($keyDetail['after']); |
58
|
|
|
$oldImages = Image::get()->filter(['ParentID' => $oldFolder->ID]); |
59
|
|
|
if ($newFolder && $newFolder->exists()) { |
60
|
|
|
if ($list && $list->exists()) { |
61
|
|
|
$list->PlaceToStoreImagesID = $newFolder->ID; |
62
|
|
|
$list->write(); |
63
|
|
|
} |
64
|
|
|
if ($oldFolder && $oldFolder->exists()) { |
65
|
|
|
if ($oldImages && $oldImages->count()) { |
66
|
|
|
foreach ($oldImages as $oldImage) { |
67
|
|
|
$oldImage->ParentID = $newFolder->ID; |
68
|
|
|
$oldImage->write(); |
69
|
|
|
} |
70
|
|
|
$oldFilesAny = File::get()->filter(['ParentID' => $oldFolder->ID]); |
71
|
|
|
if ($oldFilesAny->count()) { |
72
|
|
|
$oldFilesAny->delete(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.