sqweb / symfony_bundle
Requires
- php: >=5.5.0
- twig/twig: ^2.0
Requires (Dev)
- sebastian/phpcpd: ^2.0
- sebastian/version: 1.0.6
- squizlabs/php_codesniffer: dev-master
README
此包允许您轻松将 SQweb 集成到由 Symfony 驱动的网站上。
要求
此 SDK 已在 PHP 5.5 及更高版本上进行了测试。
我们无法为更早的版本提供官方支持。有关 PHP 分支的生命周期信息,请参阅此页面。
安装
此包适用于由 Symfony 驱动的网站。
如果您使用 WordPress,我们已为您简化操作。直接从 WordPress.org 下载 SQweb 插件,或在此处查看源代码 此处。
使用 Symfony 3.x
-
在项目根目录中,执行
composer require mltpss/symfony-bundle
。现在,转到app/AppKernel.php
并将此行添加到您的捆绑数组中new SQweb\SQwebBundle\SQwebSQwebBundle()
-
在
app/config/config.yml
中# Twig configuration
之后添加twig: globals: sqweb: "@s_qweb_s_qweb.SQweb"
-
并在您的
config.yml
文件的末尾添加# SQweb | Multipass Configuration s_qweb_s_qweb: config: id_site: 00000 sitename: "website_name" debug: false targeting: false beacon: false dwide: false autologin: true lang: "en_US" message: "" login: "" support: "" connected: "" btn_noads: "" login_tiny: "" connected_s: "" btn_unlimited: "" connected_tiny: "" connected_support: ""
别忘了相应地设置您的 id_site
、sitename
和 lang
。
有关其他设置信息,请参阅下文的 "选项"。
使用 Symfony 4.x
-
确保您正在使用 twig bundle,如果不是,请在项目根目录中执行以下命令:
composer require twig
-
现在转到
packages/twig.yaml
并复制粘贴以下代码。确保在此行上使用您的真实 id_site:id_site: 00000
并将"website_name"
替换为您的实际网站名称。twig: [...] globals: sqweb: "@s_qweb_s_qweb.SQweb" # SQweb | Multipass Configuration s_qweb_s_qweb: config: id_site: 00000 sitename: "website_name" debug: false targeting: false beacon: false dwide: false autologin: true lang: "en_US" message: "" login: "" support: "" connected: "" btn_noads: "" login_tiny: "" connected_s: "" btn_unlimited: "" connected_tiny: "" connected_support: ""
别忘了相应地设置您的
id_site
、sitename
和lang
。有关其他设置信息,请参阅下文的 "选项"。
-
在项目根目录中,执行
composer require mltpss/symfony-bundle
。
使用方法
1. 标记您的页面
此函数输出 SQweb JavaScript 标签。将其插入到您的 HTML 的 </body>
标签之前。
{{ sqweb.script|raw }}
如果您之前有 SQweb JavaScript 标签,请确保将其删除以避免任何冲突。
2. 检查您的订阅者的积分
如果用户订阅了 multipass,则此变量为 true
,如果没有订阅,则为 false
,这样您就可以禁用广告或解锁付费内容。
使用方法如下
{% if sqweb.abo %} //CONTENT {% else %} //ADS {% endif %}
3. a) 显示 Multipass 按钮
最后,使用此代码在您的页面上显示 Multipass 按钮
{{ sqweb.button|raw }}
我们提供了不同大小的按钮,以下是如何使用它们的示例:
{{ sqweb.buttonTiny|raw }} OR {{ sqweb.buttonSlim|raw }} OR {{ sqweb.buttonLarge|raw }}
3. b) 自定义 Multipass 按钮
如果您想自定义我们不同类型的按钮,请编辑以下内容到您的 config.yaml
文件中。
例如
# SQweb Configuration s_qweb_s_qweb: config: ... login:"Hello world" ...
在未登录访客的常规按钮上显示 Hello world
而不是 Premium with Multipass
。
按钮模型 | 登录状态 | 未登录状态 |
---|---|---|
迷你型 | connected_tiny |
login_tiny |
常规 | connected |
login |
大号 - 在黑点之前 | N / A | btn_unlimited |
大号 - 在黑点之后 | N / A | btn_noads |
大号 connected | connected_s |
N / A |
4. 更多功能
为您的用户显示支持div
/** * Display a support block. */ function supportBlock() { } `` For instance: ```php {{sqweb.supportBlock|raw}}
将显示该块。
为您的用户显示锁定div
/** * Display a locking block. */ function lockingBlock() { } `` For instance: ```php {{sqweb.lockingBlock|raw}}
将显示该块。我们建议您将其与我们的其他限制功能结合使用,例如
{% 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 display a message that free users will see while your article is not displayed {{sqweb.lockingBlock|raw}} {% endif %}
仅向非高级用户显示您的内容的一部分
/** * 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.transpartext('one two three four', 50)|raw }}
将显示免费用户
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 display a message that free users will see while your article is not displayed {% endif %}
限制免费用户每天可以阅读的文章数量
/* * @param int $limitation Number of articles a free user can see. */ function limitArticle($limitation = 0) { ... }
例如,如果我想向免费用户显示5篇文章
{% if sqweb.limitArticle(5) %} // Put your content here {% else %} // Here you can display a message that free users will see while your article is not displayed {% endif %}
选项
除非另有说明,否则以下选项默认为 false
。您可以在配置文件中设置它们,例如:config.yml
。
选项 | 描述 |
---|---|
id_site |
设置您的网站SQweb ID。例如:123456。 |
sitename |
将在我们按钮的大号版本中显示的名称。您必须设置此变量。 |
debug |
在插件执行时向浏览器控制台输出各种消息。 |
dwide |
设置为 false 仅在当前域上启用 SQweb。默认为 true 。 |
lang |
您可以选择 en_US 和 fr_FR 之间的任一选项。 |
autologin |
自动登录您的网站上的Multipass用户。 |
贡献
我们欢迎贡献和改进。
编码风格
所有PHP代码都必须符合PSR2标准。
错误和安全漏洞
如果您遇到任何错误或意外的行为,您可以通过GitHub上的错误跟踪器报告,或者通过电子邮件至 hello@sqweb.com
。我们将尽快与您联系。
如果您在SQweb或此插件中发现安全漏洞,请通过电子邮件至 security@sqweb.com
。漏洞将得到及时处理。
许可证
版权(C)2016 – SQweb
本程序是自由软件;您可以根据自由软件基金会发布的GNU通用公共许可证的条款重新分发和/或修改它;许可证的版本可以是第3版,或者(根据您的选择)任何后续版本。
本程序的分发是希望它是有用的,但没有任何保证;甚至不包括适销性或特定用途适用性的隐含保证。有关详细信息,请参阅GNU通用公共许可证。
您应该已收到随本程序一起提供的GNU通用公共许可证副本。如果没有,请参阅https://gnu.ac.cn/licenses/。