rezozero/social-links
Composer 安装命令:
composer require rezozero/social-links
包简介
Provide social network url for sharing.
README 文档
README
Usage
Install SocialLinks using Composer
composer require rezozero/social-links
Configure your SocialLinks instance with your data source and some output settings.
Load fontawesome CSS (base, regular and brands minimum) files in your HTML page.
// Construct a new SocialLinks $share = new \RZ\SocialLinks\SocialLinks(array( 'url' => 'http://www.rezo-zero.com', 'title' => 'REZO ZERO website homepage', // Optional image source url for pinterest. must be at least 200px by 200px, if you intent to use for facebook 'imageUrl' => 'http://www.rezo-zero.com/templates/rezo-zero/img/apple-icon.png', // Optional status for overriding title for twitter, whatsapp and emails body 'status' => 'Hey! Look at this awesome website.' )); // Set link class prefix $share->setClassPrefix('social-link'); // Set social icons class prefix // Use fa for Font Awesome or an // other for a custom icon set. $share->setIconPrefix('fa'); // Optional: // Set link additional classes, for example // to add "btn" bootstrap classes. $share->setLinkClasses('btn btn-default');
Single Url
echo $share->getUrl('twitter'); // https://twitter.com/intent/tweet?text=Hey%21%20Look%20at%20this%20awesome%20website.%20%E2%80%94%20http%3A%2F%2Fwww.rezo-zero.com
Single Link with icon
$share->setClassPrefix('social-link'); $share->setIconPrefix('fa'); echo $share->getLink('facebook', $share->getIcon('facebook')); // <a class="social-link social-link-facebook" target="_blank" rel="nofollow" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.rezo-zero.com"><i class="social-link-icon fa fa-brands fa-square-facebook"></i><span class="social-link-name">Facebook</span></a>
Single Link with SVG tag
$share->setClassPrefix('social-link'); $share->setIconPrefix('fa'); echo $share->getLink('facebook', $share->getUseSVG('facebook')); // <a class="social-link social-link-facebook" target="_blank" rel="nofollow" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.rezo-zero.com"><svg class="social-link-icon fa fa-brands fa-square-facebook"><use xlink:href="#fa-facebook"></use></svg><span class="social-link-name">Facebook</span></a>
A bunch of links with their icons
Without icons:
echo $share->getLinks(array('facebook', 'twitter', 'linked-in'));
With <i> icons:
echo $share->getLinksWithIcon(array('facebook', 'twitter', 'linked-in'));
With <svg> icons:
echo $share->getLinksWithSVG(array('facebook', 'twitter', 'linked-in'));
You also can choose a not empty separator, i.e. a dash:
echo $share->getLinksWithIcon(array('facebook', 'twitter', 'linked-in'), ' - ');
Available networks
- delicious
- digg
- evernote
- facebook (sharer by default, or /dialog/feed if you provide a
facebookAppId), if you use default font-awesome icon prefix, icon class will befacebook-official. It’s stillfacebookfor SVG icons or non font-awesome prefix. - friendfeed
- google-plus
- linked-in
- newsvine
- scoop-it
- slashdot
- stumbleupon
- tumblr
Twig extension
$twig->addExtension(new \RZ\SocialLinks\Twig\SocialLinksExtension());
SocialLinksExtension Twig extension introduces 3 new filters to be able
to generate your social links without any PHP code.
social_linksicon_social_linkssvg_social_linkstweet_links
First you’ll need to gather your social data in an associative array or
simply set a string variable (it will be used as the URL).
{% set social_data = {
'url': 'http://www.rezo-zero.com',
'title': 'REZO ZERO website homepage',
} %}
{# or #}
{% set social_data = 'http://www.rezo-zero.com' %}
Then, you can use one of the 3 SocialLinks filters with or without optional arguments. Selected networks can be set using an array or a simple string.
<nav class="social-links"> {{ social_data|social_links(['facebook', 'twitter']) }} </nav> <nav class="social-links"> {{ social_data|social_links('twitter') }} </nav> <nav class="social-links"> {{ social_data|icon_social_links( ['facebook', 'twitter'], 'icon-prefix', 'class-prefix', 'link-classes', 'Share on %s' ) }} </nav>
Bonus: tweet_links is a Twig filter to parse your tweets contents.
Translate share action label
We introduced shareActionLabel argument to provide title for accessibility on your social links. You can override it in your own Twig template to change the title and translate it:
<nav class="social-links"> {{ social_data|icon_social_links( ['facebook', 'twitter'], 'icon-prefix', 'class-prefix', 'link-classes', ('share_on_%s'|trans) ) }} </nav>
rezozero/social-links 适用场景与选型建议
rezozero/social-links 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.94k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2016 年 01 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 rezozero/social-links 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rezozero/social-links 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5.94k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 21
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-15
