mltpss/laravel-sdk

Laravel用户的多重通行证包

v1.3.4 2018-04-16 14:14 UTC

README

Build Status Latest Stable Version Dependency Status

此包允许您轻松地将SQweb集成到由Laravel提供的网站中。

要求

此SDK已与PHP 5.5及更高版本进行了测试。

我们无法为早期版本提供官方支持。有关PHP分支的生命周期信息,请参阅此页面

安装

此包适用于由Laravel提供动力和高级集成的网站。

如果您正在使用WordPress,我们已经为您简化了操作。直接从WordPress.org下载SQweb插件,或在此处查看源代码

使用Composer

  1. 在项目根目录中,执行composer require mltpss/laravel-sdk;

  2. 现在,转到config/app.php并添加此行到您的提供者数组

    Sqweb\Laravel_sdk\SqwebServiceProvider::class,
  3. 在项目根目录中输入php artisan vendor:publish以创建配置文件。

  4. .env中,粘贴以下配置并将变量SQW_ID_SITE设置为您的网站ID,将变量SQW_SITENAME设置为要在大多重通行证按钮上显示的名称。

    SQW_ID_SITE=YOUR_WEBSITE_ID
    SQW_SITENAME=YOUR_WEBSITE_NAME

有关更多设置,请参阅下面的"选项"。

使用方法

SDK非常简单易用。以下是操作方法

1. 标记您的页面

此功能输出SQweb JavaScript标签。将其插入到HTML的</body>标签之前。

{{ $sqweb->script() }}

如果您之前已经有SQweb JavaScript标签,请确保将其删除以避免任何冲突。

2. 检查您的订阅者的信用额度

此功能检查用户是否有信用额度,这样您就可以禁用广告并/或解锁付费内容。

使用方法

@if ($sqweb->checkCredits())
    // CONTENT
@else
    // ADS
@endif

3. a) 显示多重通行证按钮

最后,使用此代码在您的页面上获取多重通行证按钮

{{ $sqweb->button() }}

我们为按钮提供了不同的尺寸,要使用它们,请将字符串传递给函数,例如

{{ $sqweb->button('tiny') }}
{{ $sqweb->button('slim') }}
{{ $sqweb->button('large') }}

Example Buttons

3. b) 自定义多重通行证按钮

如果您想自定义我们不同类型的按钮,请将以下内容放在您的.env文件中或在sqweb配置文件中。例如:SQW_LOGIN=Hello world将在未登录访客的常规按钮上显示Hello world而不是多重通行证付费版

4. 更多功能

为您的用户显示“支持我们”的信息

/**
 * Display a support block.
 */

function supportBlock() {   }
``

For instance:

```php
{!! $sqweb->supportBlock !!}

将显示此块。

为您的用户显示锁定div

/**
 * Display a locking block.
 */

function lockingBlock() {   }
``

For instance:

```php
{!! $sqweb->lockingBlock !!}

我们建议您将其与我们的过滤函数结合使用,例如

@if($sqweb->waitToDisplay('2016-09-15', 2))
    // The content here will appear the 2016-09-17, 2 days after the publication date for non paying users.
@else
    // Here you can put content that free users will see before the content above is available for all.
    // {!! $sqweb->lockingBlock !!}
@end

仅向非付费用户显示您的内容的一部分

/**
 * Put opacity to your text
 * Returns the text with opcaity style.
 * @param text, which is your text.
 * @param int percent which is the percent of your text you want to show.
 * @return string
 */
    public function transparent($text, $percent = 100) { ... }

示例

{!! $sqweb->transparent('one two three four', 50) !!}

将为免费用户显示

one two

稍后为非付费用户显示您的内

    /**
     * Display your premium content at a later date to non-paying users.
     * @param  string  $date  When to publish the content on your site. It must be an ISO format(YYYY-MM-DD).
     * @param  integer $wait  Days to wait before showing this content to free users.
     * @return bool
     */
    public function waitToDisplay($date, $wait = 0) { ... }

示例

@if($sqweb->waitToDisplay('2016-09-15', 2))
    // The content here will appear the 2016-09-17, 2 days after the publication date for non paying users.
@else
    // Here you can put content that free users will see before the content above is available for all.
@end

限制免费用户每天可阅读的文章数量

    /**
     * Limit the number of articles free users can read per day.
     * @param $limitation int The number of articles a free user can see.
     * @return bool
     */
    public function limitArticle($limitation = 0) { ... }

示例:如果我想为免费用户仅显示5篇文章

@if ($sqweb->limitArticle(5) == true)
    echo "This is my article";
@else
    echo "Sorry, you reached the limit of pages you can see today, come back tomorrow or subscribe to Multipass to get unlimited articles !";
@endif

选项

除非另有说明,否则以下选项默认为false。您可以在.env文件中设置它们。

贡献

我们欢迎贡献和改进。

编码风格

所有PHP代码都必须符合PSR2标准

构建和发布

请参阅 RELEASE.md

错误和安全漏洞

如果您遇到任何错误或意外行为,您可以通过以下方式报告:在Github上使用错误跟踪器,或者通过电子邮件发送到 hello@sqweb.com。我们将尽快与您联系。

如果您在SQweb或此插件中发现了安全漏洞,请通过电子邮件发送到 security@sqweb.com。我们将及时处理漏洞。

许可证

版权所有 (C) 2018 – SQweb

本程序是免费软件;您可以在自由软件基金会发布的GNU通用公共许可证的条款下重新分发和/或修改它;许可证的版本可以是第3版或任何更新的版本。

本程序的分发是希望它将是有用的,但没有任何保证;甚至没有关于其商业性或适用于特定目的的暗示保证。有关详细信息,请参阅GNU通用公共许可证。

您应该已经随本程序收到了GNU通用公共许可证的副本。如果没有,请参阅https://gnu.ac.cn/licenses/