diff --git a/action.php b/action.php index 39ea597..d9d9f78 100644 --- a/action.php +++ b/action.php @@ -322,6 +322,16 @@ switch ($VARS['action']) { } returnToSender("file_deleted"); break; + case "unsplash_download": + Crew\Unsplash\HttpClient::init([ + 'applicationId' => UNSPLASH_ACCESSKEY, + 'secret' => UNSPLASH_SECRETKEY, + 'utmSource' => UNSPLASH_UTMSOURCE + ]); + Crew\Unsplash\Photo::find($VARS['imageid'])->download(); + header('Content-Type: application/json'); + exit(json_encode(["status" => "OK"])); + break; case "signout": session_destroy(); header('Location: index.php'); diff --git a/composer.json b/composer.json index d2aa591..12f8f70 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,8 @@ "require": { "catfan/medoo": "^1.5", "guzzlehttp/guzzle": "^6.2", - "geoip2/geoip2": "~2.0" + "geoip2/geoip2": "~2.0", + "unsplash/unsplash": "^2.4" }, "license": "MPL-2.0", "authors": [ diff --git a/composer.lock b/composer.lock index 5ad0e7f..c30be00 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "a05b32c4ba7d59c1fa2dc87ef59b238d", - "content-hash": "2b47ec7e64412178507c9e9362debc56", + "hash": "14eefa1d98fa62ca2f2fe52de606868c", + "content-hash": "e9f318b9d8bd1dfa6c7fb56c820d1910", "packages": [ { "name": "catfan/medoo", @@ -355,6 +355,125 @@ ], "time": "2017-03-20 17:10:46" }, + { + "name": "hughbertd/oauth2-unsplash", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/HughbertD/oauth2-unsplash.git", + "reference": "f451f4a49dca4027f6edaa850d2fccdfa8721bfe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/HughbertD/oauth2-unsplash/zipball/f451f4a49dca4027f6edaa850d2fccdfa8721bfe", + "reference": "f451f4a49dca4027f6edaa850d2fccdfa8721bfe", + "shasum": "" + }, + "require": { + "league/oauth2-client": ">=1.0", + "php": ">=5.6.0" + }, + "require-dev": { + "mockery/mockery": "~0.9", + "phpunit/phpunit": "~5.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Unsplash\\OAuth2\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Hugh Downer", + "email": "hugh.downer@gmail.com" + } + ], + "description": "Unsplash OAuth 2.0 Client Provider for The PHP League OAuth2-Client", + "keywords": [ + "Authentication", + "SSO", + "Unsplash", + "authorization", + "identity", + "idp", + "oauth", + "oauth2", + "single sign on" + ], + "time": "2017-12-14 13:08:42" + }, + { + "name": "league/oauth2-client", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/oauth2-client.git", + "reference": "aa2e3df188f0bfd87f7880cc880e906e99923580" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/oauth2-client/zipball/aa2e3df188f0bfd87f7880cc880e906e99923580", + "reference": "aa2e3df188f0bfd87f7880cc880e906e99923580", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^6.0", + "paragonie/random_compat": "^1|^2", + "php": "^5.6|^7.0" + }, + "require-dev": { + "eloquent/liberator": "^2.0", + "eloquent/phony-phpunit": "^1.0|^3.0", + "jakub-onderka/php-parallel-lint": "^0.9.2", + "phpunit/phpunit": "^5.7|^6.0", + "squizlabs/php_codesniffer": "^2.3|^3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-2.x": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\OAuth2\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Alex Bilbie", + "email": "hello@alexbilbie.com", + "homepage": "http://www.alexbilbie.com", + "role": "Developer" + }, + { + "name": "Woody Gilk", + "homepage": "https://github.com/shadowhand", + "role": "Contributor" + } + ], + "description": "OAuth 2.0 Client Library", + "keywords": [ + "Authentication", + "SSO", + "authorization", + "identity", + "idp", + "oauth", + "oauth2", + "single sign on" + ], + "time": "2018-01-13 05:27:58" + }, { "name": "maxmind-db/reader", "version": "v1.3.0", @@ -457,6 +576,54 @@ "homepage": "https://github.com/maxmind/web-service-common-php", "time": "2018-02-12 22:31:54" }, + { + "name": "paragonie/random_compat", + "version": "v2.0.12", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "258c89a6b97de7dfaf5b8c7607d0478e236b04fb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/258c89a6b97de7dfaf5b8c7607d0478e236b04fb", + "reference": "258c89a6b97de7dfaf5b8c7607d0478e236b04fb", + "shasum": "" + }, + "require": { + "php": ">=5.2.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "autoload": { + "files": [ + "lib/random.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "pseudorandom", + "random" + ], + "time": "2018-04-04 21:24:14" + }, { "name": "psr/http-message", "version": "1.0.1", @@ -506,6 +673,65 @@ "response" ], "time": "2016-08-06 14:39:51" + }, + { + "name": "unsplash/unsplash", + "version": "2.4.3", + "source": { + "type": "git", + "url": "https://github.com/unsplash/unsplash-php.git", + "reference": "7c6fed642cf4234545624a1263d57c9cb0970fbf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/unsplash/unsplash-php/zipball/7c6fed642cf4234545624a1263d57c9cb0970fbf", + "reference": "7c6fed642cf4234545624a1263d57c9cb0970fbf", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^6.3.0", + "hughbertd/oauth2-unsplash": ">=1.0.3", + "league/oauth2-client": ">=1.4.2", + "php": ">=5.6.0" + }, + "require-dev": { + "mockery/mockery": "~0.9.0", + "php-vcr/php-vcr": "dev-master", + "php-vcr/phpunit-testlistener-vcr": "*", + "phpunit/phpunit": "~5.1", + "satooshi/php-coveralls": "dev-master", + "vlucas/phpdotenv": "dev-master" + }, + "type": "library", + "autoload": { + "psr-4": { + "Crew\\Unsplash\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Charles Lalonde", + "email": "charles@pickcrew.com" + }, + { + "name": "Hugh Downer", + "email": "hugh.downer@gmail.com" + }, + { + "name": "Aaron Klaassen", + "email": "aaron@unsplash.com" + }, + { + "name": "Luke Chesser", + "email": "luke@unsplash.com" + } + ], + "description": "Wrapper to access the Unsplash API and photo library", + "time": "2018-03-30 17:45:15" } ], "packages-dev": [], diff --git a/lang/en_us.php b/lang/en_us.php index 4bd8cc0..189d325 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -127,5 +127,10 @@ define("STRINGS", [ "navbar title" => "Page title for menu", "navbar position" => "Menu position (drag to change position):", "remove image" => "Remove image", - "site footer links" => "Site Footer Links" + "site footer links" => "Site Footer Links", + "uploaded files" => "Uploaded Files", + "stock photos" => "Free Stock Photos", + "load more" => "Load more", + "search images" => "Search images", + "x results" => "{results} results", ]); \ No newline at end of file diff --git a/lib/filepicker.php b/lib/filepicker.php index 7bcbaff..fea5385 100644 --- a/lib/filepicker.php +++ b/lib/filepicker.php @@ -23,110 +23,60 @@ if (isset($VARS['type']) && $VARS['type'] != "") { $type = explode("|", $VARS['type']); } -if ($folder == "/") { - $folder = ""; +$enableunsplash = ENABLE_UNSPLASH; +if (count($type) > 0 && !in_array("image", $type)) { + $enableunsplash = false; } - -$fullpath = $base . $folder; ?> -
- -
-
+ + 0) { - $found = false; - foreach ($type as $t) { - if (strpos($mimetype, $t) === 0) { - $found = true; - break; - } - } - } - if (!$found) { - continue; - } +} +?> +
+
+
+
+
- // Lookup icon from mimetype - if (array_key_exists($mimetype, $MIMEICONS)) { - $icon = $MIMEICONS[$mimetype]; - } else { // Allow broad generic /other icons - $mimefirst = explode("/", $mimetype, 2)[0]; - if (array_key_exists($mimefirst . "/other", $MIMEICONS)) { - $icon = $MIMEICONS[$mimetype]; - } - } - } - ?> -
" - data-path="" - data-file=""> - -
- -
-

