| 1 |
<?php |
| 2 |
/** |
| 3 |
* DataBase Update |
| 4 |
* |
| 5 |
* @package Wow_Plugin |
| 6 |
* @copyright Copyright (c) 2018, Dmytro Lobov |
| 7 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 8 |
* @since 1.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace float_menu_free; |
| 12 |
|
| 13 |
if ( !defined( 'ABSPATH' ) ) exit; |
| 14 |
|
| 15 |
class Wow_DB_Update |
| 16 |
{ |
| 17 |
|
| 18 |
function __construct( $plugin_dir, $plugin_slug ) |
| 19 |
{ |
| 20 |
$this->plugin_dir = $plugin_dir; |
| 21 |
$upload = wp_upload_dir(); |
| 22 |
$this->basedir = $upload[ 'basedir' ] . '/' . $plugin_slug . '/'; |
| 23 |
} |
| 24 |
|
| 25 |
function addNewItem( $tblname, $info ) |
| 26 |
{ |
| 27 |
global $wpdb; |
| 28 |
$fields = $wpdb->get_col( "DESC " . $tblname, 0 ); |
| 29 |
$data = array(); |
| 30 |
foreach ( $fields as $key ) { |
| 31 |
if ( is_array( $info[ $key ] ) == true ) { |
| 32 |
$data[ $key ] = serialize( $info[ $key ] ); |
| 33 |
} else { |
| 34 |
$data[ $key ] = $info[ $key ]; |
| 35 |
} |
| 36 |
} |
| 37 |
$wpdb->insert( $tblname, $data ); |
| 38 |
$lastid = $wpdb->insert_id; |
| 39 |
$result = $wpdb->get_results( "SELECT * FROM " . $tblname . " WHERE id = " . $lastid ); |
| 40 |
if ( count( $result ) > 0 ) { |
| 41 |
foreach ( $result as $key => $val ) { |
| 42 |
$param = unserialize( $val->param ); |
| 43 |
$file_script = $this->plugin_dir . 'admin/partials/generator/script.php'; |
| 44 |
if ( file_exists( $file_script ) ) { |
| 45 |
$path_script = $this->basedir . 'script-' . $lastid . '.js'; |
| 46 |
ob_start(); |
| 47 |
include($file_script); |
| 48 |
$content_script = ob_get_contents(); |
| 49 |
$script_packer = __NAMESPACE__ . '\\JavaScriptPacker'; |
| 50 |
$packer = new $script_packer( $content_script, 'Normal', true, false ); |
| 51 |
$packed = $packer->pack(); |
| 52 |
ob_end_clean(); |
| 53 |
file_put_contents( $path_script, $packed ); |
| 54 |
} |
| 55 |
$file_style = $this->plugin_dir . 'admin/partials/generator/style.php'; |
| 56 |
if ( file_exists( $file_style ) ) { |
| 57 |
$path_style = $this->basedir . 'style-' . $lastid . '.css'; |
| 58 |
ob_start(); |
| 59 |
include($file_style); |
| 60 |
$content_style = ob_get_contents(); |
| 61 |
ob_end_clean(); |
| 62 |
file_put_contents( $path_style, $content_style ); |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
function updItem( $tblname, $info ) |
| 69 |
{ |
| 70 |
global $wpdb; |
| 71 |
$fields = $wpdb->get_col( "DESC " . $tblname, 0 ); |
| 72 |
$data = array(); |
| 73 |
foreach ( $fields as $key ) { |
| 74 |
if ( is_array( $info[ $key ] ) == true ) { |
| 75 |
$data[ $key ] = serialize( $info[ $key ] ); |
| 76 |
} else { |
| 77 |
$data[ $key ] = $info[ $key ]; |
| 78 |
} |
| 79 |
} |
| 80 |
$where = array( 'id' => $info[ "id" ] ); |
| 81 |
$id = $info[ "id" ]; |
| 82 |
$wpdb->update( $tblname, $data, array( 'id' => $id ), $format = null, $where_format = null ); |
| 83 |
$result = $wpdb->get_results( "SELECT * FROM " . $tblname . " WHERE id = " . $id ); |
| 84 |
if ( count( $result ) > 0 ) { |
| 85 |
foreach ( $result as $key => $val ) { |
| 86 |
$param = unserialize( $val->param ); |
| 87 |
$file_script = $this->plugin_dir . 'admin/partials/generator/script.php'; |
| 88 |
if ( file_exists( $file_script ) ) { |
| 89 |
$path_script = $this->basedir . 'script-' . $id . '.js'; |
| 90 |
ob_start(); |
| 91 |
include($file_script); |
| 92 |
$content_script = ob_get_contents(); |
| 93 |
$script_packer = __NAMESPACE__ . '\\JavaScriptPacker'; |
| 94 |
$packer = new $script_packer( $content_script, 'Normal', true, false ); |
| 95 |
$packed = $packer->pack(); |
| 96 |
ob_end_clean(); |
| 97 |
file_put_contents( $path_script, $packed ); |
| 98 |
} |
| 99 |
$file_style = $this->plugin_dir . 'admin/partials/generator/style.php'; |
| 100 |
if ( file_exists( $file_style ) ) { |
| 101 |
$path_style = $this->basedir . '/style-' . $id . '.css'; |
| 102 |
ob_start(); |
| 103 |
include( $file_style ); |
| 104 |
$content_style = ob_get_contents(); |
| 105 |
ob_end_clean(); |
| 106 |
file_put_contents( $path_style, $content_style ); |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
?> |