Sponsorship is one of the most important features of the phpFox platform. Purpose of this tutorial is to provide some guideline for developers who want to integrate this feature with their apps.
Sponsor in app's block
...
# | Name | Description |
---|---|---|
1 | can_sponsor_ | Can members of this user group mark a an |
2 |
| How much is does the sponsor space worth for |
3 | auto_publish_sponsored_ | After the user has purchased a sponsored space, should the |
Note: replace {{
app
}} with your app's alias
...
Sponsor methods
phpFox provides 2 sponsor methods: Sponsor without fee and Purchase sponsor.
Sponsor without fee
When can_sponsor_{{app
}} is Yes, user users of that user group can sponsor item without paying fee.
All you have to do in your app is mark item as sponsor by database query and don't forget to add sponsor via function addSponsor()
in class Ad_Service_Process
.
...
Code Block | ||||
---|---|---|---|---|
| ||||
{permalink module='ad.sponsor' id={item-id}} section_={{itemapp}} |
...
Note:
replace
{{{{}}}}
app
with
your
item
app
alias
and
{{{}}}
item-id
with
your
item
id.
If your app has multiple items, please replace
...
app
...
with
...
app_item
...
(Ex: music_song, music_album, ...)
Code Block | ||||
---|---|---|---|---|
|
...
{permalink module='ad.sponsor' id={item-id} |
...
section |
...
={ |
...
app_item}}
|
Callbacks
Belows is all required callbacks when integrating your app with Ad Sponsor.
# | Function name (Single item) | Function name (Multiple item | Description |
---|---|---|---|
1 | getToSponsorInfo | getToSponsorInfo{{itemItem}} | Get info of sponsor item |
2 | deleteSponsorItem | deleteSponsorItem{{itemItem}} | Callback when sponsor is deleted in AdminCP, you can use this callback to set that item as un-sponsor so that user can sponsor it again |
3 | enableSponsor | enableSponsor{{itemItem}} | Callback when sponsor is published, mark your item as sponsored |
4 | getLink | getLink{{itemItem}} | Get url of your sponsor item |
...
Sponsor in feed depends on 4 user group settings of Feed app Feed below.
# | Name | Description |
---|---|---|
1 | feed.can_purchase_sponsor | Can members of this user group purchase a sponsored ad space? |
2 | feed.can_sponsor_feed | Can members of this user group define a feed as sponsored without paying? |
3 | feed.feed_sponsor_price | How much does it cost to sponsor a feed post? This works in a CPM basis |
4 | feed.auto_publish_sponsored_item | After the user has purchased a sponsored space, should the item be published right away? If set to false, the admin will have to approve each new purchased sponsored event space before it is shown in the site. |
...
Code Block | ||||
---|---|---|---|---|
| ||||
{url link='ad.sponsor' where='feed' section='{{app}}' item={item-id}} |
...
Note:
replace
{{{{}}}}
app
with
your
item
app
alias
and
{{{}}}
item-id
with
your
item
id.
If your app has multiple items, please replace
...
app
...
with
...
app_item
...
(Ex: music_song, music_album, ...)
Code Block | ||||
---|---|---|---|---|
|
...
{url link='ad.sponsor' where='feed' section='{ |
...
app_item} |
...
' item={item-id}}
|
...
Un-sponsor action
To unsponsor un-sponsor an item, we usually use ajax call
Code Block | ||||
---|---|---|---|---|
| ||||
$.ajaxCall('ad.removeSponsor', 'type_id={{app}}&item_id={item`item-id}id`', 'GET'); |
Note: don't forget to replace {{
app
}}/{{app_item
}} and {{app-id
}}
Or we can use function deleteSponsor
of class Ad_Service_Process
.
Code Block | ||||
---|---|---|---|---|
|
...
Phpfox::getService('ad.process')->deleteSponsor($iSponsorId, true);
|
Check sponsored item
To check sponsored item, you can use function canSponsoredInFeed
of class Feed_Service_Feed
. This function will return true
if item is sponsored.
Code Block | ||||
---|---|---|---|---|
| ||||
Phpfox::getService('feed')->canSponsoredInFeed({{app}}, {{app-id}}); |
Note: don't forget to replace {{
app
}}/{{app_item
}} and {{app-id
}}