/**
     * recognizes match from referrer by DirectLink feature
     *
     * @return array
     */
    protected function getMatch(Pap_Contexts_Click $context, $referrerUrl) {
        if(Gpf_Settings::get(Pap_Settings::SUPPORT_DIRECT_LINKING) != Gpf::YES) {
            $context->debug('  DirectLink tracking is not supported');
            return null;
        }

        if($referrerUrl == '') {
            $context->debug('Referrer URL empty');
            return null;
        }
        	
        $context->debug('  Trying to recognize affiliate from referrer URL (DirectLink): \'' . $referrerUrl . '\'');
        $directLinksBase = Pap_Tracking_DirectLinksBase::getInstance();
        try {
            $match = $directLinksBase->checkDirectLinkMatch($referrerUrl);
            return $match;
        } catch(Gpf_Exception $e) {
            $context->debug('Exception :'.$e->getMessage());
            return null;
        }
    }
    /**
     *
     * @service direct_link read_own
     * @param Gpf_Rpc_Params $params (pattern, url)
     * @return Gpf_Rpc_Action
     */
    public function checkUrlMatch(Gpf_Rpc_Params $params) {
        $action = new Gpf_Rpc_Action($params);
        $action->setErrorMessage($this->_("Pattern didn't matched the URL, check your pattern"));
        $action->setInfoMessage($this->_("Pattern matched the URL"));

        $pattern = $action->getParam("pattern");
        $url = $action->getParam("url");

        $url = str_replace('https://', '', $url);
        $url = str_replace('http://', '', $url);

        $directLinksBase = Pap_Tracking_DirectLinksBase::getInstance();
        $pattern = $directLinksBase->transformToPreg($pattern);

        if ($directLinksBase->isMatch($url, '', $pattern)) {
            $action->addOk();
        } else {
            $action->addError();
        }

        return $action;
    }
    private function createSampleDirectLinkUrl() {
        $directLinkUrl = new Pap_Db_DirectLinkUrl();
        $directLinkUrl->setId('11111111');
        $directLinkUrl->setPapUserId('11111111');
        $directLinkUrl->setUrl('*tests/banners_linking.*');
        $directLinkUrl->setStatus('A');
        $directLinkUrl->save();

        $directLinksBase = Pap_Tracking_DirectLinksBase::getInstance();
        $directLinksBase->regenerateDirectLinksFile();
    }
 /**
  * @service direct_link add
  * @param $fields
  */
 public function add(Gpf_Rpc_Params $params) {
     $ret = parent::add($params);
     Pap_Tracking_DirectLinksBase::getInstance()->regenerateDirectLinksFile();
     return $ret;
 }