mh/collection

我的工具箱

1.0.6 2019-02-12 11:32 UTC

This package is auto-updated.

Last update: 2024-09-13 12:40:12 UTC


README

这是我在大部分工作中使用的工具集合

MaxMind

下载文件 https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz,解压后你将获得 mmdb 文件。

<?php

require_once 'vendor/autoload.php';

use GeoIp2\Database\Reader;

$reader = new Reader(__DIR__.'/GeoLite2-City/GeoLite2-City.mmdb');
$record = $reader->city('84.227.20.193');

var_dump($record->country->isoCode);

ld-json

支持谷歌丰富片段的相当酷的包

<?php

$title = 'This is my awesome blog';
$description = 'This post is about loan and good stuff';
$url = 'http://this.blog/1';
$author = 'this.blog';
$publisher = $author;
$datePublished = '2019-01-01';
$image = 'http://this.image.url';

$json = \JsonLd\Context::create('article', [
    'headline' => $title,
    'description' => $description,
    'mainEntityOfPage' => $url,
    'author' => $author,
    'publisher' => [
        'name' => $publisher,
    ],
    'datePublished' => $datePublished,
    'image' => $image,
]);

echo $json;

open graph

记得也要添加 open graph 支持

<?php

require_once(__DIR__.'/../vendor/autoload.php');

use ChrisKonnertz\OpenGraph\OpenGraph;

$title = 'This is my blog';
$image = 'http://www.image.url';
$description = 'This is going to happen in 2019';
$url = 'http://this.blog.url';

$og = new OpenGraph();
$og->type('article')
    ->title($title)
    ->image($image)
    ->description($description)
    ->url($url)
    ;

var_dump($og->renderTags());

社交分享 URL

添加方便的社交媒体分享集成

<?php

require_once(__DIR__.'/vendor/autoload.php');

use \drmonkeyninja\SocialShareUrl\SocialShareUrl;

$SocialShareUrl = new SocialShareUrl();
$url = $SocialShareUrl->getUrl('facebook', 'http://example.com');

var_dump($url);