<commit_before><?php
/**
 * @version     $Id$
 * @category    Nooku
 * @package     Nooku_Components
 * @subpackage  Koowa
 * @copyright   Copyright (C) 2010 Timble CVBA and Contributors. (http://www.timble.net)
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// In order to allow multiple components being installed in go, this check is crucial
if(!function_exists('com_install'))
{
    /**
     * This function is required by JInstallerComponent in order to run this script
     * 
     * @return  void
     */
    function com_install()
    {
        return JFactory::getApplication()->get('com_install') !== false;
    }
}

$errors = array();
if(extension_loaded('suhosin'))
{
    //Attempt setting the whitelist value
    @ini_set('suhosin.executor.include.whitelist', 'tmpl://, file://');

    //Checking if the whitelist is ok
    if(!@ini_get('suhosin.executor.include.whitelist') || strpos(@ini_get('suhosin.executor.include.whitelist'), 'tmpl://') === false)
    {
        $this->parent->abort(sprintf(JText::_('The install failed because your server has Suhosin loaded, but it\'s not configured correctly. Please follow <a href="%s" target="_blank">this</a> tutorial before you reinstall.'), 'https://nooku.assembla.com/wiki/show/nooku-framework/Known_Issues'));
        return false;
    }
}

if (!class_exists('mysqli'))
{
    $this->parent->abort(JText::_("We're sorry but your server isn't configured with the MySQLi database driver. Please contact your host and ask them to enable MySQLi for your server."));
    JFactory::getApplication()->set('com_install', false);
    return;
}

// Check if mysqli is active, if not, then enable it
if(JFactory::getApplication()->getCfg('dbtype') != 'mysqli')
{
    $path = JPATH_CONFIGURATION.DS.'configuration.php';
    if(JFile::exists($path))
    {
        JPath::setPermissions($path, '0777');
        $search     = JFile::read($path);
        $replaced   = str_replace('var $dbtype = \'mysql\';', 'var $dbtype = \'mysqli\';', $search);
        JFile::write($path, $replaced);
        JPath::setPermissions($path, '0644');
    }
    JError::raiseNotice(0, JText::_("Database configuration setting changed to 'mysqli'."));
}

// Define variables
$database   = JFactory::getDBO();
$type       = 'com';
$manifest   = simplexml_load_file($this->parent->getPath('manifest'));
$package    = (string) $manifest->name;
$source     = $this->parent->getPath('source'); // The install package dir
$version    = (string) $manifest->version;
$logo       = JURI::root(1).'/media/com_koowa/images/logo.png';
$jversion   = JVersion::isCompatible('1.6.0') ? '1.6' : '1.5';

//Run platform specific procedures
require JPATH_ROOT.'/administrator/components/com_'.$package.'/install/install.'.$jversion.'.php';

//Fail the app if errors happened
if($errors) {
    //require '';
}

// Copy over the folders for the fw, com_default, mod_default
foreach ($manifest->framework->folder as $folder)
{
    $from   = isset($folder['src']) ? $folder['src'] : $folder;
    JFolder::copy($source.$from, JPATH_ROOT.$folder, false, true);
}

foreach ($manifest->framework->file as $file)
{
    $folder = JPATH_ROOT.dirname($file);
    if(!JFolder::exists($folder)) JFolder::create($folder);
    
    JFile::copy($source.$file, JPATH_ROOT.$file);
}

$versiontext = '<em>'.JText::_('You need at least %s to run Nooku Framework. You have: %s').'</em>';

// Preload the logo<commit_msg>re #27 refactoring install script UI, fixing rollback behavior, refactoring how fatal errors (like Suhosin detection) are handled<commit_after><?php
/**
 * @version     $Id$
 * @category    Nooku
 * @package     Nooku_Components
 * @subpackage  Koowa
 * @copyright   Copyright (C) 2010 Timble CVBA and Contributors. (http://www.timble.net)
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// In order to allow multiple components being installed in go, this check is crucial
if(!function_exists('com_install'))
{
    /**
     * This function is required by JInstallerComponent in order to run this script
     * 
     * @return  void
     */
    function com_install()
    {
        return JFactory::getApplication()->get('com_install') !== false;
    }
}

$errors = array();
if(extension_loaded('suhosin'))
{
    //Attempt setting the whitelist value
    @ini_set('suhosin.executor.include.whitelist', 'tmpl://, file://');

    //Checking if the whitelist is ok
    if(!@ini_get('suhosin.executor.include.whitelist') || strpos(@ini_get('suhosin.executor.include.whitelist'), 'tmpl://') === false)
    {
        $this->parent->abort(sprintf(JText::_('The install failed because your server has Suhosin loaded, but it\'s not configured correctly. Please follow <a href="%s" target="_blank">this</a> tutorial before you reinstall.'), 'https://nooku.assembla.com/wiki/show/nooku-framework/Known_Issues'));
        return false;
    }
}

if (!class_exists('mysqli'))
{
    $this->parent->abort(JText::_("We're sorry but your server isn't configured with the MySQLi database driver. Please contact your host and ask them to enable MySQLi for your server."));
    JFactory::getApplication()->set('com_install', false);
    return;
}

// Define variables
$database   = JFactory::getDBO();
$type       = 'com';
$manifest   = simplexml_load_file($this->parent->getPath('manifest'));
$package    = (string) $manifest->name;
$source     = $this->parent->getPath('source'); // The install package dir
$version    = (string) $manifest->version;
$logo       = JURI::root(1).'/media/com_koowa/images/logo.png';
$jversion   = JVersion::isCompatible('1.6.0') ? '1.6' : '1.5';

//Run platform specific procedures
require JPATH_ROOT.'/administrator/components/com_'.$package.'/install/install.'.$jversion.'.php';

//Fail the app if errors happened
if($errors) {
    //require '';
}

// Check if mysqli is active, if not, then enable it
if(JFactory::getApplication()->getCfg('dbtype') != 'mysqli')
{
    $path = JPATH_CONFIGURATION.DS.'configuration.php';
    if(JFile::exists($path))
    {
        JPath::setPermissions($path, '0777');
        $search     = JFile::read($path);
        $replaced   = str_replace('var $dbtype = \'mysql\';', 'var $dbtype = \'mysqli\';', $search);
        JFile::write($path, $replaced);
        JPath::setPermissions($path, '0644');
    }
    JError::raiseNotice(0, JText::_("Database configuration setting changed to 'mysqli'."));
}

// Copy over the folders for the fw, com_default, mod_default
foreach ($manifest->framework->folder as $folder)
{
    $from   = isset($folder['src']) ? $folder['src'] : $folder;
    JFolder::copy($source.$from, JPATH_ROOT.$folder, false, true);
}

foreach ($manifest->framework->file as $file)
{
    $folder = JPATH_ROOT.dirname($file);
    if(!JFolder::exists($folder)) JFolder::create($folder);
    
    JFile::copy($source.$file, JPATH_ROOT.$file);
}

$versiontext = '<em>'.JText::_('You need at least %s to run Nooku Framework. You have: %s').'</em>';

// Preload the logo
{'fraction_non_alphanumeric': 0.17107461024498885, 'fraction_numerical': 0.006403118040089087, 'mean_word_length': 3.848178137651822, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 47, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, 'xml': 2}, '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': '6269860', 'n_tokens_mistral': 2351, 'n_tokens_neox': 2301, 'n_words': 550}