PluginProbe
Bubble Menu – Floating Button Menu with Sticky Navigation / 2.2
Bubble Menu – Floating Button Menu with Sticky Navigation v2.2
trunk 1.3 2.0 2.2 2.2.1 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.1 4.1.1
bubble-menu / includes / class-db.php

class-db.php in Bubble Menu – Floating Button Menu with Sticky Navigation 2.2, at includes/class-db.php

148 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * DataBase Update
4 *
5 * @package Wow_Plugin
6 * @subpackage Includes/Database
7 * @author Dmytro Lobov <i@wpbiker.com>
8 * @copyright 2019 Wow-Company
9 * @license GNU Public License
10 * @version 1.0
11
12 */
13
14 namespace bubble_menu_lite;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20 /**
21 * Creates and updates a record in the database
22 *
23 * @since 1.0
24 *
25 * @property string plugin_dir - filesystem directory path for the plugin
26 * @property string basedir - URL to the file which saving CSS and JS files
27 */
28 class Wow_DB_Update {
29
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 /**
45 * Create a new Item in the database
46 *
47 * @param string $table name of the datatable
48 * @param string $info array of parameters to save to the database
49 *
50 * @since 1.0
51 */
52 function create_item( $table, $info ) {
53 global $wpdb;
54 $fields = $wpdb->get_col( "DESC " . $table, 0 );
55 // Collect all passed parameters
56 $data = array();
57 foreach ( $fields as $key ) {
58 if ( is_array( $info[ $key ] ) == true ) {
59 $data[ $key ] = serialize( $info[ $key ] );
60 } else {
61 $data[ $key ] = $info[ $key ];
62 }
63 }
64 // Insert in database
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 }
95 }
96 }
97
98 /**
99 * Update an existing item in the database
100 *
101 * @param string $table name of the datatable
102 * @param string $info array of parameters to save to the database
103 *
104 * @since 1.0
105 */
106 function update_item( $table, $info ) {
107 global $wpdb;
108 $fields = $wpdb->get_col( "DESC " . $table, 0 );
109 // Collect all passed parameters
110 $data = array();
111 foreach ( $fields as $key ) {
112 if ( is_array( $info[ $key ] ) == true ) {
113 $data[ $key ] = serialize( $info[ $key ] );
114 } else {
115 $data[ $key ] = $info[ $key ];
116 }
117 }
118
119 $id = absint( $info["id"] );
120 $wpdb->update( $table, $data, array( 'id' => $id ), $format = null, $where_format = null );
121 // Get information for creating JS and CSS files
122 $result = $wpdb->get_results( "SELECT * FROM " . $table . " WHERE id = " . $id );
123 if ( count( $result ) > 0 ) {
124 foreach ( $result as $key => $val ) {
125 $param = unserialize( $val->param );
126 $file_script = $this->plugin['dir'] . 'admin/partials/generator/script.php';
127 if ( file_exists( $file_script ) ) {
128 $path_script = $this->basedir . 'script-' . $id . '.js';
129 ob_start();
130 include( $file_script );
131 $content_script = ob_get_contents();
132 ob_end_clean();
133 file_put_contents( $path_script, $content_script );
134 }
135 $file_style = $this->plugin['dir'] . 'admin/partials/generator/style.php';
136 if ( file_exists( $file_style ) ) {
137 $path_style = $this->basedir . '/style-' . $id . '.css';
138 ob_start();
139 include( $file_style );
140 $content_style = ob_get_contents();
141 ob_end_clean();
142 file_put_contents( $path_style, $content_style );
143 }
144 }
145 }
146 }
147 }
148