Initial Commit

This commit is contained in:
2019-11-21 12:25:31 +01:00
commit f4aabcb9b1
13959 changed files with 787761 additions and 0 deletions

View File

@@ -0,0 +1,151 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Nwdthemes Standalone Slider Revolution
*
* @package StandaloneRevslider
* @author Nwdthemes <mail@nwdthemes.com>
* @link http://nwdthemes.com/
* @copyright Copyright (c) 2015. Nwdthemes
* @license http://themeforest.net/licenses/terms/regular
*/
if( ! function_exists('WP_Filesystem'))
{
/**
* Init filesystem class
*/
function WP_Filesystem() {
global $wp_filesystem;
$ci = &get_instance();
$ci->load->library('filesystem');
$wp_filesystem = $ci->filesystem;
return true;
}
}
if( ! function_exists('unzip_file'))
{
/**
* Unzip file
*
* @param string $file
* @param string $path
* @return boolean
*/
function unzip_file($file, $path) {
// make sure it have trailing slash
$path = rtrim(str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $path), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
if ( ! wp_mkdir_p($path)) return false;
if (class_exists('ZipArchive') && RevSliderOperations::getGeneralSettingsOptionValue('force_pclzip', 'off') == 'off') {
$zip = new ZipArchive;
$zipResult = $zip->open($file, ZIPARCHIVE::CREATE);
if ($zipResult === true) {
for($i = 0; $i < $zip->numFiles; $i++) {
$fileName = $zip->getNameIndex($i);
$fileInfo = pathinfo($fileName);
if (strpos($fileName, '_') !== 0 && strpos($fileName, '.') !== 0 && strpos($fileInfo['basename'], '_') !== 0 && strpos($fileInfo['basename'], '.') !== 0) {
if ($fileInfo['dirname'] !== '.' && ! file_exists($path.$fileInfo['dirname'])) {
$parts = explode('/', $fileInfo['dirname']);
$dirPath = $path;
foreach ($parts as $part) {
$dirPath .= $part . DIRECTORY_SEPARATOR;
wp_mkdir_p($dirPath);
}
}
if (substr($fileName, -1) !== '/' && substr($fileName, -1) !== '\\') {
$targetFile = $path.str_replace('//', DIRECTORY_SEPARATOR, $fileName);
file_put_contents($targetFile, $zip->getFromName($fileName));
updatePermissions($targetFile);
}
}
}
$zip->close();
}
} else {
include_once APPPATH . "libraries/pclzip.lib.php";
$pclZip = new PclZip($file);
$list = $pclZip->listContent();
if ($list) {
for ($i=0; $i<sizeof($list); $i++) {
$fileInfo = $list[$i];
$fileName = $fileInfo['filename'];
if (strpos($fileName, '_') !== 0 && strpos($fileName, '.') !== 0 && strpos($fileName, '/_') === FALSE && strpos($fileName, '/.') === FALSE) {
if ($fileInfo['folder']) {
if ( ! file_exists($path.$fileName)) {
wp_mkdir_p($path.$fileName);
}
} elseif ( ! file_exists($path . dirname($fileName))) {
$parts = explode('/', dirname($fileName));
$dirPath = $path;
foreach ($parts as $part) {
$dirPath .= $part . DIRECTORY_SEPARATOR;
wp_mkdir_p($dirPath);
}
}
$extract = $pclZip->extract(PCLZIP_OPT_BY_INDEX, $fileInfo['index'], PCLZIP_OPT_EXTRACT_AS_STRING);
if ( ! $fileInfo['folder'] && $extract && isset($extract[0]['content'])) {
$targetFile = $path.$fileName;
file_put_contents($targetFile, $extract[0]['content']);
updatePermissions($targetFile);
}
}
}
}
$zipResult = count($list) !== 0;
}
return $zipResult;
}
}
if( ! function_exists('recurse_move'))
{
/**
* Move files recursively
*
* @param string $src
* @param string $dst
*/
function recurse_move($src, $dst) {
$src = rtrim($src,'/\\');
$dst = rtrim($dst,'/\\');
$dir = opendir($src);
wp_mkdir_p($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) )
{
recurse_move($src . '/' . $file,$dst . '/' . $file);
}
else
{
rename($src . '/' . $file,$dst . '/' . $file);
updatePermissions($dst . '/' . $file);
}
}
}
closedir($dir);
rmdir($src);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,255 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Nwdthemes Standalone Slider Revolution
*
* @package StandaloneRevslider
* @author Nwdthemes <mail@nwdthemes.com>
* @link http://nwdthemes.com/
* @copyright Copyright (c) 2015. Nwdthemes
* @license http://themeforest.net/licenses/terms/regular
*/
/**
* Get image url by id and size
*
* @param int Image id
* @param string Size type
* @return string
*/
if( ! function_exists('wp_get_attachment_image_src'))
{
function wp_get_attachment_image_src($attachment_id, $size='thumbnail')
{
if ( $image = image_downsize($attachment_id, $size) )
return $image;
else
return false;
}
}
if( ! function_exists('image_downsize')) {
/**
* Resize image by id and preset size
*
* @param int $id
* @param string $size
* @return mixed
*/
function image_downsize($id, $size = 'medium') {
$ci = &get_instance();
$ci->load->model('image_model', 'Image');
$imageUrl = $ci->Image->getUrl($id);
if ( ! $imageUrl) {
return false;
}
if ($size == 'full') {
if ( ! file_exists(FCPATH . RS_IMAGE_PATH . '/' . $imageUrl) || ! $size = getimagesize(FCPATH . RS_IMAGE_PATH . '/' . $imageUrl)){
return false;
}
$resultUrl = base_url() . RS_IMAGE_PATH . '/' . $imageUrl;
$width = $size[0];
$height = $size[1];
} else {
$sizes = $ci->config->item('rs_image_sizes');
$targetSize = isset($sizes[$size]) ? $sizes[$size] : reset($sizes);
$width = $targetSize['width'];
$height = $targetSize['height'];
$resultUrl = image_resize(FCPATH . RS_IMAGE_PATH . '/' . $imageUrl, $width, $height);
}
return array( $resultUrl, $width, $height );
}
}
/**
* Resize image
*
* @param string Image url
* @param int Width
* @param int Height
* @param boolean Is crop
* @param boolean Is single
* @param boolean Is upscale
* @return string
*/
if( ! function_exists('image_resize')) {
function image_resize($url, $width = null, $height = null, $crop = null, $single = true, $upscale = false) {
$ci = &get_instance();
$arrImagePath = explode('/', $url);
$imageFile = array_pop($arrImagePath);
$thumbUrl = RS_THUMB_PATH . '/' . $width . 'x' . $height . '_' . $imageFile;
if ( ! file_exists(FCPATH . $thumbUrl) || ! getimagesize(FCPATH . $thumbUrl))
{
$ci->load->library('image_moo');
$ci->image_moo->load( image_url_to_path($url) );
if ($crop)
{
$ci->image_moo->resize_crop($width, $height);
}
else
{
$ci->image_moo->resize($width, $height);
}
$ci->image_moo->save(FCPATH . $thumbUrl, true);
if ($ci->image_moo->errors) {
return false;
}
}
return base_url() . $thumbUrl;
}
}
/**
* Alias for Resize Image
*/
if( ! function_exists('rev_aq_resize'))
{
function rev_aq_resize($url, $width = null, $height = null, $crop = null, $single = true, $upscale = false)
{
return image_resize($url, $width, $height, $crop, $single, $upscale);
}
}
/**
* Insert new image
*
* @param array Data
* @param string Image
* @return int Id
*/
if( ! function_exists('wp_insert_attachment'))
{
function wp_insert_attachment($data, $image) {
$ci = &get_instance();
$ci->load->model('image_model', 'Image');
return $ci->Image->insert($image);
}
}
/**
* Get image path by id
*
* @param int $attachment_id
* @return string
*/
if( ! function_exists('get_attached_file'))
{
function get_attached_file($attachment_id) {
$ci = &get_instance();
$ci->load->model('image_model', 'Image');
$imageUrl = $ci->Image->getUrl($attachment_id);
if ( ! $imageUrl)
{
return false;
}
return FCPATH . 'media/' . $imageUrl;
}
}
/**
* Get image id by url
*
* @param string $url
* @return int
*/
if( ! function_exists('get_image_id_by_url'))
{
function get_image_id_by_url($url) {
$ci = &get_instance();
$ci->load->model('image_model', 'Image');
$id = $ci->Image->getId($url);
if ( ! $id)
{
return false;
}
return $id;
}
}
if( ! function_exists('attachment_url_to_postid'))
{
function attachment_url_to_postid($url) {
return get_image_id_by_url($url);
}
}
if( ! function_exists('image_url_to_path')) {
/**
* Convert image url to path
*
* @param string
* @return string
*/
function image_url_to_path($url) {
$baseUrl = base_url() . RS_IMAGE_PATH . '/';
$basePath = FCPATH . RS_IMAGE_PATH . '/';
if (strpos($url, $baseUrl) === false && strpos($url, $basePath) === false) {
return $url;
}
$image = str_replace(array($baseUrl, $basePath), '', $url);
$path = $basePath . $image;
return $path;
}
}
/**
* For compatiblity
*/
if( ! function_exists('wp_generate_attachment_metadata'))
{
function wp_generate_attachment_metadata() {
return FALSE;
}
}
if( ! function_exists('wp_update_attachment_metadata'))
{
function wp_update_attachment_metadata() {
return FALSE;
}
}
if( ! function_exists('wp_get_attachment_metadata'))
{
function wp_get_attachment_metadata() {
return FALSE;
}
}
if( ! function_exists('get_intermediate_image_sizes'))
{
function get_intermediate_image_sizes() {
return array();
}
}
if( ! function_exists('get_the_title'))
{
function get_the_title($id) {
return '';
}
}

