b13/magnets
Composer 安装命令:
composer require b13/magnets
包简介
Magnets: TYPO3 Service Package revolving around having a good API to fetch the current Geo IP and its location of the user.
README 文档
README
This extension acts as a thin wrapper for TYPO3 to access GeoIP relevant information.
A symfony CLI Command can be added to download the latest GeoIP2 data.
For download the latest GeoIP2 data you have to provide an licence-key from maxmind
(as .env-Variable or $GLOBALS['TYPO3_CONF_VARS']['SYS']['GeoIPLicenceKey'])
Maxmind API requests are limited (1000 requests/day). As an alternative the databases (GeoLite2-City, GeoLite2-Country) can be stored as a "Generic Package" in GitLab.
For Download during the CI run the CI_JOB_TOKEN can be used as follows:
if (!empty(getenv('CI_JOB_TOKEN'))) { $GLOBALS['TYPO3_CONF_VARS']['SYS']['GeoIPSource']['url'] = 'https://<GITLAB_HOST>/api/v4/projects/<PROJECT_ID>/packages/generic/GeoLite2/1.0.0/###REMOTE_EDITION###.tar.gz'; $GLOBALS['TYPO3_CONF_VARS']['SYS']['GeoIPSource']['headers'] = [ 'JOB-TOKEN' => getenv('CI_JOB_TOKEN'), ]; }
Installation
Run composer req b13/magnets and install the extension via Extension Manager.
Usage
Ensure your cronjob / scheduler task is running and use the IpLocation PHP class to have a nice and quick API.
In addition, you have "countryCode" as TypoScript condition available.
[countryCode == 'FR']
page.10 = TEXT
page.10.value = You are from france
[global]
The condition is also available in site configurations.
Settings
Headers to send while running the request to download the database.
Either use JOB-TOKEN or PRIVATE-TOKEN to authenticate on GitLab.
$GLOBALS['TYPO3_CONF_VARS']['SYS']['GeoIPSource']['headers'] = [];
Change the URL to retrieve the databases from.
The URL needs to include ###REMOTE_EDITION### which will be replaced by
the "remote edition" (GeoLite2-Country and GeoLite2-City).
$GLOBALS['TYPO3_CONF_VARS']['SYS']['GeoIPSource']['url'] = 'https://download.maxmind.com/app/geoip_download?suffix=tar.gz&edition_id=###REMOTE_EDITION###';
Store and Update databases using GitLab
Create a project and add a .gitlab-ci.yml
stages: - package-update geo-ip: stage: package-update image: alpine/curl:8.9.1 variables: GIT_STRATEGY: none GITLAB_RELEASE_VERSION: "1.0.0" PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/GeoLite2" script: # Download Maxmind GeoIP database - mkdir -p downloads - curl -sSL "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${GEOIP_LICENCE_KEY}&suffix=tar.gz" > downloads/GeoLite2-Country.tar.gz - curl -sSL "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=${GEOIP_LICENCE_KEY}&suffix=tar.gz" > downloads/GeoLite2-City.tar.gz # Upload files to package - 'curl --fail-with-body --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ./downloads/GeoLite2-Country.tar.gz ${PACKAGE_REGISTRY_URL}/${GITLAB_RELEASE_VERSION}/GeoLite2-Country.tar.gz' - 'curl --fail-with-body --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ./downloads/GeoLite2-City.tar.gz ${PACKAGE_REGISTRY_URL}/${GITLAB_RELEASE_VERSION}/GeoLite2-City.tar.gz'
Under Settings -> CI/CD -> Variables add a variable named "GEOIP_LICENCE_KEY" containing the licence-key.
For regular updates add a "New schedule" und Build -> Pipeline schedules.
e.g. 8 00 * * 1,3
License
Just as TYPO3 Core, this is an extension for TYPO3 and also licensed under GPL2+.
Made by b13 with ♥
Find more TYPO3 extensions we have developed that help us deliver value in client projects. As part of the way we work, we focus on testing and best practices to ensure long-term performance, reliability, and results in all our code.
b13/magnets 适用场景与选型建议
b13/magnets 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28.89k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2019 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 b13/magnets 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 b13/magnets 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 28.89k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2019-04-02