Jump to content

How to add support for country restrictions on videos


Tech Support

Recommended Posts

In KVS there is no built-in support for country restrictions. The main reason is that KVS caching engine doesn't allow having these restrictions along with site caching, so for now we don't have any way to add this feature.

However, if you discount caching aspect, it is possible to activate this feature with few theme adjustments. Disabling caching could have negative impact on your database load. But in this case you will only disable cache for video_view block, which is not the hardest block to be rendered.

 

Step 1. First of all you need to switch off caching for the View Video page and video_view block on it. In order to do that go to Website UI -> Pages and search for video_view there. This will show you all pages that have this block (by default your theme will only have one page and block with caching time set to 3600 on both). Set caching time to 0 in both page and block fields (by default it will have 3600) and use Save caching option:

disable_video_view_cache.thumb.png.b69818de3f798c3bd9df07f8d942b307.png

 

Step 2. Go to Settings -> Customization and activate some custom text field in Videos. This will be the field where you need to list country codes of the countries where a specific video should be blocked. The format of the data is comma-separated list of 2-symbol country codes, for example like this:

video_countries.png.cba30976eded7c248cb4dcb2b081af45.png

NOTE: the actual formatting doesn't matter, possible to specify in lower case, or without space between commas.

 

Step 3. In Website UI -> Pages -> View Video page -> video_view block template find this fragment:

{{if $data.status_id==5 || $data.status_id==2 || $data.status_id==3}}
	<div class="no-player" style="width: 100%; height: 0; padding-bottom: {{$player_size[1]/$player_size[0]*100|replace:",":"."}}%; background: black">
		<span class="message">{{$data.delete_reason|default:$lang.videos.video_player_deleted}}</span>
	</div>
{{elseif $is_limit_over==1}}
	....

 

Add the following block right before it:

{{assign var="blocked_countries" value=","|explode:$data.custom1}}
{{assign var="is_blocked_by_country" value="false"}}
{{foreach from=$blocked_countries item="country_code"}}
	{{if $country_code|trim|strtolower==$smarty.server.GEOIP_COUNTRY_CODE|strtolower}}
		{{assign var="is_blocked_by_country" value="true"}}
	{{/if}}
{{/foreach}}
{{if $is_blocked_by_country=='true'}}
	<div class="no-player" style="width: 100%; height: 0; padding-bottom: {{$player_size[1]/$player_size[0]*100|replace:",":"."}}%; background: black">
		<span class="message">This video is not available in your country</span>
	</div>

 

and it order to make the smarty syntax complete you should changed {{if}} with {{elseif}} in the mentioned before block in the first line:

{{elseif $data.status_id==5 || $data.status_id==2 || $data.status_id==3}}
	<div class="no-player" style="width: 100%; height: 0; padding-bottom: {{$player_size[1]/$player_size[0]*100|replace:",":"."}}%; background: black">
		<span class="message">{{$data.delete_reason|default:$lang.videos.video_player_deleted}}</span>
	</div>
{{elseif $is_limit_over==1}}
	....

 

IMPORTANT! If you fail to insert this block into the correct place, or to correct the IF -> ELSEIF logic, your template code may become broken and in this case it will stop rendering player. Then go to Website UI -> Change history to find the previous template version and restore it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...