View File

@@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

View File

@@ -0,0 +1,84 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Nwdthemes Standalone Slider Revolution
*
* @package StandaloneRevslider
* @author Nwdthemes <mail@nwdthemes.com>
* @link http://nwdthemes.com/
* @copyright Copyright (c) 2015. Nwdthemes
* @license http://themeforest.net/licenses/terms/regular
*/
/**
* Get translated string
*
* @param string $string
* @return string
*/
if( ! function_exists('__'))
{
function __($string = '')
{
$ci = &get_instance();
if ( ! isset($ci->translator))
{
return $string;
}
return $ci->translator->gettext($string);
}
}
/**
* Output translation string
*
* @param string $string
*/
if( ! function_exists('_e'))
{
function _e($string = '')
{
echo __($string);
}
}
/**
* Set current language
*
* @param string Languag
*/
if( ! function_exists('set_language'))
{
function set_language($lang) {
$ci = &get_instance();
if (array_key_exists($lang, $ci->config->item('available_languages'))) {
if (isset($ci->session)) $ci->session->set_userdata('language', $lang);
update_option('language', $lang);
}
}
}
/**
* Get current language
*
* @return string Languag
*/
if( ! function_exists('get_language'))
{
function get_language() {
$ci = &get_instance();
$lang = isset($ci->session) ? $ci->session->userdata('language') : '';
if ( ! $lang) {
$lang = get_option('language', $ci->config->item('default_lang_code'));
}
if ( ! array_key_exists($lang, $ci->config->item('available_languages'))) {
$lang = $ci->config->item('default_lang_code');
}
return $lang;
}
}

