<commit_before><?php
/**
 *                    Jojo CMS
 *                ================
 *
 * Copyright 2007-2008 <NAME> <<EMAIL>>
 * Copyright 2007-2008 <NAME> <<EMAIL>>
 * Copyright 2007 <NAME> <<EMAIL>>
 *
 * See the enclosed file license.txt for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  <NAME> <<EMAIL>>
 * @author  <NAME> <<EMAIL>>
 * @author  <NAME> <<EMAIL>>
 * @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
 * @link    http://www.jojocms.org JojoCMS
 * @package jojo_core
 */

/* Should we be here? */
if (file_exists('config/config.php') || file_exists('config.php')) {
    /* No, redirect to setup */
    header('Location: setup/');
    exit;
}

error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 1);

/* Output html header */
jojo_install_header();

$errors = array();

$action = 'step2';

switch($action) {

    /* Step 2 - Site Settings */
    case 'step2':
        /* Check Step 2 Fields */
        $missing = false;
        $found  = false;
        $fields = array(
                'masterpass'     => '',
                'confirmpass'    => '',
                'sitetitle'      => '',
                'webmastername'  => '',
                'webmasteremail' => '',
                'admin'          => 'admin',
                    );

        foreach($fields as $f => $default) {
            if (!empty($_POST[$f])) {
                $$f = $_POST[$f];
                $_SESSION[$f] = $_POST[$f];
                $found = true;
            } elseif (!empty($_SESSION[$f])) {
                $$f = $_SESSION[$f];
                $found = true;
            } else {
                $$f = $default;
                $missing = true;
            }
        }

        /* User submitted some values so lets check them */
        if ($found) {
            if (empty($webmastername)) {
                $errors[] = 'Webmastername is empty';
            }
            if (empty($sitetitle)) {
                $errors[] = 'Site title is empty';
            }
            if (empty($webmasteremail)) {
                $errors[] = 'Webmasteradress is empty';
            } elseif(!preg_match('/^\w[-.\w]*@(\w[-._\w]*\.[a-zA-Z]{2,}.*)$/', $webmasteremail)) {
                $errors[] = 'Webmasteradress '.$webmasteremail.' is not valid';
            }
            if (empty($confirmpass)) {
                $errors[] = 'Password Confirmation is empty';
            }
            if (empty($masterpass)) {
                $errors[] = 'Master password is empty';
            }
            if ($masterpass != $confirmpass)  {
                $errors[] = 'The Confirmation Password isn\'t the same as the Masterpassword.';
            }

            if (!preg_match('/^[a-z0-9]*$/', $admin)) {
                $errors[] = 'The Admin URI needs to be lowercase alphanumeric with no spaces, special characters.';
            }

            if (count($errors)) {
                $errortext = implode('<br />',$errors);
                echo '<div class="errors"><h2>Errors</h2>' . $errortext . '</div>';
                $missing = true;
            }
        }

        /* Missing fields, show form */
        if ($missing) {
            echo '<h1>Site information</h1>'."\n";
            echo '<form class="form inline" method="post" action="install">'."\n";
            echo '<p>The following settings are required to run Jojo. These can be changed later from the "edit options" page.</p>';
            echo '<div class="well">
            <div class="form-group">
                <label for="sitetitle">Site Title: </label>
                <input class="form-control" type="text" size="30" id="sitetitle" name="sitetitle" value="'.$sitetitle.'" />
                 <div class="help-block">This should generally be the name of the business, or the name of the website. The site title will be appended to the end of the title of every page, and is used as the FROM in all emails sent by the website. </div>
            </div>
            <div class="form-group">
                <label for="webmastername">Webmaster Name: </label>
                <input class="form-control" type="text" size="30" id="webmastername" name="webmastername" value="'.$webmastername.'" />
                 <div class="help-block">The name of the person or company who will be managing this site.</div>
            </div>
            <div class="form-group">
                <label for="webmasteremail">Webmaster Email: </label>
                <input class="form-control" type="text" size="30" id="webmasteremail" name="webmasteremail" value="'.$webmasteremail.'" />
                 <div class="help-block">Used on 404 pages, and as the contact address for system reports</div>
           </div>
            <div class="form-group">
            <label for="masterpass">Master Password: </label>
            <input class="form-control" type="password" size="30" id="masterpass" name="masterpass" value="'.$masterpass.'" />
                <div class="help-block">This password is used to protect the Jojo setup process, and will also become the initial admin user password.</div>
            </div>
            <div class="form-group">
                <label for="confirmpass">Confirm Password: </label>
                <input class="form-control" type="password" size="30" id="confirmpass" name="confirmpass" value="'.$confirmpass.'" />
            </div>
            
            <div class="form-group">
                <label for="admin">Admin URI: </label>
                <input class="form-control" type="text" size="30" id="admin" name="admin" value="'.$admin.'" />
                <div class="help-block">The base address of the Jojo admin section. The default admin page will be www.example.com/admin/ - usually the default is fine, but you will need to change this if the /admin/ URI is already in use by the web hosting control panel.</div>
            </div>'."\n";
            echo '</div>';
            echo '<p class="action">Please complete the above fields then move on to the next step. <button class="btn btn-default" type="submit" name="submit" value="Next" />Next</button></p>';
            echo '</form>';
            echo ''."\n";
            break;
        }

    /* Step 3 - Create a config file */
    case 'step3':
        /* Check Step 2 Fields */
        $missing = false;
        $found = false;
        $protocol = ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) || getenv('SSL_PROTOCOL_VERSION')) ? 'https://' : 'http://';
        $fields = array(
                    'dbhost' => 'localhost',
                    'dbuser' => '',
                    'dbpass' => '',
                    'dbname' => '',
                    'webdir' => dirname($_SERVER['SCRIPT_FILENAME']),
                    'sitedir' => '',
                    'altplugindir' => '',
                    'siteurl' => preg_replace('%(.*?)/install/?%', '$1', $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']),
                        );
        $optional = array('altplugindir');

        foreach($fields as $f => $default) {
            if ($_POST[$f] || in_array($f, $optional)) {
                $$f = $_POST[$f];
                $_SESSION[$f] = $_POST[$f];
                $found = true;
            } elseif ($_SESSION[$f]) {
                $$f = $_SESSION[$f];
                $found = true;
            } elseif ($f == 'dbpass') {
                $$f = '';
            } else {
                $$f = $default;
                $missing = true;
            }
        }
        /* User submitted some values so lets check them */
        if ($found) {
            $link = @mysql_connect($dbhost, $dbuser, $dbpass);
            if (!$link) {
                $errors[] = 'Could not connect to database: '. mysql_error();
            } else {
                $db_selected = @mysql_select_db($dbname, $link);
                if (!$db_selected) {
                    $errors[] = 'Could not select database ' . $dbname . ': ' . mysql_error();
                } else {
                    @mysql_query('ALTER DATABASE `' . $dbname . '` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci', $link);
                }
            }
            @mysql_close($link);

            if (!file_exists($basedir)) {
                $errors[] = 'Base Directory ' . $basedir . ' not found';
            }
            if (!file_exists($webdir)) {
                $errors[] = 'Web Dir ' . $webdir . ' not found';
            }
            if (!file_exists($sitedir)) {
                $errors[] = 'My Site Directory ' . $sitedir . ' not found';
            }
            if (count($errors)) {
                $errortext = implode('<br />',$errors);
                echo '<div class="errors"><h2>Errors</h2>' . $errortext . '</div>';
                $missing = true;
            }
        }

        $webdir  = str_replace('\\', '/', $webdir);
        $basedir = str_replace('\\', '/', $basedir);
        $sitedir = str_replace('\\', '/', $sitedir);
        $altplugindir = $_SESSION['altplugindir'] ? str_replace('\\', '/', $_SESSION['altplugindir']) : '';
        $data = explode('/', $webdir);
        $suggested_mysite = '';
        for ($i=0; $i<(count($data)-1); $i++) {
            $suggested_mysite .= $data[$i].'/';
        }
        $suggested_mysite .= 'mysite';<commit_msg>Core: Update install to use the mysqli connector (mysql is dropped in php7)<commit_after><?php
/**
 *                    Jojo CMS
 *                ================
 *
 * Copyright 2007-2008 <NAME> <<EMAIL>>
 * Copyright 2007-2008 <NAME> <<EMAIL>>
 * Copyright 2007 <NAME> <<EMAIL>>
 *
 * See the enclosed file license.txt for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  <NAME> <<EMAIL>>
 * @author  <NAME> <<EMAIL>>
 * @author  <NAME> <<EMAIL>>
 * @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
 * @link    http://www.jojocms.org JojoCMS
 * @package jojo_core
 */

/* Should we be here? */
if (file_exists('config/config.php') || file_exists('config.php')) {
    /* No, redirect to setup */
    header('Location: setup/');
    exit;
}

error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 1);

