PluginProbe
WP Coder – Insert & Manage Code Snippets / 2.5.5
WP Coder – Insert & Manage Code Snippets v2.5.5
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
wp-coder / includes / class-db-update.php

class-db-update.php in WP Coder – Insert & Manage Code Snippets 2.5.5, at includes/class-db-update.php

103 lines 3.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 * @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 wpcoder;
12
13 if ( ! defined( 'ABSPATH' ) ) exit;
14
15 class Wow_DB_Update {
16
17 function __construct( $plugin_dir, $plugin_slug ) {
18 $this->plugin_dir = $plugin_dir;
19 $upload = wp_upload_dir();
20 $this->basedir = $upload['basedir'] . '/' . $plugin_slug . '/';
21 }
22
23 function addNewItem( $tblname, $info ) {
24 global $wpdb;
25 $fields = $wpdb->get_col( "DESC " . $tblname, 0);
26 $data = array();
27 foreach ( $fields as $key ) {
28 if ( is_array( $info[$key] ) == true ){
29 $data[$key] = serialize( $info[$key] );
30 }
31 else {
32 $data[$key] = $info[$key];
33 }
34 }
35 $wpdb->insert( $tblname, $data );
36 $lastid = $wpdb->insert_id;
37 $result = $wpdb->get_results( "SELECT * FROM " . $tblname . " WHERE id = " . $lastid );
38 if ( count( $result ) > 0 ) {
39 foreach ( $result as $key => $val ) {
40 $param = unserialize( $val->param );
41 $file_script = $this->plugin_dir . 'admin/partials/generator/script.php';
42 if ( file_exists ( $file_script ) ) {
43 $path_script = $this->basedir . 'script-' . $lastid . '.js';
44 ob_start();
45 include ( $file_script );
46 $content_script = ob_get_contents();
47 ob_end_clean();
48 file_put_contents( $path_script, $content_script );
49 }
50 $file_style = $this->plugin_dir . 'admin/partials/generator/style.php';
51 if ( file_exists ( $file_style ) ) {
52 $path_style = $this->basedir . 'style-' . $lastid . '.css';
53 ob_start();
54 include ( $file_style );
55 $content_style = ob_get_contents();
56 ob_end_clean();
57 file_put_contents( $path_style, $content_style );
58 }
59 }
60 }
61 }
62 function updItem( $tblname, $info ) {
63 global $wpdb;
64 $fields = $wpdb->get_col( "DESC " . $tblname, 0);
65 $data = array();
66 foreach ( $fields as $key ) {
67 if (is_array( $info[$key] ) == true ) {
68 $data[$key] = serialize( $info[$key] );
69 }
70 else {
71 $data[$key] = $info[$key];
72 }
73 }
74 $where = array( 'id' => $info["id"] );
75 $id = $info["id"];
76 $wpdb->update( $tblname, $data, array('id' => $id ), $format = null, $where_format = null );
77 $result = $wpdb->get_results( "SELECT * FROM ".$tblname." WHERE id = " . $id );
78 if (count( $result ) > 0 ) {
79 foreach ( $result as $key => $val ) {
80 $param = unserialize($val->param);
81 $file_script = $this->plugin_dir . 'admin/partials/generator/script.php';
82 if ( file_exists ( $file_script ) ) {
83 $path_script = $this->basedir . 'script-' . $id . '.js';
84 ob_start();
85 include ( $file_script );
86 $content_script = ob_get_contents();
87 ob_end_clean();
88 file_put_contents( $path_script, $content_script );
89 }
90 $file_style = $this->plugin_dir . 'admin/partials/generator/style.php';
91 if ( file_exists ( $file_style ) ) {
92 $path_style = $this->basedir . '/style-' . $id . '.css';
93 ob_start();
94 include ( $file_style );
95 $content_style = ob_get_contents();
96 ob_end_clean();
97 file_put_contents( $path_style, $content_style );
98 }
99 }
100 }
101 }
102 }
103