sudhaus7/shortcutlink 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sudhaus7/shortcutlink

Composer 安装命令:

composer require sudhaus7/shortcutlink

包简介

A flexible url shortener for TYPO3, with FLUID ViewHelpers and Encodeservice

README 文档

README

Latest Stable Version TYPO3 13 TYPO3 12 Total Downloads Monthly Downloads

A urlshortener for TYPO3

What does it do:

This extension will create a short URL similar to bit.ly or similar services in an easy way. For the Integrator this means that the usual Viewhelpers for creating links have been extended and the shortener can be used transparently for any link created by a FLUID Viewhelper.

Additionaly a Service Class is available to create shortened URLs on the fly for example in a Plugin or in an Extbase Controller.

I think this will be the last upgrade, as the main functionality seems to be available in core TYPO3 14. It might change to just provide the viewhelpers from here

Available FLUID Viewhelpers

Import the namespace like this:

<html
    xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"
    xmlns:scl="http://typo3.org/ns/SUDHAUS7/Shortcutlink/ViewHelpers"
    data-namespace-typo3-fluid="true"
>

or like this:

{namespace scl=SUDHAUS7\Shortcutlink\ViewHelpers}

The following ViewHelpers are available:

  • uri.action
  • uri.external
  • uri.page
  • uri.typolink
  • link.action
  • link.external
  • link.page

these ViewHelpers have all attributes available and behave the same way as their normal counterparts, except they will produce a shortened url

That means you can now replace any

<f:link.page pageId="15">The link</f:link.page>

simply with

<scl:link.page pageId="15">The link</scl:link.page>

Usage in PHP

a simple example to shorten a URL:

$url = 'https://google.com/';
$shortener = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\SUDHAUS7\Shortcutlink\Service\ShortlinkService::class);

$shortener->setUrl($url);
$shortlink = $shortener->getShorturlWithDomain();

Locking a shortend URL to a frontend user

It is possible to lock a frontend user ID to the shortened URL, which means that the short link can only be opened with an existing frontend user Session with the same user id

For this all ViewHelpers have an additional attribute chainToUserid which accepts the user id of the frontend user it has to be chained to.

For example:

<scl:link.page pageId="15" chainToUserid="42">The link</scl:link.page>

The resulting short link can only be opened if the user with the ID 42 is logged in.

The PHP equivalent to this would be:

$url = 'https://google.com/';
$shortener = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\SUDHAUS7\Shortcutlink\Service\ShortlinkService::class);

$shortener->setUrl($url);
$shortener->setFeuser(42);
$shortlink = $shortener->getShorturlWithDomain();

REST Interface

The entrypoint you define in the extension-setup (default: /goto/) can be used as a Restful Interface API for creating, updating and deleting shortened URLs.

To enable this feature you need to go to the TYPO3 Backend and into the Settings Module and open the 'Configure Extensions' Dialog.

Here you open the configuration options of the 'shortcutlink' extension.

You will find a button 'generate a new API key'. Klick that Button and a new key will be generated. Make sure to copy it once it is generated, it can not be restored. Save the configuration after that.

This key can now be used for POST,PUT and DELETE operations by adding it as a header named 'ApiKey' to the HTTP Request header.

To create a new shortened url you will use the POST method without a key after /goto/

Here is an example with curl:

curl -X POST \
-d "url=https://google.com" \
-H "ApiKey: GTeZNuFWHfMxSTBf2krrasTCu9INcmHa5KwQ12uggDM" \
http://mysite/goto/

The response will be the shortlink URL as text/plain. For example:

http://mysite/goto/4J5tqQUkVnc

Alternatively you can use a json-encoded string as payload, if you set the Content-type to application/json. The answer will still be text/plain though:

curl -X POST \
-d '{"url":"https://google.com"}' \
-H "Content-type: application/json" \
-H "ApiKey: GTeZNuFWHfMxSTBf2krrasTCu9INcmHa5KwQ12uggDM" \
http://mysite/goto/

Possible fields in the payload are:

  • url = the url to shorten (required)
  • feuser = a frontenduser id this shortcode is locked to (optional)

Possible return codes are:

  • 200 - Success
  • 304 Forbidden - when the ApiKey is wrong or missing
  • 500 Invalid Payload - when the payload is not valid

To update a shortened url you would use the PUT method on the shortened URL. PUT supports like POST a json encoded and a query encoded payload.

for example:

curl -X PUT \
-d '{"url":"https://bing.com"}' \
-H "Content-type: application/json" \
-H "ApiKey: GTeZNuFWHfMxSTBf2krrasTCu9INcmHa5KwQ12uggDM" \
http://mysite/goto/4J5tqQUkVnc

The body will simply contain OK on an successfull update. If the shortened URL is locked to a user, the userid needs to be provided as well. Only the URL can be updated, not the user.

Possible return codes are:

  • 200 - Success
  • 304 Forbidden - when the ApiKey is wrong or missing
  • 500 Invalid Payload - when the payload is not valid
  • 404 - if the shortened URL is not valid
  • 403 - if a feuser has been provided but doesn't match the stored user

Respectively the method DELETE will delete a shortened url. DELETE does not require a payload.

curl -X DELETE \
-H "ApiKey: GTeZNuFWHfMxSTBf2krrasTCu9INcmHa5KwQ12uggDM" \
http://mysite/goto/4J5tqQUkVnc

The body will simply contain OK on an successfull delete.

Possible return codes are:

  • 200 - Success
  • 304 Forbidden - when the ApiKey is wrong or missing
  • 404 - if the shortened URL is not valid

TODO: Documentation

sudhaus7/shortcutlink 适用场景与选型建议

sudhaus7/shortcutlink 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.55k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2020 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「url」 「shortener」 「typo3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sudhaus7/shortcutlink 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sudhaus7/shortcutlink 我们能提供哪些服务?
定制开发 / 二次开发

基于 sudhaus7/shortcutlink 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.55k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-05