| @@ -3,12 +3,12 @@ | ||
| 3 | 3 | * DataBase Update |
| 4 | 4 | * |
| 5 | 5 | * @package Wow_Plugin |
| 6 | 6 | * @subpackage Includes/Database |
| 7 | - * @author Dmytro Lobov <i@lobov.dev> | |
| 7 | + * @author Dmytro Lobov <i@wpbiker.com> | |
| 8 | 8 | * @copyright 2019 Wow-Company |
| 9 | 9 | * @license GNU Public License |
| 10 | - * @version 2.0 | |
| 10 | + * @version 1.0 | |
| 11 | 11 | |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | namespace floatingbutton; |
| @@ -25,10 +25,24 @@ | ||
| 25 | 25 | * @property string plugin_dir - filesystem directory path for the plugin |
| 26 | 26 | * @property string basedir - URL to the file which saving CSS and JS files |
| 27 | 27 | */ |
| 28 | 28 | class Wow_DB_Update { |
| 29 | - | |
| 29 | + | |
| 30 | 30 | /** |
| 31 | + * Setup folder fo saving CSS and JS files | |
| 32 | + * | |
| 33 | + * @param string $plugin_dir filesystem directory path for the plugin | |
| 34 | + * @param string $plugin_slug URL directory path for the plugin | |
| 35 | + * | |
| 36 | + * @since 1.0 | |
| 37 | + */ | |
| 38 | + function __construct( $plugin_dir, $plugin_slug ) { | |
| 39 | + $this->plugin['dir'] = $plugin_dir; | |
| 40 | + $upload = wp_upload_dir(); | |
| 41 | + $this->basedir = $upload['basedir'] . '/' . $plugin_slug . '/'; | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 31 | 45 | * Create a new Item in the database |
| 32 | 46 | * |
| 33 | 47 | * @param string $table name of the datatable |
| 34 | 48 | * @param string $info array of parameters to save to the database |
| @@ -48,10 +62,39 @@ | ||
| 48 | 62 | } |
| 49 | 63 | } |
| 50 | 64 | // Insert in database |
| 51 | 65 | $wpdb->insert( $table, $data ); |
| 66 | + // Get information for creating JS and CSS files | |
| 67 | + $last_id = $wpdb->insert_id; | |
| 68 | + $result = $wpdb->get_results( "SELECT * FROM " . $table . " WHERE id = " . $last_id ); | |
| 69 | + if ( count( $result ) > 0 ) { | |
| 70 | + foreach ( $result as $key => $val ) { | |
| 71 | + $param = unserialize( $val->param ); | |
| 72 | + // Create the JS file in the plugin folder in uploads | |
| 73 | + $file_script = $this->plugin['dir'] . 'admin/partials/generator/script.php'; | |
| 74 | + if ( file_exists( $file_script ) ) { | |
| 75 | + $path_script = $this->basedir . 'script-' . $last_id . '.js'; | |
| 76 | + ob_start(); | |
| 77 | + include( $file_script ); | |
| 78 | + $content_script = ob_get_contents(); | |
| 79 | + ob_end_clean(); | |
| 80 | + file_put_contents( $path_script, $content_script ); | |
| 81 | + } | |
| 82 | + | |
| 83 | + // Create the CSS file in the plugin folder in uploads | |
| 84 | + $file_style = $this->plugin['dir'] . 'admin/partials/generator/style.php'; | |
| 85 | + if ( file_exists( $file_style ) ) { | |
| 86 | + $path_style = $this->basedir . 'style-' . $last_id . '.css'; | |
| 87 | + ob_start(); | |
| 88 | + include( $file_style ); | |
| 89 | + $content_style = ob_get_contents(); | |
| 90 | + ob_end_clean(); | |
| 91 | + file_put_contents( $path_style, $content_style ); | |
| 92 | + } | |
| 93 | + } | |
| 94 | + } | |
| 52 | 95 | } |
| 53 | - | |
| 96 | + | |
| 54 | 97 | /** |
| 55 | 98 | * Update an existing item in the database |
| 56 | 99 | * |
| 57 | 100 | * @param string $table name of the datatable |
| @@ -70,10 +113,34 @@ | ||
| 70 | 113 | } else { |
| 71 | 114 | $data[ $key ] = $info[ $key ]; |
| 72 | 115 | } |
| 73 | 116 | } |
| 74 | - | |
| 117 | + | |
| 75 | 118 | $id = absint( $info["id"] ); |
| 76 | 119 | $wpdb->update( $table, $data, array( 'id' => $id ), $format = null, $where_format = null ); |
| 77 | - | |
| 120 | + // Get information for creating JS and CSS files | |
| 121 | + $result = $wpdb->get_results( "SELECT * FROM " . $table . " WHERE id = " . $id ); | |
| 122 | + if ( count( $result ) > 0 ) { | |
| 123 | + foreach ( $result as $key => $val ) { | |
| 124 | + $param = unserialize( $val->param ); | |
| 125 | + $file_script = $this->plugin['dir'] . 'admin/partials/generator/script.php'; | |
| 126 | + if ( file_exists( $file_script ) ) { | |
| 127 | + $path_script = $this->basedir . 'script-' . $id . '.js'; | |
| 128 | + ob_start(); | |
| 129 | + include( $file_script ); | |
| 130 | + $content_script = ob_get_contents(); | |
| 131 | + ob_end_clean(); | |
| 132 | + file_put_contents( $path_script, $content_script ); | |
| 133 | + } | |
| 134 | + $file_style = $this->plugin['dir'] . 'admin/partials/generator/style.php'; | |
| 135 | + if ( file_exists( $file_style ) ) { | |
| 136 | + $path_style = $this->basedir . '/style-' . $id . '.css'; | |
| 137 | + ob_start(); | |
| 138 | + include( $file_style ); | |
| 139 | + $content_style = ob_get_contents(); | |
| 140 | + ob_end_clean(); | |
| 141 | + file_put_contents( $path_style, $content_style ); | |
| 142 | + } | |
| 143 | + } | |
| 144 | + } | |
| 78 | 145 | } |
| 79 | 146 | } |