View File

@@ -0,0 +1,91 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Nwdthemes Standalone Slider Revolution
*
* @package StandaloneRevslider
* @author Nwdthemes <mail@nwdthemes.com>
* @link http://nwdthemes.com/
* @copyright Copyright (c) 2015. Nwdthemes
* @license http://themeforest.net/licenses/terms/regular
*/
if( ! function_exists('get_option')) {
/**
* Get option
*
* @param string Handle
* @param string Default value
* @return string Option value
*/
function get_option($handle, $default = false) {
$ci = &get_instance();
$ci->load->model('option_model', 'Option');
if ($value = $ci->Option->get_option($handle)) {
if ((strpos($value, 'a:') !== false
|| strpos($value, 's:') !== false
|| strpos($value, 'O:') !== false
|| strpos($value, 'i:') !== false
|| strpos($value, 'b:') !== false)
&& (($unserializedValue = @unserialize($value)) !== false || $value == 'b:0;')) {
$value = $unserializedValue;
}
return $value;
} else {
return $default;
}
}
}
if( ! function_exists('update_option')) {
/**
* Update option
*
* @param string $handle
* @param string value
*/
function update_option($handle, $option = '') {
$ci = &get_instance();
$ci->load->model('option_model', 'Option');
$ci->Option->update_option($handle, $option);
}
}
if( ! function_exists('add_option')) {
/**
* Add option
*
* @param string $handle
* @param string value
*/
function add_option($handle, $option = '', $deprecated = '', $autoload = 'yes') {
update_option($handle, $option);
return true;
}
}
if( ! function_exists('delete_option')) {
/**
* Delete option
*
* @param string $handle
*/
function delete_option($handle) {
$ci = &get_instance();
$ci->load->model('option_model', 'Option');
$ci->Option->delete_option($handle);
}
}

