<commit_before><?php
class Kwc_Mail_Redirect_Component extends Kwc_Abstract
{
    protected $_params = array();

    public static function getSettings()
    {
        $ret = parent::getSettings();
        $ret['childModel'] = 'Kwc_Mail_Redirect_Model';
        $ret['viewCache'] = false;
        $ret['flags']['processInput'] = true;
        $ret['contentSender'] = 'Kwc_Mail_Redirect_ContentSender';
        return $ret;
    }

    public final function getRedirectRow()
    {
        return $this->_getRedirectRow();
    }

    protected function _getRedirectRow()
    {
        if (!$this->_params || empty($this->_params['redirectId'])) {
            throw new Kwf_Exception("params in object must be set before _getRedirectRow is called");
        }

        $r = $this->getChildModel()->getRow($this->_params['redirectId']);
        if (!$r) {
            throw new Kwf_Exception("The redirect row was not found");
        }
        return $r;
    }

    public function processInput($inputData)
    {
        if (empty($inputData['d'])) {
            throw new Kwf_Exception_NotFound();
        }

        $params = explode('_', $inputData['d']);
        if (count($params) < 4) {
            throw new Kwf_Exception_Client("Too few parameters submitted");
        }

        $modelClass = $this->_getRecipientModelClass($params[2]);
        if (!$modelClass) throw new Kwf_Exception_NotFound();
        $params = array(
            'redirectId' => $params[0],
            'recipientId' => $params[1],
            'recipientModelShortcut' => $params[2],
            'recipientModelClass' => $modelClass,
            'hash' => $params[3]
        );
        $this->_params = $params;

        // check the hash
        if ($params['hash'] != $this->_getHash(array(
            $params['redirectId'], $params['recipientId'], $params['recipientModelShortcut']
        ))) {
            throw new Kwf_Exception_Client("The submitted hash is incorrect.");
        }

        // statistics
        $statModel = Kwf_Model_Abstract::getInstance('Kwc_Mail_Redirect_StatisticsModel');
        // avoid double insert (e.g. click on link in kmail)
        $statSel = $statModel->select()
            ->whereEquals('mail_component_id', $this->getData()->parent->componentId)
            ->whereEquals('redirect_id', $params['redirectId'])
            ->whereEquals('recipient_id', $params['recipientId'])
            ->whereEquals('recipient_model_shortcut', $params['recipientModelShortcut'])
            ->where(new Kwf_Model_Select_Expr_Higher('click_date', new Kwf_DateTime(time() - 10)));
        if (isset($_SERVER['REMOTE_ADDR'])) {
            $statSel->whereEquals('ip', $_SERVER['REMOTE_ADDR']);
        }
        if (!$statModel->getRow($statSel)) {
            $statRow = $statModel->createRow(array(
                'mail_component_id' => $this->getData()->parent->componentId,
                'redirect_id' => $params['redirectId'],
                'recipient_id' => $params['recipientId'],
                'recipient_model_shortcut' => $params['recipientModelShortcut'],
                'click_date' => date('Y-m-d H:i:s')
            ));
            if (isset($_SERVER['REMOTE_ADDR'])) $statRow->ip = $_SERVER['REMOTE_ADDR'];
            $statRow->save();
        }

        $r = $this->_getRedirectRow();
        if ($r->type == 'showcomponent') {
            $recipientRow = Kwf_Model_Abstract::getInstance($params['recipientModelClass'])
                ->getRow($params['recipientId']);
            $c = Kwf_Component_Data_Root::getInstance()
                ->getComponentById($r->value)->getComponent();<commit_msg>call _getRedirectRow() only once<commit_after><?php
class Kwc_Mail_Redirect_Component extends Kwc_Abstract
{
    protected $_params = array();
    protected $_redirectRow = null;

    public static function getSettings()
    {
        $ret = parent::getSettings();
        $ret['childModel'] = 'Kwc_Mail_Redirect_Model';
        $ret['viewCache'] = false;
        $ret['flags']['processInput'] = true;
        $ret['contentSender'] = 'Kwc_Mail_Redirect_ContentSender';
        return $ret;
    }

    public final function getRedirectRow()
    {
        if (!$this->_redirectRow) {
            $this->_redirectRow = $this->_getRedirectRow();
        }
        return $this->_redirectRow;
    }

    protected function _getRedirectRow()
    {
        if (!$this->_params || empty($this->_params['redirectId'])) {
            throw new Kwf_Exception("params in object must be set before _getRedirectRow is called");
        }

        $r = $this->getChildModel()->getRow($this->_params['redirectId']);
        if (!$r) {
            throw new Kwf_Exception("The redirect row was not found");
        }
        return $r;
    }

    public function processInput($inputData)
    {
        if (empty($inputData['d'])) {
            throw new Kwf_Exception_NotFound();
        }

        $params = explode('_', $inputData['d']);
        if (count($params) < 4) {
            throw new Kwf_Exception_Client("Too few parameters submitted");
        }

        $modelClass = $this->_getRecipientModelClass($params[2]);
        if (!$modelClass) throw new Kwf_Exception_NotFound();
        $params = array(
            'redirectId' => $params[0],
            'recipientId' => $params[1],
            'recipientModelShortcut' => $params[2],
            'recipientModelClass' => $modelClass,
            'hash' => $params[3]
        );
        $this->_params = $params;

        // check the hash
        if ($params['hash'] != $this->_getHash(array(
            $params['redirectId'], $params['recipientId'], $params['recipientModelShortcut']
        ))) {
            throw new Kwf_Exception_Client("The submitted hash is incorrect.");
        }

        // statistics
        $statModel = Kwf_Model_Abstract::getInstance('Kwc_Mail_Redirect_StatisticsModel');
        // avoid double insert (e.g. click on link in kmail)
        $statSel = $statModel->select()
            ->whereEquals('mail_component_id', $this->getData()->parent->componentId)
            ->whereEquals('redirect_id', $params['redirectId'])
            ->whereEquals('recipient_id', $params['recipientId'])
            ->whereEquals('recipient_model_shortcut', $params['recipientModelShortcut'])
            ->where(new Kwf_Model_Select_Expr_Higher('click_date', new Kwf_DateTime(time() - 10)));
        if (isset($_SERVER['REMOTE_ADDR'])) {
            $statSel->whereEquals('ip', $_SERVER['REMOTE_ADDR']);
        }
        if (!$statModel->getRow($statSel)) {
            $statRow = $statModel->createRow(array(
                'mail_component_id' => $this->getData()->parent->componentId,
                'redirect_id' => $params['redirectId'],
                'recipient_id' => $params['recipientId'],
                'recipient_model_shortcut' => $params['recipientModelShortcut'],
                'click_date' => date('Y-m-d H:i:s')
            ));
            if (isset($_SERVER['REMOTE_ADDR'])) $statRow->ip = $_SERVER['REMOTE_ADDR'];
            $statRow->save();
        }

        $r = $this->getRedirectRow();
        if ($r->type == 'showcomponent') {
            $recipientRow = Kwf_Model_Abstract::getInstance($params['recipientModelClass'])
                ->getRow($params['recipientId']);
            $c = Kwf_Component_Data_Root::getInstance()
                ->getComponentById($r->value)->getComponent();
{'fraction_non_alphanumeric': 0.15329648105703114, 'fraction_numerical': 0.0021572064176890926, 'mean_word_length': 2.522317188983856, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 90, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5540694', 'n_tokens_mistral': 2162, 'n_tokens_neox': 2056, 'n_words': 371}