- -

-

- -

+
+
+
+
+ " /> +
+
+ +
+
+
+ via Unsplash +
+
+
+
+ +
+
0 && !in_array("image", $type)) { + $enableunsplash = false; +} + +if ($folder == "/") { + $folder = ""; +} + +$fullpath = $base . $folder; +?> +
+ +
+
+ 0) { + $found = false; + foreach ($type as $t) { + if (strpos($mimetype, $t) === 0) { + $found = true; + break; + } + } + } + if (!$found) { + continue; + } + + // Lookup icon from mimetype + if (array_key_exists($mimetype, $MIMEICONS)) { + $icon = $MIMEICONS[$mimetype]; + } else { // Allow broad generic /other icons + $mimefirst = explode("/", $mimetype, 2)[0]; + if (array_key_exists($mimefirst . "/other", $MIMEICONS)) { + $icon = $MIMEICONS[$mimetype]; + } + } + } + ?> +
" + data-path="" + data-file=""> + +
+ +
+

+ +

+

+ +

+
+ +
\ No newline at end of file diff --git a/lib/filepicker_unsplash.php b/lib/filepicker_unsplash.php new file mode 100644 index 0000000..e9defe0 --- /dev/null +++ b/lib/filepicker_unsplash.php @@ -0,0 +1,77 @@ + UNSPLASH_ACCESSKEY, + 'secret' => UNSPLASH_SECRETKEY, + 'utmSource' => UNSPLASH_UTMSOURCE +]); + +$page = 1; +if (isset($_GET['page']) && is_numeric($_GET['page'])) { + $page = $_GET['page']; +} + +$per_page = 15; + +$results = null; + +if (isset($_GET['query']) && $_GET['query'] != "") { + $results = Crew\Unsplash\Search::photos($_GET['query'], $page, $per_page, null, null); + $images = $results->getArrayObject(); +} else { + $images = Crew\Unsplash\Photo::all($page, $per_page, 'popular'); +} + +$images-> + +$htmlout = ""; + +if (count($images) == 0) { + $htmlout = "" . lang("no results", false) . ""; +} + +$htmlout .= '
'; + +foreach ($images as $img) { + $imageid = $img->id; + $description = $img->description; + $thumb = $img->urls['thumb']; + $image = $img->urls['regular']; + $attribution = '' . $img->user['name'] . ''; + $card = << + $description +
+

By $attribution

+
+
+END; + $htmlout .= $card; +} +$htmlout .= '
'; + +$jsonout = [ + 'total' => null, + 'pages' => null, + 'page' => $page, + 'html' => $htmlout +]; + +if (!is_null($results)) { + $jsonout['total'] = lang2("x results", ["results" => $results->getTotal()], false); + $jsonout['pages'] = $results->getTotalPages(); +} + +echo json_encode($jsonout); \ No newline at end of file diff --git a/pages.php b/pages.php index 9dd2eaf..c2ddd6c 100644 --- a/pages.php +++ b/pages.php @@ -46,6 +46,8 @@ define("PAGES", [ "scripts" => [ "static/js/html5sortable.min.js", "static/js/iconselector.js", + "static/js/filepicker_local.js", + "static/js/filepicker_unsplash.js", "static/js/editorparent.js", ] ], diff --git a/pages/editor.php b/pages/editor.php index 8c76e27..8b87873 100644 --- a/pages/editor.php +++ b/pages/editor.php @@ -75,7 +75,7 @@ if (!is_empty($VARS['siteid'])) { ?>