<commit_before><?php

namespace Skaphandrus\AppBundle\Twig;

use Twig_Environment;
use Symfony\Component\Intl\Intl;
use Skaphandrus\AppBundle\Utils\Utils;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\Loader\ArrayLoader;

class UtilsExtension extends \Twig_Extension {

    protected $twig;
    protected $pathFunction;
    private $container;
    private $translator;
    private $request;

    public function __construct($container, Translator $translator, \Symfony\Component\HttpFoundation\RequestStack $requestStack)
    {
        $this->request = $requestStack->getCurrentRequest();
        $this->container = $container;
        $this->translator = $translator;
    }

    protected function getPathFunction() {
        if (empty($this->pathFunction)) {
            $this->pathFunction = $this->twig->getFunction('path')->getCallable();
        }

        return $this->pathFunction;
    }

    public function initRuntime(Twig_Environment $twig) {
        $this->twig = $twig;
    }

    public function getName() {
        return 'Skaphandrus App Utils';
    }

    public function getFunctions() {
        return array(
            // Intl helper functions.
            new \Twig_SimpleFunction('intl_country_name', array($this, 'intl_country_name')),
            new \Twig_SimpleFunction('intl_locale_name', array($this, 'intl_locale_name')),
// Link helper functions.
            // The "is_safe" parameter allows html, for rendering the links.
            new \Twig_SimpleFunction('link_to_user', array($this, 'link_to_user'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_user_profile', array($this, 'link_to_user_profile'), array('is_safe' => array('html'))),
            //species
            new \Twig_SimpleFunction('link_to_species', array($this, 'link_to_species'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_taxon', array($this, 'link_to_taxon'), array('is_safe' => array('html'))),
            //contests
            new \Twig_SimpleFunction('link_to_contests', array($this, 'link_to_contests'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_contest', array($this, 'link_to_contest'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_contest_photos', array($this, 'link_to_contest_photos'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_contest_photographers', array($this, 'link_to_contest_photographers'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_contest_sponsors', array($this, 'link_to_contest_sponsors'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_contest_winners', array($this, 'link_to_contest_winners'), array('is_safe' => array('html'))),
            //spots
            new \Twig_SimpleFunction('link_to_spot', array($this, 'link_to_spot'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_location', array($this, 'link_to_location'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_country', array($this, 'link_to_country'), array('is_safe' => array('html'))),
            //photo
            new \Twig_SimpleFunction('link_to_photo', array($this, 'link_to_photo'), array('is_safe' => array('html'))),
            //identification
            new \Twig_SimpleFunction('link_to_identification', array($this, 'link_to_identification'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_module', array($this, 'link_to_module'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_message', array($this, 'link_to_message'), array('is_safe' => array('html'))),
// URL helper functions.
            new \Twig_SimpleFunction('url_to_user', array($this, 'url_to_user')),
            new \Twig_SimpleFunction('url_to_user_profile', array($this, 'url_to_user_profile')),
            new \Twig_SimpleFunction('url_to_species', array($this, 'url_to_species')),
            new \Twig_SimpleFunction('url_to_taxon', array($this, 'url_to_taxon')),
            new \Twig_SimpleFunction('url_to_contests', array($this, 'url_to_contests')),
            new \Twig_SimpleFunction('url_to_contest', array($this, 'url_to_contest')),
            new \Twig_SimpleFunction('url_to_contest_photos', array($this, 'url_to_contest_photos')),
            new \Twig_SimpleFunction('url_to_contest_photographers', array($this, 'url_to_contest_photographers')),
            new \Twig_SimpleFunction('url_to_contest_sponsors', array($this, 'url_to_contest_sponsors')),
            new \Twig_SimpleFunction('url_to_contest_winners', array($this, 'url_to_contest_winners')),
            new \Twig_SimpleFunction('url_to_spot', array($this, 'url_to_spot')),
            new \Twig_SimpleFunction('url_to_business', array($this, 'url_to_business')),
            new \Twig_SimpleFunction('url_to_location', array($this, 'url_to_location')),
            new \Twig_SimpleFunction('url_to_country', array($this, 'url_to_country')),
            new \Twig_SimpleFunction('url_to_photo', array($this, 'url_to_photo')),
            new \Twig_SimpleFunction('url_to_photos', array($this, 'url_to_photos')),
            new \Twig_SimpleFunction('url_to_identification', array($this, 'url_to_identification')),
            new \Twig_SimpleFunction('url_to_module', array($this, 'url_to_module')),
            new \Twig_SimpleFunction('url_to_message', array($this, 'url_to_message')),
            new \Twig_SimpleFunction('url_to_dashboard', array($this, 'url_to_dashboard')),
            new \Twig_SimpleFunction('url_to_homepage', array($this, 'url_to_homepage')),
            // Other helpers
            new \Twig_SimpleFunction('sk_build_query', array($this, 'sk_build_query')),
            new \Twig_SimpleFunction('slugify', array($this, 'slugify')),
            new \Twig_SimpleFunction('unslugify', array($this, 'unslugify')),
            //message helpers
            new \Twig_SimpleFunction('activity_message', array($this, 'activity_message')),
            new \Twig_SimpleFunction('notification_message', array($this, 'notification_message')),
            'insertCoin' => new \Twig_Function_Method($this, 'insertCoin', ['needs_environment' => true]),
            'insertCoinPageLevel' => new \Twig_Function_Method($this, 'insertCoinPageLevel', ['needs_environment' => true]),
        );
    }

    public function insertCoin(Twig_Environment $twig) {

        //$country2LetterIso = strtoupper($country2LetterIso);
        $country2LetterIso = "PT";
        $domain = "http://skaphandrus.com";
        
        // get visitor ip
        $HTTP_CLIENT_IP = $this->request->server->get("HTTP_CLIENT_IP");
        $HTTP_X_FORWARDED_FOR = $this->request->server->get("HTTP_X_FORWARDED_FOR");
        $REMOTE_ADDR = $this->request->server->get("REMOTE_ADDR");
        
        if (filter_var($HTTP_CLIENT_IP, FILTER_VALIDATE_IP)) {
            $ip = $HTTP_CLIENT_IP;
        } elseif (filter_var($HTTP_X_FORWARDED_FOR, FILTER_VALIDATE_IP)) {
            $ip = $HTTP_X_FORWARDED_FOR;
        } else {
            $ip = $REMOTE_ADDR;
        }
        // curl the API
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-Type: text/xml'));
        curl_setopt($ch, CURLOPT_URL, 'http://api.wipmania.com/' . $ip . '?' . $domain);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $country = curl_exec($ch);
        if (!$country || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
            return false;
        } elseif (curl_errno($ch)) {
            return false;
        }
        curl_close($ch);

//        echo "IP = " . $ip;
//        echo "COUNTRY = " . $country;
        
        if ($country === $country2LetterIso):
            return false;
        else:
            return $twig->render('SkaphandrusAppBundle:Common:insertCoin.html.twig');
        endif;
    }

        public function insertCoinPageLevel(Twig_Environment $twig) {

        //$country2LetterIso = strtoupper($country2LetterIso);
        $country2LetterIso = "PT";
        $domain = "http://skaphandrus.com";
        
        // get visitor ip
        $HTTP_CLIENT_IP = $this->request->server->get("HTTP_CLIENT_IP");
        $HTTP_X_FORWARDED_FOR = $this->request->server->get("HTTP_X_FORWARDED_FOR");
        $REMOTE_ADDR = $this->request->server->get("REMOTE_ADDR");
        
        if (filter_var($HTTP_CLIENT_IP, FILTER_VALIDATE_IP)) {
            $ip = $HTTP_CLIENT_IP;
        } elseif (filter_var($HTTP_X_FORWARDED_FOR, FILTER_VALIDATE_IP)) {
            $ip = $HTTP_X_FORWARDED_FOR;
        } else {
            $ip = $REMOTE_ADDR;
        }
        // curl the API
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-Type: text/xml'));
        curl_setopt($ch, CURLOPT_URL, 'http://api.wipmania.com/' . $ip . '?' . $domain);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $country = curl_exec($ch);
        if (!$country || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
            return false;
        } elseif (curl_errno($ch)) {
            return false;
        }
        curl_close($ch);

//        echo "IP = " . $ip;
//        echo "COUNTRY = " . $country;
        
        if ($country === $country2LetterIso):
            //return false;
            return $twig->render('SkaphandrusAppBundle:Common:insertCoinPageLevel.html.twig');
        else:
            return $twig->render('SkaphandrusAppBundle:Common:insertCoinPageLevel.html.twig');
        endif;
    }

    


    /**
     * Intl helper functions.
     */
    public function intl_country_name($country_code) {
        return Intl::getRegionBundle()->getCountryName($country_code);
    }

    public function intl_locale_name($locale_code) {
        return Intl::getLocaleBundle()->getLocaleName($locale_code);
    }

    /*
     * Notification helper messages
     */<commit_msg>script<commit_after><?php

namespace Skaphandrus\AppBundle\Twig;

use Twig_Environment;
use Symfony\Component\Intl\Intl;
use Skaphandrus\AppBundle\Utils\Utils;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\Loader\ArrayLoader;

class UtilsExtension extends \Twig_Extension {

    protected $twig;
    protected $pathFunction;
    private $container;
    private $translator;
    private $request;

    public function __construct($container, Translator $translator, \Symfony\Component\HttpFoundation\RequestStack $requestStack)
    {
        $this->request = $requestStack->getCurrentRequest();
        $this->container = $container;
        $this->translator = $translator;
    }

    protected function getPathFunction() {
        if (empty($this->pathFunction)) {
            $this->pathFunction = $this->twig->getFunction('path')->getCallable();
        }

        return $this->pathFunction;
    }

    public function initRuntime(Twig_Environment $twig) {
        $this->twig = $twig;
    }

    public function getName() {
        return 'Skaphandrus App Utils';
    }

    public function getFunctions() {
        return array(
            // Intl helper functions.
            new \Twig_SimpleFunction('intl_country_name', array($this, 'intl_country_name')),
            new \Twig_SimpleFunction('intl_locale_name', array($this, 'intl_locale_name')),
// Link helper functions.
            // The "is_safe" parameter allows html, for rendering the links.
            new \Twig_SimpleFunction('link_to_user', array($this, 'link_to_user'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_user_profile', array($this, 'link_to_user_profile'), array('is_safe' => array('html'))),
            //species
            new \Twig_SimpleFunction('link_to_species', array($this, 'link_to_species'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_taxon', array($this, 'link_to_taxon'), array('is_safe' => array('html'))),
            //contests
            new \Twig_SimpleFunction('link_to_contests', array($this, 'link_to_contests'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_contest', array($this, 'link_to_contest'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_contest_photos', array($this, 'link_to_contest_photos'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_contest_photographers', array($this, 'link_to_contest_photographers'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_contest_sponsors', array($this, 'link_to_contest_sponsors'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_contest_winners', array($this, 'link_to_contest_winners'), array('is_safe' => array('html'))),
            //spots
            new \Twig_SimpleFunction('link_to_spot', array($this, 'link_to_spot'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_location', array($this, 'link_to_location'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_country', array($this, 'link_to_country'), array('is_safe' => array('html'))),
            //photo
            new \Twig_SimpleFunction('link_to_photo', array($this, 'link_to_photo'), array('is_safe' => array('html'))),
            //identification
            new \Twig_SimpleFunction('link_to_identification', array($this, 'link_to_identification'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_module', array($this, 'link_to_module'), array('is_safe' => array('html'))),
            new \Twig_SimpleFunction('link_to_message', array($this, 'link_to_message'), array('is_safe' => array('html'))),
// URL helper functions.
            new \Twig_SimpleFunction('url_to_user', array($this, 'url_to_user')),
            new \Twig_SimpleFunction('url_to_user_profile', array($this, 'url_to_user_profile')),
            new \Twig_SimpleFunction('url_to_species', array($this, 'url_to_species')),
            new \Twig_SimpleFunction('url_to_taxon', array($this, 'url_to_taxon')),
            new \Twig_SimpleFunction('url_to_contests', array($this, 'url_to_contests')),
            new \Twig_SimpleFunction('url_to_contest', array($this, 'url_to_contest')),
            new \Twig_SimpleFunction('url_to_contest_photos', array($this, 'url_to_contest_photos')),
            new \Twig_SimpleFunction('url_to_contest_photographers', array($this, 'url_to_contest_photographers')),
            new \Twig_SimpleFunction('url_to_contest_sponsors', array($this, 'url_to_contest_sponsors')),
            new \Twig_SimpleFunction('url_to_contest_winners', array($this, 'url_to_contest_winners')),
            new \Twig_SimpleFunction('url_to_spot', array($this, 'url_to_spot')),
            new \Twig_SimpleFunction('url_to_business', array($this, 'url_to_business')),
            new \Twig_SimpleFunction('url_to_location', array($this, 'url_to_location')),
            new \Twig_SimpleFunction('url_to_country', array($this, 'url_to_country')),
            new \Twig_SimpleFunction('url_to_photo', array($this, 'url_to_photo')),
            new \Twig_SimpleFunction('url_to_photos', array($this, 'url_to_photos')),
            new \Twig_SimpleFunction('url_to_identification', array($this, 'url_to_identification')),
            new \Twig_SimpleFunction('url_to_module', array($this, 'url_to_module')),
            new \Twig_SimpleFunction('url_to_message', array($this, 'url_to_message')),
            new \Twig_SimpleFunction('url_to_dashboard', array($this, 'url_to_dashboard')),
            new \Twig_SimpleFunction('url_to_homepage', array($this, 'url_to_homepage')),
            // Other helpers
            new \Twig_SimpleFunction('sk_build_query', array($this, 'sk_build_query')),
            new \Twig_SimpleFunction('slugify', array($this, 'slugify')),
            new \Twig_SimpleFunction('unslugify', array($this, 'unslugify')),
            //message helpers
            new \Twig_SimpleFunction('activity_message', array($this, 'activity_message')),
            new \Twig_SimpleFunction('notification_message', array($this, 'notification_message')),
            'insertCoin' => new \Twig_Function_Method($this, 'insertCoin', ['needs_environment' => true]),
            'insertCoinPageLevel' => new \Twig_Function_Method($this, 'insertCoinPageLevel', ['needs_environment' => true]),
        );
    }

    public function insertCoin(Twig_Environment $twig) {

        //$country2LetterIso = strtoupper($country2LetterIso);
        $country2LetterIso = "PT";
        $domain = "http://skaphandrus.com";
        
        // get visitor ip
        $HTTP_CLIENT_IP = $this->request->server->get("HTTP_CLIENT_IP");
        $HTTP_X_FORWARDED_FOR = $this->request->server->get("HTTP_X_FORWARDED_FOR");
        $REMOTE_ADDR = $this->request->server->get("REMOTE_ADDR");
        
        if (filter_var($HTTP_CLIENT_IP, FILTER_VALIDATE_IP)) {
            $ip = $HTTP_CLIENT_IP;
        } elseif (filter_var($HTTP_X_FORWARDED_FOR, FILTER_VALIDATE_IP)) {
            $ip = $HTTP_X_FORWARDED_FOR;
        } else {
            $ip = $REMOTE_ADDR;
        }
        // curl the API
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-Type: text/xml'));
        curl_setopt($ch, CURLOPT_URL, 'http://api.wipmania.com/' . $ip . '?' . $domain);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $country = curl_exec($ch);
        if (!$country || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
            return false;
        } elseif (curl_errno($ch)) {
            return false;
        }
        curl_close($ch);

     
        if ($country === $country2LetterIso):
            return false;
        else:
            return $twig->render('SkaphandrusAppBundle:Common:insertCoin.html.twig');
        endif;
    }

        public function insertCoinPageLevel(Twig_Environment $twig) {

        //$country2LetterIso = strtoupper($country2LetterIso);
        $country2LetterIso = "PT";
        $domain = "http://skaphandrus.com";
        
        // get visitor ip
        $HTTP_CLIENT_IP = $this->request->server->get("HTTP_CLIENT_IP");
        $HTTP_X_FORWARDED_FOR = $this->request->server->get("HTTP_X_FORWARDED_FOR");
        $REMOTE_ADDR = $this->request->server->get("REMOTE_ADDR");
        
        if (filter_var($HTTP_CLIENT_IP, FILTER_VALIDATE_IP)) {
            $ip = $HTTP_CLIENT_IP;
        } elseif (filter_var($HTTP_X_FORWARDED_FOR, FILTER_VALIDATE_IP)) {
            $ip = $HTTP_X_FORWARDED_FOR;
        } else {
            $ip = $REMOTE_ADDR;
        }
        // curl the API
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-Type: text/xml'));
        curl_setopt($ch, CURLOPT_URL, 'http://api.wipmania.com/' . $ip . '?' . $domain);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $country = curl_exec($ch);
        if (!$country || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
            return false;
        } elseif (curl_errno($ch)) {
            return false;
        }
        curl_close($ch);
        
        if ($country === $country2LetterIso):
            return false;
            //return $twig->render('SkaphandrusAppBundle:Common:insertCoinPageLevel.html.twig');
        else:
            return $twig->render('SkaphandrusAppBundle:Common:insertCoinPageLevel.html.twig');
        endif;
    }

    


    /**
     * Intl helper functions.
     */
    public function intl_country_name($country_code) {
        return Intl::getRegionBundle()->getCountryName($country_code);
    }

    public function intl_locale_name($locale_code) {
        return Intl::getLocaleBundle()->getLocaleName($locale_code);
    }

    /*
     * Notification helper messages
     */
{'fraction_non_alphanumeric': 0.1454848678079168, 'fraction_numerical': 0.001765831166920096, 'mean_word_length': 3.2289981331673925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 113, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '4548690', 'n_tokens_mistral': 6552, 'n_tokens_neox': 6390, 'n_words': 1004}