b13/magnets 问题修复 & 功能扩展

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

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

b13/magnets

最新稳定版本:3.0.1

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.

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 10
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2019-04-02