Action-scripts (redirect-scripts)

Creating a Redirect in Version 4.0 and Later Versions

Create a new file of a redirect in the directory “/application/data/redirects/”, for example, “myredirect.php”;

The script template:

<?php
/**
 * @redirectName New redirect
 * @redirectWeight 100
 */
class myredirect_redirect extends AbstractRedirect2
{
    public function go(Stream $stream, Visitor $visitor) 
    {
        // Here the algorithm of a redirect, PHP code
        //
        // Basic methods: 
        //   $this->addHeader($string) — add header which send header() through php-function
        //   $this->setContent($string) — send a text to a buffer and then the text will be showed in a browser
    }
 
    public function goDebug(Stream $stream, Visitor $visitor)
    {	
         return "Redirecting to: " . $stream->getUrlWithParams($visitor);	
    }	
}

The class prefix must be the same as the file name.

An example

/application/redirects/jsiframe.php

<?php
/**
 * @redirectName JSIFrame
 * @redirectWeight 101
 */
class jsiframe_redirect extends AbstractRedirect2
{
    public function go(Stream $stream, Visitor $visitor)
    {
        $content = '<script type="text/javascript">
        function handle() { top.location="'.$stream->getUrlWithParams($visitor).'"; }
        window.onerror = handle;
        if (top.location.href != window.location.href) {top.location = "'.$stream->getUrlWithParams($visitor).'";}
      </script>';
 
        $this->setContent($content);
    }
 
    public function goDebug(Stream $stream, Visitor $visitor)
    {
         return "JSIFrame redirecting to: " . $stream->getUrlWithParams($visitor);  
    }
}

List of methods $stream

MethodDescription
getUrl a stream URL
getUrlWithParams($visitor) URL with parameters
getComments stream comment
getGroupId a group ID
getWeight a stream weight
isExitStream If it's an exit stream

List of methods $visitor

MethodDescription
getIp Visitor's IP
getIpLong IP as Number
getCountry Country (ISO code)
getRegion Region code
getBrowser Browsers
getOs OS
getSe Search Engine name
getOperator Cell data operator
getKeyword Keyword
getSource Source
getReferrer Referrer
getDeviceType Device type
getDeviceModel Device model
isBot Is it boot (boolean)
getParam(name)GET-param
getSubId()Unique Visitor's SubId
getSubId(n)sub_id_n
getExtraParam(n)extra_param_n