/* Output html header */
jojo_install_header();

$errors = array();

$action = 'step2';

switch($action) {

    /* Step 2 - Site Settings */
    case 'step2':
        /* Check Step 2 Fields */
        $missing = false;
        $found  = false;
        $fields = array(
                'masterpass'     => '',
                'confirmpass'    => '',
                'sitetitle'      => '',
                'webmastername'  => '',
                'webmasteremail' => '',
                'admin'          => 'admin',
                    );

        foreach($fields as $f => $default) {
            if (!empty($_POST[$f])) {
                $$f = $_POST[$f];
                $_SESSION[$f] = $_POST[$f];
                $found = true;
            } elseif (!empty($_SESSION[$f])) {
                $$f = $_SESSION[$f];
                $found = true;
            } else {
                $$f = $default;
                $missing = true;
            }
        }

        /* User submitted some values so lets check them */
        if ($found) {
            if (empty($webmastername)) {
                $errors[] = 'Webmastername is empty';
            }
            if (empty($sitetitle)) {
                $errors[] = 'Site title is empty';
            }
            if (empty($webmasteremail)) {
                $errors[] = 'Webmasteradress is empty';
            } elseif(!preg_match('/^\w[-.\w]*@(\w[-._\w]*\.[a-zA-Z]{2,}.*)$/', $webmasteremail)) {
                $errors[] = 'Webmasteradress '.$webmasteremail.' is not valid';
            }
            if (empty($confirmpass)) {
                $errors[] = 'Password Confirmation is empty';
            }
            if (empty($masterpass)) {
                $errors[] = 'Master password is empty';
            }
            if ($masterpass != $confirmpass)  {
                $errors[] = 'The Confirmation Password isn\'t the same as the Masterpassword.';
            }

            if (!preg_match('/^[a-z0-9]*$/', $admin)) {
                $errors[] = 'The Admin URI needs to be lowercase alphanumeric with no spaces, special characters.';
            }

            if (count($errors)) {
                $errortext = implode('<br />',$errors);
                echo '<div class="errors"><h2>Errors</h2>' . $errortext . '</div>';
                $missing = true;
            }
        }

        /* Missing fields, show form */
        if ($missing) {
            echo '<h1>Site information</h1>'."\n";
            echo '<form class="form inline" method="post" action="install">'."\n";
            echo '<p>The following settings are required to run Jojo. These can be changed later from the "edit options" page.</p>';
            echo '<div class="well">
            <div class="form-group">
                <label for="sitetitle">Site Title: </label>
                <input class="form-control" type="text" size="30" id="sitetitle" name="sitetitle" value="'.$sitetitle.'" />
                 <div class="help-block">This should generally be the name of the business, or the name of the website. The site title will be appended to the end of the title of every page, and is used as the FROM in all emails sent by the website. </div>
            </div>
            <div class="form-group">
                <label for="webmastername">Webmaster Name: </label>
                <input class="form-control" type="text" size="30" id="webmastername" name="webmastername" value="'.$webmastername.'" />
                 <div class="help-block">The name of the person or company who will be managing this site.</div>
            </div>
            <div class="form-group">
                <label for="webmasteremail">Webmaster Email: </label>
                <input class="form-control" type="text" size="30" id="webmasteremail" name="webmasteremail" value="'.$webmasteremail.'" />
                 <div class="help-block">Used on 404 pages, and as the contact address for system reports</div>
           </div>
            <div class="form-group">
            <label for="masterpass">Master Password: </label>
            <input class="form-control" type="password" size="30" id="masterpass" name="masterpass" value="'.$masterpass.'" />
                <div class="help-block">This password is used to protect the Jojo setup process, and will also become the initial admin user password.</div>
            </div>
            <div class="form-group">
                <label for="confirmpass">Confirm Password: </label>
                <input class="form-control" type="password" size="30" id="confirmpass" name="confirmpass" value="'.$confirmpass.'" />
            </div>
            
            <div class="form-group">
                <label for="admin">Admin URI: </label>
                <input class="form-control" type="text" size="30" id="admin" name="admin" value="'.$admin.'" />
                <div class="help-block">The base address of the Jojo admin section. The default admin page will be www.example.com/admin/ - usually the default is fine, but you will need to change this if the /admin/ URI is already in use by the web hosting control panel.</div>
            </div>'."\n";
            echo '</div>';
            echo '<p class="action">Please complete the above fields then move on to the next step. <button class="btn btn-default" type="submit" name="submit" value="Next" />Next</button></p>';
            echo '</form>';
            echo ''."\n";
            break;
        }

    /* Step 3 - Create a config file */
    case 'step3':
        /* Check Step 2 Fields */
        $missing = false;
        $found = false;
        $protocol = ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) || getenv('SSL_PROTOCOL_VERSION')) ? 'https://' : 'http://';
        $fields = array(
                    'dbhost' => 'localhost',
                    'dbuser' => '',
                    'dbpass' => '',
                    'dbname' => '',
                    'webdir' => dirname($_SERVER['SCRIPT_FILENAME']),
                    'sitedir' => '',
                    'altplugindir' => '',
                    'siteurl' => preg_replace('%(.*?)/install/?%', '$1', $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']),
                        );
        $optional = array('altplugindir');

        foreach($fields as $f => $default) {
            if ($_POST[$f] || in_array($f, $optional)) {
                $$f = $_POST[$f];
                $_SESSION[$f] = $_POST[$f];
                $found = true;
            } elseif ($_SESSION[$f]) {
                $$f = $_SESSION[$f];
                $found = true;
            } elseif ($f == 'dbpass') {
                $$f = '';
            } else {
                $$f = $default;
                $missing = true;
            }
        }
        /* User submitted some values so lets check them */
        if ($found) {
            $link = @mysqli_connect($dbhost, $dbuser, $dbpass);
            if (!$link) {
                $errors[] = 'Could not connect to database: '. mysqli_error();
            } else {
                $db_selected = @mysqli_select_db($link, $dbname);
                if (!$db_selected) {
                    $errors[] = 'Could not select database ' . $dbname . ': ' . mysqli_error();
                } else {
                    @mysqli_query('ALTER DATABASE `' . $dbname . '` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci', $link);
                }
            }
            @mysqli_close($link);

            if (!file_exists($basedir)) {
                $errors[] = 'Base Directory ' . $basedir . ' not found';
            }
            if (!file_exists($webdir)) {
                $errors[] = 'Web Dir ' . $webdir . ' not found';
            }
            if (!file_exists($sitedir)) {
                $errors[] = 'My Site Directory ' . $sitedir . ' not found';
            }
            if (count($errors)) {
                $errortext = implode('<br />',$errors);
                echo '<div class="errors"><h2>Errors</h2>' . $errortext . '</div>';
                $missing = true;
            }
        }

        $webdir  = str_replace('\\', '/', $webdir);
        $basedir = str_replace('\\', '/', $basedir);
        $sitedir = str_replace('\\', '/', $sitedir);
        $altplugindir = $_SESSION['altplugindir'] ? str_replace('\\', '/', $_SESSION['altplugindir']) : '';
        $data = explode('/', $webdir);
        $suggested_mysite = '';
        for ($i=0; $i<(count($data)-1); $i++) {
            $suggested_mysite .= $data[$i].'/';
        }
        $suggested_mysite .= 'mysite';
{'fraction_non_alphanumeric': 0.16627746523723597, 'fraction_numerical': 0.006103386052436047, 'mean_word_length': 1.7217969088545428, 'pattern_counts': {'":': 0, '<': 167, '<?xml version=': 0, '>': 195, 'https://': 2, 'lorem ipsum': 0, 'www.': 8, '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': '5354788', 'n_tokens_mistral': 5495, 'n_tokens_neox': 5280, 'n_words': 1379}