@@ -14,6 +14,7 @@ public function process() {
1414 $ resource = $ this ->getProperty ('resource ' );
1515 $ field = $ this ->getProperty ('fieldName ' , '' );
1616 $ url = $ this ->getProperty ('url ' );
17+ $ image = $ this ->getProperty ('image ' );
1718 $ mediaSource = (int )$ this ->getProperty ('mediaSource ' , 0 );
1819
1920 if (empty ($ mediaSource )) {
@@ -24,21 +25,25 @@ public function process() {
2425 return $ this ->failure ("Resource is required " );
2526 }
2627
27- if (empty ($ url )) {
28- return $ this ->failure ('URL is required ' );
28+ if (empty ($ url ) && empty ( $ image ) ) {
29+ return $ this ->failure ('URL or Image is required ' );
2930 }
3031
31- $ additionalDomains = Settings::getSetting ($ this ->modx , 'image.download_domains ' );
32+ $ additionalDomains = Settings::getSetting ($ this ->modx , 'image.download_domains ' , '' );
3233 $ additionalDomains = Utils::explodeAndClean ($ additionalDomains );
3334
3435 $ allowedDomains = array_merge ($ additionalDomains , $ this ->allowedDomains );
3536
36- $ domainAllowed = false ;
37- foreach ($ allowedDomains as $ domain ) {
38- if (strncmp ($ url , $ domain , strlen ($ domain )) === 0 ) {
39- $ domainAllowed = true ;
40- break ;
37+ if (!empty ($ url )) {
38+ $ domainAllowed = false ;
39+ foreach ($ allowedDomains as $ domain ) {
40+ if (strncmp ($ url , $ domain , strlen ($ domain )) === 0 ) {
41+ $ domainAllowed = true ;
42+ break ;
43+ }
4144 }
45+ } else {
46+ $ domainAllowed = true ;
4247 }
4348
4449 if (!$ domainAllowed ) {
@@ -59,7 +64,9 @@ public function process() {
5964
6065 $ filePath = $ this ->createFilePath ($ path , $ resource );
6166
62- $ source ->createObject ($ filePath [0 ], $ filePath [1 ], file_get_contents ($ url ));
67+ $ image = file_get_contents (empty ($ url ) ? $ image : $ url );
68+
69+ $ source ->createObject ($ filePath [0 ], $ filePath [1 ], $ image );
6370
6471 return $ this ->success ('' , ['url ' => $ filePath [0 ].$ filePath [1 ]]);
6572 }
0 commit comments