aerni/social-links 问题修复 & 功能扩展

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

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

aerni/social-links

Composer 安装命令:

composer require aerni/social-links

包简介

Easily generate Social Sharing Links

README 文档

README

This addon provides an easy way to create social profile and sharing links for channels like Facebook, Twitter and more.

Installation

Install the addon using Composer.

composer require aerni/social-links

Supported Channels

This addon supports the following social channels: Facebook, GitHub, Instagram, LinkedIn, Mail, Pinterest, Telegram, Twitter, Vimeo, WhatsApp, Xing, YouTube

Profile Link

Create a link to a social profile by providing the social channel and handle of the profile:

{{ social:profile channel="facebook" handle="michaelaerni" }}

Or using the shorthand:

{{ social:facebook:profile handle="michaelaerni" }}

Sharing Link

Create a sharing link by providing the social channel:

{{ social:share channel="facebook" }}

Or using the shorthand:

{{ social:facebook:share }}

Parameters

There are a number of parameters you may use to customize the sharing links:

Facebook

Name Description Usage
url The URL of the page to share Optional
text The text of your post Optional

LinkedIn

Name Description Usage
url The URL of the page to share Optional
title The title of your post Optional
text The text of your post Optional
source The source of your post Optional

Mail

Name Description Usage
url The URL of the page to share Optional
to The email address you want to send the email to Optional
cc The email address to CC Optional
bcc The email address to BCC Optional
subject The subject of the email Optional
body The body of the email Optional

The url will be placed in the body of the email by default. You can customize the email body text by using the body parameter. Note, that this will override the default body text that includes the url. You will have to manually add the url in the body parameter like so:

{{ social:mail:share body="I want to share this great site with you: {permalink}" }}

Pinterest

Name Description Usage
url The URL of the page to share Optional
image The image to share Optional

Telegram

Name Description Usage
url The URL of the page to share Optional
text The description of your shared page Optional

Twitter

Name Description Usage
url The URL of the page to share Optional
text The text of your Tweet Optional
handle The twitter handle you want to add to the Tweet Optional

WhatsApp

Name Description Usage
url The URL of the page to share Optional

Xing

Name Description Usage
url The URL of the page to share Optional

Channel Name

Get the name of a social channel:

{{ social:name channel="facebook" }}

Or using the shorthand:

{{ social:facebook:name }}

Tag Pair

You may also use a tag pair to get all the data at once:

{{ social channel="facebook" handle="michaelaerni" }}
  {{ profile }}
  {{ share }}
  {{ name }}
{{ /social }}

Or using the shorthand:

{{ social:facebook handle="michaelaerni" }}
  {{ profile }}
  {{ share }}
  {{ name }}
{{ /social:facebook }}`

Extending

You can register your own custom channels in two ways.

Creating a Custom Channel

Create a class that extends BaseChannel. A channel can support profile links, share links, or both. All params passed to the Antlers tag are available in the channel via $this->params->get('param_name').

Profile Channels

To support profile links, set the $profileBaseUrl property. The profile URL is built by appending the handle param to the base URL. The handle param must be provided on the Antlers tag.

Property/Method Description
$profileBaseUrl The base URL for profile links.
use Aerni\SocialLinks\Channels\BaseChannel;

class Mastodon extends BaseChannel
{
    protected string $profileBaseUrl = 'https://mastodon.social';
}

Share Channels

To support share links, set the $shareBaseUrl property and override shareUrlParams() to define the query parameters for the share URL. The url param defaults to the current page URL if not explicitly provided on the Antlers tag.

Property/Method Description
$shareBaseUrl The base URL for share links.
shareUrlParams() Override this method to define the query parameters for the share URL. Must return an array.
$encodeShareUrlQuery Whether to URL-encode the share URL query string. Defaults to true. Set to false for channels like Mail that need raw URLs.
use Aerni\SocialLinks\Channels\BaseChannel;

class Reddit extends BaseChannel
{
    protected string $shareBaseUrl = 'https://www.reddit.com/submit';

    protected function shareUrlParams(): array
    {
        return [
            'url' => $this->params->get('url'),
            'title' => $this->params->get('title'),
        ];
    }
}

If you need dynamic logic for the base URL, override the profileBaseUrl() or shareBaseUrl() method instead of using the property.

Registering via Config

Publish the config file and add your channel class to the channels array in config/social-links.php:

return [
    'channels' => [
        App\Channels\Mastodon::class,
    ],
];

Registering Programmatically

Register a channel from a service provider's boot() method:

use App\Channels\Mastodon;

public function boot(): void
{
    Mastodon::register();
}

aerni/social-links 适用场景与选型建议

aerni/social-links 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37.91k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2020 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 aerni/social-links 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 37.91k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-29