<commit_before><?php

/**
 * ioly
 *
 * PHP version 5.3
 *
 * @category ioly_modulmanager
 * @package  OXID Connector
 * @author   <NAME> <<EMAIL>>
 * @author   <NAME> <<EMAIL>>
 * @author   <NAME> <<EMAIL>>
 * @license  MIT License http://opensource.org/licenses/MIT
 * @link     http://getioly.com/
 * @version     1.9.0
 */
class ioly_main extends oxAdminView
{
    /**
     * Current class template name.
     * @var string
     */
    protected $_sThisTemplate = 'ioly_main.tpl';
    /**
     * URL to ioly core (ioly.php)
     * @var string
     */
    protected $_iolyCoreUrl = "https://raw.githubusercontent.com/ioly/ioly/core/ioly.php";

    protected $_iolyCore = null;
    protected $_authFile = null;
    /**
     * The ioly core
     * @var ioly\ioly
     */
    protected $_ioly = null;
    protected $_iolyHelper = null;
    protected $_allModules = null;
    protected $_currSortKey = '';
    /**
     * Required JS libs and versions
     * @var array
     */
    protected $_requiredJsLibs = array(
        "ioly/oxid-connector-js-libs" => "1.0.0"
    );
    /**
     * Filter ioly modules for OXID
     * @var array
     */
    protected $_iolyFilter = array('type' => 'oxid');

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->_iolyCore = getShopBasePath() . '/modules/ioly/ioly/ioly.php';
        $this->_authFile = getShopBasePath() . '/modules/ioly/ioly/.auth';
        if ($this->_initIoly()) {
            $this->_checkForJsLibs();
        }
    }

    /**
     * Check if AngularJS, JQuery etc. are avaliable
     * If not, download them via ioly core :)
     */
    protected function _checkForJsLibs()
    {
        foreach ($this->_requiredJsLibs as $jsLib => $jsVersion) {
            if (!$this->_ioly->isInstalled($jsLib)) {
                try {
                    $this->_ioly->install($jsLib, $jsVersion);
                } catch (Exception $ex) {
                    $this->addTplParam("iolyerrorfatal", $ex->getMessage());
                }
            }
        }
    }

    /**
     * Gets ioly core if it doesn't exist.
     * @return boolean
     */
    protected function _initIoly()
    {
        if (!file_exists($this->_iolyCore)) {
            if (!$this->updateIoly()) {
                $this->addTplParam("iolyerrorfatal", oxRegistry::getLang()->translateString('IOLY_EXCEPTION_CORE_NOT_LOADED'));
            }
        }
        if (file_exists($this->_iolyCore)) {
            include_once $this->_iolyCore;
            $this->_ioly = new ioly\ioly();
            $this->_ioly->setSystemBasePath(oxRegistry::getConfig()->getConfigParam('sShopDir'));
            $this->_ioly->setSystemVersion($this->getShopMainVersion());
            return true;
        }
        return false;
    }

    /**
     * Set multiple cookbooks as defined in module settings.
     * @return null
     */
    protected function _setCookbooks()
    {
        if (($aCookbookUrls = oxRegistry::getConfig()->getConfigParam('iolycookbookurl')) && is_array($aCookbookUrls)) {
            // remove local zip files
            $this->_ioly->clearCookbooks();
            // and download new ones....
            $this->_ioly->setCookbooks($aCookbookUrls);
            return true;
        }
        return false;
    }

    /**
     * Allow module activation via ioly?
     * @return bool
     */
    public function allowActivation()
    {
        return oxRegistry::getConfig()->getShopConfVar('iolyenableinst');
    }

    /**
     * Get modules
     */
    public function getAllModules()
    {
        if ($this->_allModules === null) {
            $searchString = oxRegistry::getConfig()->getRequestParameter('searchstring');
            if ($searchString != '') {
                $allModules = $this->_ioly->search($searchString, $this->_iolyFilter);
                $this->addTplParam('searchstring', $searchString);
            } else {
                $allModules = $this->_ioly->listAll($this->_iolyFilter);
            }
            $this->_allModules = $allModules;
        }
    }

    /**
     * Returns all modules as JSON
     */
    public function getAllModulesAjax()
    {
        $page = oxRegistry::getConfig()->getRequestParameter('page');
        if (!$page && $page !== '0') {
            $page = 0;
        } else {
            $page = (int)$page;
        }
        $pageSize = (int)oxRegistry::getConfig()->getRequestParameter('pageSize');
        if (!$pageSize) {
            $pageSize = 20;
        } else {
            $pageSize = (int)$pageSize;
        }
        $offset = $page * $pageSize;
        $this->_currSortKey = oxRegistry::getConfig()->getRequestParameter('orderBy');
        $orderDir = oxRegistry::getConfig()->getRequestParameter('orderDir');
        // fill internal variable
        $this->getAllModules();
        $numItems = 0;
        $data = array();
        if ($this->_allModules && is_array($this->_allModules)) {

            // filter module list
            $onlyInstalled = oxRegistry::getConfig()->getRequestParameter('onlyInstalled') == "false" ? false : true;
            $onlyActive = oxRegistry::getConfig()->getRequestParameter('onlyActive') == "false" ? false : true;
            $this->_filterModules($onlyInstalled, $onlyActive);

            $numItems = count($this->_allModules);
            // sort by requested field
            if ($this->_currSortKey != '') {
                uasort($this->_allModules, array($this, 'cmpModules'));
            }
            // reverse order?
            if ($orderDir == "desc") {
                $this->_allModules = array_reverse($this->_allModules);
            }
            $data = array_slice($this->_allModules, $offset, $pageSize, false);
            // check if module is active?
            if (oxRegistry::getConfig()->getShopConfVar('iolycheckactive')) {
                foreach ($data as $idx => $aPackage) {
                    $aVersions = $aPackage['versions'];<commit_msg>small fix: default filters to false<commit_after><?php

/**
 * ioly
 *
 * PHP version 5.3
 *
 * @category ioly_modulmanager
 * @package  OXID Connector
 * @author   <NAME> <<EMAIL>>
 * @author   <NAME> <<EMAIL>>
 * @author   <NAME> <<EMAIL>>
 * @license  MIT License http://opensource.org/licenses/MIT
 * @link     http://getioly.com/
 * @version     1.9.0
 */
class ioly_main extends oxAdminView
{
    /**
     * Current class template name.
     * @var string
     */
    protected $_sThisTemplate = 'ioly_main.tpl';
    /**
     * URL to ioly core (ioly.php)
     * @var string
     */
    protected $_iolyCoreUrl = "https://raw.githubusercontent.com/ioly/ioly/core/ioly.php";

    protected $_iolyCore = null;
    protected $_authFile = null;
    /**
     * The ioly core
     * @var ioly\ioly
     */
    protected $_ioly = null;
    protected $_iolyHelper = null;
    protected $_allModules = null;
    protected $_currSortKey = '';
    /**
     * Required JS libs and versions
     * @var array
     */
    protected $_requiredJsLibs = array(
        "ioly/oxid-connector-js-libs" => "1.0.0"
    );
    /**
     * Filter ioly modules for OXID
     * @var array
     */
    protected $_iolyFilter = array('type' => 'oxid');

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->_iolyCore = getShopBasePath() . '/modules/ioly/ioly/ioly.php';
        $this->_authFile = getShopBasePath() . '/modules/ioly/ioly/.auth';
        if ($this->_initIoly()) {
            $this->_checkForJsLibs();
        }
    }

    /**
     * Check if AngularJS, JQuery etc. are avaliable
     * If not, download them via ioly core :)
     */
    protected function _checkForJsLibs()
    {
        foreach ($this->_requiredJsLibs as $jsLib => $jsVersion) {
            if (!$this->_ioly->isInstalled($jsLib)) {
                try {
                    $this->_ioly->install($jsLib, $jsVersion);
                } catch (Exception $ex) {
                    $this->addTplParam("iolyerrorfatal", $ex->getMessage());
                }
            }
        }
    }

    /**
     * Gets ioly core if it doesn't exist.
     * @return boolean
     */
    protected function _initIoly()
    {
        if (!file_exists($this->_iolyCore)) {
            if (!$this->updateIoly()) {
                $this->addTplParam("iolyerrorfatal", oxRegistry::getLang()->translateString('IOLY_EXCEPTION_CORE_NOT_LOADED'));
            }
        }
        if (file_exists($this->_iolyCore)) {
            include_once $this->_iolyCore;
            $this->_ioly = new ioly\ioly();
            $this->_ioly->setSystemBasePath(oxRegistry::getConfig()->getConfigParam('sShopDir'));
            $this->_ioly->setSystemVersion($this->getShopMainVersion());
            return true;
        }
        return false;
    }

    /**
     * Set multiple cookbooks as defined in module settings.
     * @return null
     */
    protected function _setCookbooks()
    {
        if (($aCookbookUrls = oxRegistry::getConfig()->getConfigParam('iolycookbookurl')) && is_array($aCookbookUrls)) {
            // remove local zip files
            $this->_ioly->clearCookbooks();
            // and download new ones....
            $this->_ioly->setCookbooks($aCookbookUrls);
            return true;
        }
        return false;
    }

    /**
     * Allow module activation via ioly?
     * @return bool
     */
    public function allowActivation()
    {
        return oxRegistry::getConfig()->getShopConfVar('iolyenableinst');
    }

    /**
     * Get modules
     */
    public function getAllModules()
    {
        if ($this->_allModules === null) {
            $searchString = oxRegistry::getConfig()->getRequestParameter('searchstring');
            if ($searchString != '') {
                $allModules = $this->_ioly->search($searchString, $this->_iolyFilter);
                $this->addTplParam('searchstring', $searchString);
            } else {
                $allModules = $this->_ioly->listAll($this->_iolyFilter);
            }
            $this->_allModules = $allModules;
        }
    }

    /**
     * Returns all modules as JSON
     */
    public function getAllModulesAjax()
    {
        $page = oxRegistry::getConfig()->getRequestParameter('page');
        if (!$page && $page !== '0') {
            $page = 0;
        } else {
            $page = (int)$page;
        }
        $pageSize = (int)oxRegistry::getConfig()->getRequestParameter('pageSize');
        if (!$pageSize) {
            $pageSize = 20;
        } else {
            $pageSize = (int)$pageSize;
        }
        $offset = $page * $pageSize;
        $this->_currSortKey = oxRegistry::getConfig()->getRequestParameter('orderBy');
        $orderDir = oxRegistry::getConfig()->getRequestParameter('orderDir');
        // fill internal variable
        $this->getAllModules();
        $numItems = 0;
        $data = array();
        if ($this->_allModules && is_array($this->_allModules)) {

            // filter module list
            $onlyInstalled = (oxRegistry::getConfig()->getRequestParameter('onlyInstalled') == "true" || oxRegistry::getConfig()->getRequestParameter('onlyInstalled') == "1" ) ? true : false;
            $onlyActive = (oxRegistry::getConfig()->getRequestParameter('onlyActive') == "true" || oxRegistry::getConfig()->getRequestParameter('onlyActive') == "1") ? true : false;
            $this->_filterModules($onlyInstalled, $onlyActive);

            $numItems = count($this->_allModules);
            // sort by requested field
            if ($this->_currSortKey != '') {
                uasort($this->_allModules, array($this, 'cmpModules'));
            }
            // reverse order?
            if ($orderDir == "desc") {
                $this->_allModules = array_reverse($this->_allModules);
            }
            $data = array_slice($this->_allModules, $offset, $pageSize, false);
            // check if module is active?
            if (oxRegistry::getConfig()->getShopConfVar('iolycheckactive')) {
                foreach ($data as $idx => $aPackage) {
                    $aVersions = $aPackage['versions'];
{'fraction_non_alphanumeric': 0.14830438378825475, 'fraction_numerical': 0.002315963606286187, 'mean_word_length': 2.029566524680531, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 147, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4548557', 'n_tokens_mistral': 3543, 'n_tokens_neox': 3502, 'n_words': 676}