mltpss / symfony-bundle
SQweb包,适用于Symfony用户
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包,如果不是,请在项目根目录中执行以下命令:
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
,如果没有,则为此,您可以禁用广告和/或解锁付费内容。
使用方式如下
{% 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
。
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
。
贡献
我们欢迎贡献和改进。
编码风格
所有PHP代码必须遵循PSR2标准。
错误和安全漏洞
如果您遇到任何错误或意外的行为,您可以报告到Github的bug跟踪器,或者通过电子邮件发送至hello@sqweb.com
。我们会尽快与您联系。
如果您在SQweb或此插件中发现安全漏洞,请通过电子邮件发送至security@sqweb.com
。我们会及时处理漏洞。
许可证
版权(C)2016 – SQweb
本程序是免费软件;您可以在自由软件基金会发布的GNU通用公共许可证的条款下重新分发和/或修改它;许可证的版本可以是第3版,或者(根据您的选择)任何后续版本。
本程序的分发是希望它是有用的,但没有任何保证;甚至没有关于其商业性或适用于特定目的的暗示性保证。有关详细信息,请参阅GNU通用公共许可证。
您应该已经随本程序收到了GNU通用公共许可证的一份副本。如果没有,请参见https://gnu.ac.cn/licenses/。