View File

@@ -0,0 +1,182 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Nwdthemes Standalone Slider Revolution
*
* @package StandaloneRevslider
* @author Nwdthemes <mail@nwdthemes.com>
* @link http://nwdthemes.com/
* @copyright Copyright (c) 2016. Nwdthemes
* @license http://themeforest.net/licenses/terms/regular
*/
if( ! function_exists('is_plugin_active')) {
/**
* Checks if addon activated
*
* @param string $plugin
* @return boolean
*/
function is_plugin_active($plugin) {
$_ci = &get_instance();
$_ci->load->library('plugin');
return $_ci->plugin->isPluginActive($plugin);
}
}
if( ! function_exists('is_plugin_inactive')) {
/**
* Checks if addon not activated
*
* @param string $plugin
* @return boolean
*/
function is_plugin_inactive($plugin) {
$_ci = &get_instance();
$_ci->load->library('plugin');
return ! $_ci->plugin->isPluginActive($plugin);
}
}
if( ! function_exists('activate_plugin')) {
/**
* Activate plugin
*
* @param string $plugin
* @return boolean
*/
function activate_plugin($plugin) {
$_ci = &get_instance();
$_ci->load->library('plugin');
return $_ci->plugin->activatePlugin($plugin);
}
}
if( ! function_exists('deactivate_plugins')) {
/**
* Deactivate plugin
*
* @param string $plugin
* @return boolean
*/
function deactivate_plugins($plugin) {
$_ci = &get_instance();
$_ci->load->library('plugin');
return $_ci->plugin->deactivatePlugin($plugin);
}
}
if( ! function_exists('get_plugins')) {
/**
* Get plugins
*
* return boolean
*/
function get_plugins() {
$_ci = &get_instance();
$_ci->load->library('plugin');
return $_ci->plugin->getPlugins();
}
}
if( ! function_exists('plugins_url')) {
/**
* Get plugins url
*
* @param string $file
* @param string $plugin
* @return string
*/
function plugins_url($file, $plugin) {
$_ci = &get_instance();
$_ci->load->library('plugin');
return $_ci->plugin->pluginUrl($plugin) . '/' . $file;
}
}
if( ! function_exists('plugin_dir_url')) {
/**
* Get plugin dir url
*
* @param string $plugin
* @return string
*/
function plugin_dir_url($plugin) {
$_ci = &get_instance();
$_ci->load->library('plugin');
return $_ci->plugin->pluginUrl($plugin) . '/';
}
}
if( ! function_exists('plugin_dir_path')) {
/**
* Get plugin dir path
*
* @param string $plugin
* @return string
*/
function plugin_dir_path($plugin) {
$_ci = &get_instance();
$_ci->load->library('plugin');
return $_ci->plugin->pluginDir($plugin);
}
}
if( ! function_exists('plugin_basename')) {
/**
* Get plugin name
*
* @param string $plugin
* @return string
*/
function plugin_basename($plugin) {
$_ci = &get_instance();
$_ci->load->library('plugin');
return $_ci->plugin->pluginName($plugin);
}
}
if( ! function_exists('update_plugin')) {
/**
* Update plugin
*
* @param string $plugin
* @return boolean
*/
function update_plugin($plugin) {
$_ci = &get_instance();
$_ci->load->library('plugin');
return $_ci->plugin->updatePlugin($plugin);
}
}

View File

@@ -0,0 +1,32 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if( ! function_exists('trace')) {
function trace($var) {
echo('<pre>');
print_r($var);
echo('</pre>');
}
}
if( ! function_exists('callback_export')) {
function callback_export($callback) {
if (is_string($callback)) {
$export = $callback;
} elseif (is_array($callback)) {
$temp = array();
foreach ($callback as $part) {
if (is_object($part)) {
$temp[] = get_class($part);
} else {
$temp[] = $part;
}
}
$export = implode('->', $temp);
} elseif (is_object($callback)) {
$export = get_class($callback);
} else {
$export = var_export($callback, true);
}
return $export;
}
}

View File

