$linksCopy = $links;
foreach ($linksCopy as $k => $linkData) {
- if(!$linkData['to']) {
+ if (!$linkData['to']) {
continue;
}
if (stristr($linkData['to'], 'javascript:canvasToPDF(')) {
$this->config->push('triggersLinks', ['page' => $page, 'link' => $link, 'delay' => $delay]);
}
- public function shortenURL($url)
+ public function shortenURL($url, $special = false)
{
if (!$this->config->linkShortener || $this->config->linkShortener === 'none' || !Url::isDistant($url)) {
return $url;
}
- return LinkShortener::shorturl($url, $this->config->linkShortener);
+
+ $res = LinkShortener::shorturl($url, $this->config->linkShortener);
+ if ($special) {
+ $this->config->push('specialShortLinks', $res);
+ }
+ return $res;
}
}
namespace App\Http\Controllers\Admin\Operations\FluidbookPublication\Services;
use App\Fluidbook\Link\LinksData;
+use App\Http\Middleware\Authenticate;
use App\Http\Middleware\CheckIfAdmin;
+use App\Http\Middleware\VerifyCsrfToken;
use App\Models\FluidbookPublication;
+use App\Models\LinkShortener;
+use Cubist\Backpack\Middleware\CORSMiddleware;
use Fluidbook\Tools\Links\Link;
use Illuminate\Support\Facades\Route;
protected function setupShortlinkRoutes($segment, $routeName, $controller)
{
foreach (['services', 's'] as $segment) {
- Route::match(['get'], $segment . '/shortlinks/{cid?}', $controller . '@listShortLinks')->withoutMiddleware([CheckIfAdmin::class]);
+ Route::match(['post'], $segment . '/shortlinks', $controller . '@listShortLinks')->withoutMiddleware([CORSMiddleware::class])->withoutMiddleware([Authenticate::class, VerifyCsrfToken::class, CheckIfAdmin::class]);
}
}
- public function listShortLinks($cid)
+ public function listShortLinks()
{
- $publication = FluidbookPublication::where('cid', $cid)->first();
+ $publication = FluidbookPublication::where('cid', request('cid'))->first();
if (null === $publication) {
abort(404);
}
abort(404);
}
- LinksData::getLinksAndRulers($publication->id, $links, $rulers);
- $res = ['youtube' => []];
- foreach ($links as $link) {
- if ($link['type'] == Link::WEBVIDEO && $link['video_service'] == 'youtube') {
-
- }
+ $res = [];
+ foreach (request('links') as $url) {
+ $res[$url] = LinkShortener::expand($url, $publication->linkShortener);
}
+ return $res;
}
}