Example #1
0
/**
 * Convert amqp|conn|host into returning value of $arrayvar['amqp']['conn']['host']
 *
 * @param string $sqlname Variable name
 * @param array $arrayvar Array where to see param
 * @param Boolean $try_isset If True, return isset($sqlname) check, else return variable content
 * @return mixed
 */
function sql_to_array($sqlname, $arrayvar, $try_isset = TRUE)
{
    list($key, $pop_sqlname) = explode('|', $sqlname, 2);
    $isset = isset($arrayvar[$key]);
    if ($pop_sqlname === NULL) {
        // Reached the variable, return its content, or FALSE if it's not set
        if ($try_isset) {
            return $isset;
        } else {
            return $isset ? $arrayvar[$key] : NULL;
        }
    } else {
        if ($isset) {
            // Recurse to lower level
            return sql_to_array($pop_sqlname, $arrayvar[$key], $try_isset);
        }
    }
    return FALSE;
}
Example #2
0
/**
* examine()
*
* - Loads in the structure of a fresh SMF install via sql_to_array
* - Looks at each table in the current installation and determines if it is a default table
* and if so finds extra columns or indexes that should be removed.
*
* @return
*/
function examine()
{
    global $smcFunc, $db_prefix, $extra, $table_prefix, $version;
    // will allow for this == THIS and thisVar == this_var on col / index names to avoid false positives, set to true for more hits
    $strict_case = false;
    $tables = sql_to_array(dirname(__FILE__) . '/sql' . $version . '.sql');
    $mset = file_to_array(dirname(__FILE__) . '/modsettings' . $version . '.txt');
    $real_prefix = preg_match('~^(`?)(.+?)\\1\\.(.*?)$~', $db_prefix, $match) === 1 ? $match[3] : $db_prefix;
    $extra = array();
    // make sure this is gone for a clean run
    if (isset($_SESSION['db_cleaner'])) {
        unset($_SESSION['db_cleaner']);
    }
    // examine each table in this installation
    $current_tables = $smcFunc['db_list_tables']();
    foreach ($current_tables as $table) {
        $table = preg_replace('~^' . $real_prefix . '~', '', $table);
        // Table itself does not exist in a fresh install
        if (!isset($tables[$table])) {
            $extra['tables'][] = $table;
            continue;
        }
        // It exists in a fresh install, lets check if there are any extra columns in it
        $current_columns = $smcFunc['db_list_columns']($table_prefix . $table, false);
        foreach ($current_columns as $column) {
            if (!isset($tables[$table]['columns'][$column]) && $strict_case) {
                $extra['columns'][$table][] = $column;
            } elseif (!$strict_case && !isset($tables[$table]['columns'][strtolower($column)])) {
                $extra['columns'][$table][] = $column;
            }
        }
        // or extra indexes taking up space
        $current_indexes = $smcFunc['db_list_indexes']($table_prefix . $table, true);
        foreach ($current_indexes as $key => $index) {
            if (!isset($tables[$table]['indexes'][$key])) {
                // keys don't match ... v1 to v2 upgrade appears to reuse old smf1 index names (upper or camel) ..
                if ($version == 2 && $key != 'PRIMARY' && !$strict_case) {
                    // lets see if a lowercase or camelCase version of the key will work
                    $tempkey = isset($tables[$table]['indexes'][strtolower($key)]) ? strtolower($key) : (isset($tables[$table]['indexes'][unCamelCase($key)]) ? unCamelCase($key) : '');
                    if (!empty($tempkey)) {
                        // Probably found it, but are the index type and index cols exactly the same as well?
                        if ($current_indexes[$key]['type'] != $tables[$table]['indexes'][$tempkey]['type'] || count(array_diff($current_indexes[$key]['columns'], $tables[$table]['indexes'][$tempkey]['columns'])) != 0) {
                            unset($tempkey);
                        }
                    }
                    if (empty($tempkey)) {
                        $extra['indexes'][$table][] = $index;
                    }
                } else {
                    $extra['indexes'][$table][] = $index;
                }
            }
        }
    }
    // modSettings that are not from standard SMF
    $current_settings = array();
    $request = $smcFunc['db_query']('', '
		SELECT variable
		FROM {db_prefix}settings', array());
    while ($row = $version == 1 ? mysql_fetch_row($request) : $smcFunc['db_fetch_row']($request)) {
        $current_settings[$row[0]] = $row[0];
    }
    $version == 1 ? mysql_free_result($request) : $smcFunc['db_free_result']($request);
    // check what could be there vs what it ;)
    foreach ($current_settings as $mod) {
        if (!isset($mset[$mod])) {
            // check for a multi settings like bbc or integration tags
            $submod = explode('_', $mod);
            if (isset($mset[$submod[0] . '_']) && strpos($mod, $mset[$submod[0] . '_']) == 0) {
                continue;
            }
            $extra['settings'][] = $mod;
        }
    }
}
Example #3
0
 } else {
     if (is_array($variable['params'])) {
         $params = $variable['params'];
     } else {
         if (!empty($varparams)) {
             foreach (explode('|', $varparams) as $param) {
                 $params[$param] = array('name' => nicecase($param));
             }
         }
     }
 }
 if (sql_to_array($varname, $config) === FALSE) {
     // Variable is not configured, set $content to its default value so the form is pre-filled
     $content = sql_to_array($varname, $default_config, FALSE);
 } else {
     $content = sql_to_array($varname, $config, FALSE);
     // Get current value
 }
 //r($varname); r($content); r($sqlset); r($locked);
 $readonly = !($sqlset || $locked);
 echo '      <div id="' . $htmlname . '_content_div">' . PHP_EOL;
 switch ($vartype) {
     case 'bool':
     case 'boolean':
         echo '      <div>' . PHP_EOL;
         $item = array('id' => $htmlname, 'size' => 'small', 'on-text' => 'True', 'off-text' => 'False', 'readonly' => $readonly, 'disabled' => (bool) $locked, 'value' => $content);
         echo generate_form_element($item, 'switch');
         //echo('        <input data-toggle="switch-bool" type="checkbox" ' . ($content ? 'checked="1" ' : '') . 'id="' . $htmlname . '" name="' . $htmlname . '" ' . ($locked ? 'disabled="1" ' : '').'>' . PHP_EOL);
         echo '      </div>' . PHP_EOL;
         break;
     case 'enum-array':
Example #4
0
/**
* examine()
*
* - Loads in the structure of a fresh SMF install via sql_to_array
* - Looks at each table in the current installation and determines if it is a default table
* and if so finds extra columns or indexes that should be removed.
*
* @return
*/
function examine()
{
    global $db_prefix, $extra, $table_prefix;
    $db = database();
    $table_db = db_table();
    // Will allow for this == THIS and thisVar == this_var on col / index names to avoid false positives, set to true for more hits
    $strict_case = false;
    // Load in our standards files
    $tables = sql_to_array(dirname(__FILE__) . '/install_sql.sql');
    // Some tables are created not installed, others?
    $tables['log_search_words'] = array('indexes' => array('PRIMARY' => array('name' => 'PRIMARY', 'type' => 'primary', 'columns' => 'id_word, id_msg')), 'columns' => array('id_word' => array('name' => 'id_word'), 'id_msg' => array('name' => 'id_msg')));
    // All of the known modSettings
    $mset = file_to_array(dirname(__FILE__) . '/modsettings.txt');
    $real_prefix = preg_match('~^(`?)(.+?)\\1\\.(.*?)$~', $db_prefix, $match) === 1 ? $match[3] : $db_prefix;
    $extra = array();
    // Make sure this is gone for a clean run
    if (isset($_SESSION['db_cleaner'])) {
        unset($_SESSION['db_cleaner']);
    }
    // Examine each table in this installation
    $current_tables = $db->db_list_tables();
    foreach ($current_tables as $table) {
        $table = preg_replace('~^' . $real_prefix . '~', '', $table);
        // Table itself does not exist in a fresh install
        if (!isset($tables[$table])) {
            $extra['tables'][] = $table;
            continue;
        }
        // It exists in a fresh install, lets check if there are any extra columns in it
        $current_columns = $table_db->db_list_columns($table_prefix . $table, false);
        foreach ($current_columns as $column) {
            if (!isset($tables[$table]['columns'][$column]) && $strict_case) {
                $extra['columns'][$table][] = $column;
            } elseif (!$strict_case && !isset($tables[$table]['columns'][strtolower($column)])) {
                $extra['columns'][$table][] = $column;
            }
        }
        // Or extra indexes taking up space
        $current_indexes = $table_db->db_list_indexes($table_prefix . $table, true);
        foreach ($current_indexes as $key => $index) {
            if (!isset($tables[$table]['indexes'][$key])) {
                // keys don't match, upgrade issue?
                if ($key != 'PRIMARY' && !$strict_case) {
                    // lets see if a lowercase or camelCase version of the key will work
                    $tempkey = isset($tables[$table]['indexes'][strtolower($key)]) ? strtolower($key) : (isset($tables[$table]['indexes'][unCamelCase($key)]) ? unCamelCase($key) : '');
                    if (!empty($tempkey)) {
                        // Probably found it, but are the index type and index cols exactly the same as well?
                        if ($current_indexes[$key]['type'] != $tables[$table]['indexes'][$tempkey]['type'] || count(array_diff($current_indexes[$key]['columns'], $tables[$table]['indexes'][$tempkey]['columns'])) != 0) {
                            unset($tempkey);
                        }
                    }
                    if (empty($tempkey)) {
                        $extra['indexes'][$table][] = $index;
                    }
                } else {
                    $extra['indexes'][$table][] = $index;
                }
            }
        }
    }
    // modSettings that are not from standard Elkarte
    $current_settings = array();
    $request = $db->query('', '
		SELECT variable
		FROM {db_prefix}settings', array());
    while ($row = $db->fetch_row($request)) {
        $current_settings[$row[0]] = $row[0];
    }
    $db->free_result($request);
    // Check what could be there vs what it ;)
    foreach ($current_settings as $mod) {
        if (!isset($mset[$mod])) {
            // check for a multi settings like bbc or integration tags
            $submod = explode('_', $mod);
            if (isset($mset[$submod[0] . '_']) && strpos($mod, $mset[$submod[0] . '_']) == 0) {
                continue;
            }
            $extra['settings'][] = $mod;
        }
    }
}