@@ -0,0 +1,349 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Nwdthemes Standalone Slider Revolution
*
* @package StandaloneRevslider
* @author Nwdthemes <mail@nwdthemes.com>
* @link http://nwdthemes.com/
* @copyright Copyright (c) 2015. Nwdthemes
* @license http://themeforest.net/licenses/terms/regular
*/
if( ! function_exists('check_for_jquery_addon'))
{
/**
* Checks if jQuery editor addon installed and have correct version
*
* return boolean
*/
function check_for_jquery_addon() {
$ci = &get_instance();
$ci->load->library('updater');
$result = $ci->updater->check_jquery_addon();
return $result['success'];
}
}
if( ! function_exists('get_jquery_addon_message'))
{
/**
* Get message about jQuery addon
*
* return string
*/
function get_jquery_addon_message() {
$ci = &get_instance();
$ci->load->library('updater');
$result = $ci->updater->check_jquery_addon();
return isset($result['message']) ? $result['message'] : '';
}
}
if( ! function_exists('is_jquery_addon_activated')) {
/**
* Checks if jQuery editor addon activated
*
* return boolean
*/
function is_jquery_addon_activated() {
return get_option('jquery-plugin-code', '') && get_option('jquery-plugin-code-activated', 'false') == 'true';
}
}
if( ! function_exists('is_jquery_addon_temp_activated')) {
/**
* Checks if jQuery editor addon temporary activated
*
* return boolean
*/
function is_jquery_addon_temp_activated() {
return get_option('jquery-plugin-code', '') && get_option('jquery-plugin-temp-active', 'false') == 'true';
}
}
if( ! function_exists('dbDelta'))
{
/**
* Execute DB updates
*
* @param string $queries
* @param boolean $execute
* @return array
*/
function dbDelta( $queries = '', $execute = true ) {
global $wpdb;
if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) )
$queries = wp_get_db_schema( $queries );
// Separate individual queries into an array
if ( !is_array($queries) ) {
$queries = explode( ';', $queries );
$queries = array_filter( $queries );
}
/**
* Filter the dbDelta SQL queries.
*
* @since 3.3.0
*
* @param array $queries An array of dbDelta SQL queries.
*/
$queries = apply_filters( 'dbdelta_queries', $queries );
$cqueries = array(); // Creation Queries
$iqueries = array(); // Insertion Queries
$for_update = array();
// Create a tablename index for an array ($cqueries) of queries
foreach($queries as $qry) {
if ( preg_match( "|CREATE TABLE ([^ ]*)|", $qry, $matches ) ) {
$cqueries[ trim( $matches[1], '`' ) ] = $qry;
$for_update[$matches[1]] = 'Created table '.$matches[1];
} elseif ( preg_match( "|CREATE DATABASE ([^ ]*)|", $qry, $matches ) ) {
array_unshift( $cqueries, $qry );
} elseif ( preg_match( "|INSERT INTO ([^ ]*)|", $qry, $matches ) ) {
$iqueries[] = $qry;
} elseif ( preg_match( "|UPDATE ([^ ]*)|", $qry, $matches ) ) {
$iqueries[] = $qry;
} else {
// Unrecognized query type
}
}
/**
* Filter the dbDelta SQL queries for creating tables and/or databases.
*
* Queries filterable via this hook contain "CREATE TABLE" or "CREATE DATABASE".
*
* @since 3.3.0
*
* @param array $cqueries An array of dbDelta create SQL queries.
*/
$cqueries = apply_filters( 'dbdelta_create_queries', $cqueries );
/**
* Filter the dbDelta SQL queries for inserting or updating.
*
* Queries filterable via this hook contain "INSERT INTO" or "UPDATE".
*
* @since 3.3.0
*
* @param array $iqueries An array of dbDelta insert or update SQL queries.
*/
$iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
$global_tables = $wpdb->tables( 'global' );
foreach ( $cqueries as $table => $qry ) {
// Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal.
if ( in_array( $table, $global_tables ) && ! wp_should_upgrade_global_tables() ) {
unset( $cqueries[ $table ], $for_update[ $table ] );
continue;
}
// Fetch the table column structure from the database
$suppress = $wpdb->suppress_errors();
$searchTables = $wpdb->get_results("SHOW TABLES LIKE '{$table}';");
$tablefields = $searchTables ? $wpdb->get_results("DESCRIBE {$table};") : false;
$wpdb->suppress_errors( $suppress );
if ( ! $tablefields )
continue;
// Clear the field and index arrays.
$cfields = $indices = array();
// Get all of the field names in the query from between the parentheses.
preg_match("|\((.*)\)|ms", $qry, $match2);
$qryline = trim($match2[1]);
// Separate field lines into an array.
$flds = explode("\n", $qryline);
// For every field line specified in the query.
foreach ($flds as $fld) {
// Extract the field name.
preg_match("|^([^ ]*)|", trim($fld), $fvals);
$fieldname = trim( $fvals[1], '`' );
// Verify the found field name.
$validfield = true;
switch (strtolower($fieldname)) {
case '':
case 'primary':
case 'index':
case 'fulltext':
case 'unique':
case 'key':
$validfield = false;
$indices[] = trim(trim($fld), ", \n");
break;
}
$fld = trim($fld);
// If it's a valid field, add it to the field array.
if ($validfield) {
$cfields[strtolower($fieldname)] = trim($fld, ", \n");
}
}
// For every field in the table.
foreach ($tablefields as $tablefield) {
$tablefield = (object) $tablefield;
// If the table field exists in the field array ...
if (array_key_exists(strtolower($tablefield->Field), $cfields)) {
// Get the field type from the query.
preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
$fieldtype = $matches[1];
// Is actual field type different from the field type in query?
if ($tablefield->Type != $fieldtype) {
// Add a query to change the column type
$_query = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[strtolower($tablefield->Field)];
$cqueries[] = str_replace(" {$tablefield->Field} ", " `{$tablefield->Field}` ", $_query);
$for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
}
// Get the default value from the array
// todo: Remove this?
//echo "{$cfields[strtolower($tablefield->Field)]}<br>";
if (preg_match("| DEFAULT '(.*?)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {
$default_value = $matches[1];
if ($tablefield->Default != $default_value) {
// Add a query to change the column's default value
$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'";
$for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
}
}
// Remove the field from the array (so it's not added).
unset($cfields[strtolower($tablefield->Field)]);
} else {
// This field exists in the table, but not in the creation queries?
}
}
// For every remaining field specified for the table.
foreach ($cfields as $fieldname => $fielddef) {
// Push a query line into $cqueries that adds the field to that table.
$cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
$for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname;
}
// Index stuff goes here. Fetch the table index structure from the database.
$tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};");
if ($tableindices) {
// Clear the index array.
$index_ary = array();
// For every index in the table.
foreach ($tableindices as $tableindex) {
$tableindex = (object) $tableindex;
// Add the index to the index data array.
$keyname = $tableindex->Key_name;
$index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part);
$index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0)?true:false;
}
// For each actual index in the index array.
foreach ($index_ary as $index_name => $index_data) {
// Build a create string to compare to the query.
$index_string = '';
if ($index_name == 'PRIMARY') {
$index_string .= 'PRIMARY ';
} elseif ( $index_data['unique'] ) {
$index_string .= 'UNIQUE ';
}
$index_string .= 'KEY ';
if ($index_name != 'PRIMARY') {
$index_string .= $index_name;
}
$index_columns = '';
// For each column in the index.
foreach ($index_data['columns'] as $column_data) {
if ($index_columns != '') $index_columns .= ',';
// Add the field to the column list string.
$index_columns .= $column_data['fieldname'];
if ($column_data['subpart'] != '') {
$index_columns .= '('.$column_data['subpart'].')';
}
}
// The alternative index string doesn't care about subparts
$alt_index_columns = preg_replace( '/\([^)]*\)/', '', $index_columns );
// Add the column list to the index create string.
$index_strings = array(
"$index_string ($index_columns)",
"$index_string ($alt_index_columns)",
);
foreach( $index_strings as $index_string ) {
if ( ! ( ( $aindex = array_search( $index_string, $indices ) ) === false ) ) {
unset( $indices[ $aindex ] );
break;
// todo: Remove this?
//echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n";
}
}
// todo: Remove this?
//else echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br /><b>Did not find index:</b>".$index_string."<br />".print_r($indices, true)."</pre>\n";
}
}
// For every remaining index specified for the table.
foreach ( (array) $indices as $index ) {
// Push a query line into $cqueries that adds the index to that table.
$cqueries[] = "ALTER TABLE {$table} ADD $index";
$for_update[] = 'Added index ' . $table . ' ' . $index;
}
// Remove the original table creation query from processing.
unset( $cqueries[ $table ], $for_update[ $table ] );
}
$allqueries = array_merge($cqueries, $iqueries);
if ($execute) {
foreach ($allqueries as $query) {
$wpdb->query($query);
}
}
return $for_update;
}
}
// For compatibility
if( ! function_exists('wp_should_upgrade_global_tables')) {
function wp_should_upgrade_global_tables() {
return false;
}
}
if( ! function_exists('wp_get_db_schema')) {
function wp_get_db_schema($queries = array()) {
return $queries;
}
}