Commit c8d78461 authored by John Punzalan's avatar John Punzalan

Update entity news and install plugin table

parent 0ebdd0df
{
"directory": "bower_components",
"json": "bower.json"
}
# Include your project-specific ignores in this file
# Read about how to use .gitignore: https://help.github.com/articles/ignoring-files
addons/*
!addons/.gitkeep
assets/*
!assets/.gitkeep
docs/
dist/
bower_components/
node_modules/
backup/
npm-debug.log
debug.log
change.log
external_tranlated_text.php
# Temporary definition
v1_functions.php
lib/cdbt.*
templates/cdbt-*
old.*
/docs
/backup
/sources/styles/old.admin-styles.css
/sources/styles/admin-styles.css
/sources/styles/main.scss
/sources/styles/cdbt-style.css
/sources/styles/styles.min.css
*.bak
{
"bitwise": true,
"browser": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"esnext": true,
"immed": true,
"jquery": true,
"latedef": true,
"newcap": true,
"noarg": true,
"node": true,
"strict": false
}
# Custom DataBase Tables
**C**ustom **D**ata**B**ase **T**ables is commonly called "**CDBT**", it is the plugin for the WordPress. Using this plugin, you can create new table on the database of the WordPress as you like. Then you can do input, output and data updating to created table. Also you can do import and export by format of CSV, TSV, JSON and SQL, and duplicate specific table. Those operation is able to be done easily from the GUI tools on the administration screen of WordPress. In addition, you can provide the functional data manipulation interface to the Web front-end by using some shortcodes or APIs.
* Latest: 2.1.32beta
* Stable: 2.1.31
* Source: [https://github.com/ka215/cdbt](https://github.com/ka215/cdbt)
* Public SVN Repository: [http://wordpress.org/plugins/custom-database-tables/](https://wordpress.org/support/plugin/custom-database-tables)
* Home Page: [https://ka2.org/cdbt/](https://ka2.org/cdbt/)
* Twitter: [@ka2bowy](https://twitter.com/ka2bowy)
* Forum: [WordPress.org](https://wordpress.org/support/plugin/custom-database-tables)
* Donate link: [PayPal Donations](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=2YZY4HWYSWEWG&lc=en_US&currency_code=USD&item_name=)
## Requirements
| Prerequisite | How to check | How to install
| --------------- | ------------ | ------------- |
| PHP >= 5.4.x | `php -v` | php.net([English](http://php.net/manual/en/install.php)/[Japanese](http://php.net/manual/ja/install.php)) |
| Node.js >=5.4.x | `node -v` | [nodejs.org](http://nodejs.org/) |
| gulp >= 3.9.x | `gulp -v` | `npm install -g gulp` |
| Bower >= 1.7.2 | `bower -v` | `npm install -g bower` |
For more installation notes, refer to the [Install gulp and Bower](#install-gulp-and-bower) section in this document.
### Install gulp and Bower {#install-gulp-and-bower}
Building the theme requires [node.js](http://nodejs.org/download/). We recommend you update to the latest version of npm: `npm install -g npm@latest`.
From the command line:
1. Install [gulp](http://gulpjs.com) and [Bower](http://bower.io/) globally with `npm install -g gulp bower`
2. Navigate to the theme directory, then run `npm install`
3. Run `bower install`
You now have all the necessary dependencies to run the build process.
## Installation
Install after downloaded from WordPress admin panel or [download here](https://github.com/ka215/cdbt) and put the plugins directory.
How to install WordPress provisions are as follows.
1. Upload `custom-database-tables` directory to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Navigate to the Custom DB Tables submenu in setting menu
That's it. Now you can easily start creating custom table in database of WordPress
## Usage
Navigate to the Custom DB Tables submenu in setting menu of WordPress admin panel.
First of all, please try to create the database required for the first.
[Please see the tutorial for more use of the plugin](https://ka2.org/cdbt/v2/tutorial/) (Sorry, Japanese only)
## Documentation
### [Plugin Documentation](https://ka2.org/cdbt/v2/) (Sorry, Japanese only)
* [Plugin Basic Information](https://ka2.org/cdbt/v2/basic-info/)
* [Plugin Structure](https://ka2.org/cdbt/v2/structure/)
* [Plugin Method Reference](https://ka2.org/cdbt/v2/methods/)
* [Plugin Action Reference](https://ka2.org/cdbt/v2/action-reference/)
* [Plugin Filter Reference](https://ka2.org/cdbt/v2/filter-reference/)
## Features
* You can create newly tables on the database. (CREATE TABLE)
* You can entry data from on the web to your created table. At that time, the entry form will be created automatically in accordance with the table structure.
* You can edit and remove data in the specific table from on the web.
* You can customize the viewing data as a table listed.
* It is corresponding to the input and output of binary data to the table.
* You can import and export with choosing a format of CSV, TSV, JSON and SQL.
* You can duplicate the specific table.
* Using the shortcodes, you can render the interactive data operation interface on the front-end WEB.
* You can set the permission as viewable users, registerable users and editable users to each tables.
* You can manage the core tables built-in WordPress, since the plugin version 2.0.
* Ofcourse, you can remove your created tables. (DROP TABLE)
* You can initialize data of the specific table. (TRUNCATE TABLE)
* You can modify table. (ALTER TABLE)
* Using built-in plugin methods can connect to various core processes as like CRUD.
## License
GPLv2 or later
## Contributing
1. Fork it
* Create your feature branch (`git checkout -b my-new-feature`)
* Install the dependencies and run gulp (`npm i && gulp`)
* Commit your changes (`git commit -am 'Add some feature'`)
* Push to the branch (`git push origin my-new-feature`)
* Create new Pull Request
2. Donate
* If you thought this plugin felt to be useful, you want to cooperate in the development, or would like to contribute, I'm very happy that you make a donation to me. The magnitude of the amount of the donation is not a problem. Your feelings will become motivation of myself to develop this plugin.<br>[PayPal Donations](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=2YZY4HWYSWEWG&lc=en_US&currency_code=USD&item_name=)
## Thanks to the following:
* [Bootstrap](http://getbootstrap.com/) for the foundation of UI/UX.
* [Fuel UX](http://getfuelux.com/) for outputting main components as UX.
* [Underscore.js](http://underscorejs.org/) for operating data source at frontend.
* [moment.js](http://momentjs.com/) for viewing localization date on the components.
* [Font Awesome](http://fortawesome.github.io/Font-Awesome/) for building an intuitive UI.
* [kinetic](https://github.com/davetayls/jquery.kinetic) for viewing component to multidevice.
* [clipboard.js](https://github.com/zenorocha/clipboard.js) for improving the usability of data.
* [phpMyAdmin](http://www.phpmyadmin.net/) for the inspiration.
## Support
I've prepared a [support forum](https://wordpress.org/support/plugin/custom-database-tables).
Please to slip issuance in here questions about plugin.
Crafted by [ka2](https://ka2.org/) ([@ka2bowy](https://twitter.com/ka2bowy)).
{
"name": "CustomDataBaseTables",
"version": "2.0.7",
"homepage": "https://ka2.org/",
"authors": [
"ka2 <ka2@ka2.org>"
],
"license": "GPL-2.0",
"private": true,
"dependencies": {
"jquery": "~2.2.1",
"bootstrap-sass": "~3.3.6",
"font-awesome-sass": "~4.6.2",
"underscore": "~1.8.3",
"fuelux": "~3.13.0",
"jquery.kinetic": "~2.1.0",
"clipboard": "~1.5.10"
},
"overrides": {
"bootstrap-sass": {
"main": [
"./assets/stylesheets/_bootstrap.scss",
"./assets/fonts/bootstrap/glyphicons-halflings-regular.eot",
"./assets/fonts/bootstrap/glyphicons-halflings-regular.svg",
"./assets/fonts/bootstrap/glyphicons-halflings-regular.ttf",
"./assets/fonts/bootstrap/glyphicons-halflings-regular.woff",
"./assets/fonts/bootstrap/glyphicons-halflings-regular.woff2",
"./assets/javascripts/bootstrap.js"
]
},
"font-awesome-sass": {
"main": [
"./assets/stylesheets/_font-awesome.scss",
"./assets/fonts/font-awesome/fontawesome-webfont.eot",
"./assets/fonts/font-awesome/fontawesome-webfont.svg",
"./assets/fonts/font-awesome/fontawesome-webfont.ttf",
"./assets/fonts/font-awesome/fontawesome-webfont.woff",
"./assets/fonts/font-awesome/fontawesome-webfont.woff2"
]
},
"requirejs": {
"main": ""
},
"bootstrap": {
"main": ""
}
}
}
<?php
/*
Plugin Name: Custom DataBase Tables
Plugin URI: https://ka2.org/
Description: <strong>C</strong>ustom <strong>D</strong>ata<strong>B</strong>ase <strong>T</strong>ables is a database management tool to enhance WordPress as the strongest CMS. Whereby this plugin will dominate the MySQL database of the WordPress, you will be able to create a new custom table. Also you will be able to more thoroughly to manipulate the data.
Version: 2.1.34beta
Author: ka2
Author URI: https://ka2.org/
Copyright: 2016 Monaural Sound (email : ka2@ka2.org)
License: GPL2 - http://www.gnu.org/licenses/gpl.txt
Text Domain: custom-database-tables
Domain Path: /langs
*/
?>
<?php
/* Copyright 2016 ka2 (https://ka2.org/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
?>
<?php
define('CDBT_PLUGIN_VERSION', '2.1.34beta');
define('CDBT_DB_VERSION', '2.1');
define('CDBT', 'custom-database-tables'); // This plugin domain name
// Check environment
$current_php_version = phpversion();
$required_php_version = '5.4';
if (version_compare( $required_php_version, $current_php_version, '>=' )) {
$message = sprintf( 'Your server is running PHP version %s but this plugin requires at least PHP %s. Please run an upgrade.', $current_php_version, $required_php_version);
$notification_html = '<div id="message" class="%s"><p>%s</p></div>';
printf( $notification_html, 'error', $message );
return false;
} else {
require_once plugin_dir_path(__FILE__) . 'functions.php';
CustomDataBaseTables\Lib\factory( 'set_global' );
}
<?php
/**
* Including libraries for this plugin
*/
defined('CDBT') OR die();
$library_dir_name = 'lib';
$library_dir = plugin_dir_path(__FILE__) . $library_dir_name;
$lib_includes = [];
$files = [
'utils.php', // Common utility class. Base class, and this class is available at single
'core.php', // Plugin core class
'config.php', // Configuration class
'validate.php', // Validate class for plugin inherited a common validator
'db.php', // Database class with wrapping wpdb
'ajax.php', // Trait for using ajax
'tmpl.php', // Trait for dynamic rendering templates
'shortcodes/cdbt-view.php', // Trait of shortcode for "cdbt-view"
'shortcodes/cdbt-entry.php', // Trait of shortcode for "cdbt-entry"
'shortcodes/cdbt-edit.php', // Trait of shortcode for "cdbt-edit"
'shortcodes.php', // Trait for shortcodes definitions
'webapis.php', // Trait for web apis definitions
'extras.php', // Trait for enhancements (for customization)
'admin.php', // Entry point class for admin panels
'main.php', // Entry point class for web frontend
'init.php' // Instance factory & plugin activater
];
foreach ($files as $file) {
$lib_includes[] = $library_dir . '/' . $file;
}
unset($library_dir_name, $library_dir, $files, $file);
foreach ($lib_includes as $file) {
if (!file_exists($file)) {
trigger_error(sprintf(__('Include path error "%s"', CDBT), $file), E_USER_ERROR);
}
require_once $file;
}
unset($file);
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
namespace CustomDataBaseTables\Lib;
if ( !class_exists( 'CdbtCore' ) ) :
/**
* Main Plugin Core Class for CustomDataBaseTables
*
* @since 2.0.0
* @since 2.1.33 Add a handler for the add-on
*
* @see CustomDataBaseTables\Lib\CdbtUtility
*/
class CdbtCore extends CdbtUtility {
var $plugin_enabled;
/**
* @var mixed False when not logged in; WP_User object when logged in
*/
public $current_user = false;
/**
* @var obj Append to this plugin as addon
*/
public $extend = array();
public $addons = array();
/**
* @var array Overloads get_option()
*/
public $options = array();
/**
* @var array Overloads get_user_meta()
*/
public $user_options = array();
/**
* @var mixed False when not error or default; WP_Error object when has errors
*/
public $errors;
/**
* @var boolean True is if debug mode
*/
public $debug = false;
/**
* @var array Store the session information for this plugin
*/
protected $cdbt_sessions;
/**
* Initialize plugin core
*
* @since 2.0.0
*/
protected function core_init() {
// Plugin Name
$this->domain_name = CDBT;
$this->basename = apply_filters( 'cdbt_plugin_name', $this->domain_name );
// Versions
$this->version = CDBT_PLUGIN_VERSION;
$this->db_version = CDBT_DB_VERSION;
// Paths
$this->file = __FILE__;
$this->plugin_lib_dir = apply_filters( 'cdbt_plugin_lib_dir_name', 'lib' );
$this->plugin_templates_dir = apply_filters( 'cdbt_plugin_templates_dir_name', 'templates' );
$this->plugin_assets_dir = apply_filters( 'cdbt_plugin_assets_dir_name', 'assets' );
$this->plugin_dir = apply_filters( 'cdbt_plugin_dir_path', str_replace($this->plugin_lib_dir . '/', '', plugin_dir_path( $this->file )) );
$this->plugin_url = apply_filters( 'cdbt_plugin_dir_url', str_replace($this->plugin_lib_dir . '/', '', plugin_dir_url( $this->file )) );
$this->plugin_main_file = apply_filters( 'cdbt_plugin_main_file', $this->plugin_dir . 'cdbt.php' );
$this->plugin_addons_dir = apply_filters( 'cdbt_plugin_addons_dir', $this->plugin_dir . 'addons' ); // @since 2.1.33
// Languages
$this->plugin_lang_dir = apply_filters( 'cdbt_plugin_lang_dir', plugin_basename($this->plugin_dir) . '/langs' );
load_plugin_textdomain( $this->domain_name, false, $this->plugin_lang_dir );
// Ajax Action name
$this->plugin_ajax_action = apply_filters( 'cdbt_plugin_ajax_action', 'cdbt_ajax_handler' );
// Check Installed Addons
// @since 2.1.33
if ( file_exists( $this->plugin_addons_dir ) ) {
$this->installed_addons = [];
array_map( function( $_val ){
$_pi = pathinfo( $_val );
if ( ! isset( $_pi['extension'] ) && ! in_array( $_pi['basename'], [ '.', '..' ] ) ) {
$this->installed_addons[] = $_pi['filename'];
}
}, scandir( $this->plugin_dir . 'addons' ) );
}
}
/**
* Plugin activation and deactivation actions
*
* @since 2.0.0
*/
protected function core_actions() {
register_deactivation_hook( $this->plugin_main_file, array( &$this, 'plugin_deactivation' ) );
register_activation_hook( $this->plugin_main_file, array( &$this, 'plugin_activate' ) );
add_action( 'plugins_loaded', array($this, 'plugin_loaded') );
//add_action( 'init', array($this, 'init_cdbt_sessions') );
add_action( 'shutdown', array( $this, 'cdbt_shutdown' ) );
}
/**
* Run the hooked action before http header response
*
* @since 2.0.0
*/
protected function plugin_loaded() {
$this->plugin_enabled = true;
if ( (isset($_POST['page']) && 'cdbt_tables' === $_POST['page'])
&& (isset($_POST['action']) && !empty($_POST['action']))
&& (isset($_POST[$this->domain_name]) && !empty($_POST[$this->domain_name]) && is_array($_POST[$this->domain_name]))
&& (isset($_POST['file_download']) && 'true' === $_POST['file_download']) ) {
if ('export_table' === $_POST['action'])
$this->download_file( $_POST[$this->domain_name] );
}
if ( isset( $this->installed_addons ) && ! empty( $this->installed_addons ) ) {
foreach ( $this->installed_addons as $_installed_addon ) {
require_once( $this->plugin_addons_dir .'/'. $_installed_addon .'/'. $_installed_addon .'.php' );
}
}
add_filter( 'gettext', array( &$this, 'cdbt_gettext_messages' ), 10, 3 );
}
/**
* Start of the session
*
* @since 2.0.0
*/
protected function init_cdbt_sessions() {
if ( ! session_id() )
session_start();
}
/**
* Shutdown all processes
*
* @since 2.0.4
* @since 2.1.33 Updated
* @since 2.1.34 Updated to public method
*/
public function cdbt_shutdown() {
$enable_zlib = ini_get( "zlib.output_compression" );
if ( ! $enable_zlib && ob_get_length() !== false ) {
$buffer = ob_get_contents();
// Finish buffering
ob_end_flush();
}
list( $max ) = sscanf( ini_get( 'memory_limit' ), '%dM' );
$max = intval( $max );
$peak = intval( memory_get_peak_usage( true ) / 1024 / 1024 );
$used = $max !== 0 ? round( $peak / $max * 100, 2 ) : '--';
if ( $used > 85 ) {
$message = sprintf( __('Memory peak usage warning: %s %% used. (max: %dM, now: %dM)', CDBT), $used, $max, $peak );
$this->logger( $message );
}
if ( isset( $buffer ) && ! empty( $buffer ) )
echo $buffer;
}
/**
* Operating environment check for this plugin
*
* @since 2.0.0
*/
public function check_plugin_notices() {
$php_min_version = '5.4';
$extensions = [
// 'iconv',
'mbstring',
// 'id3'
];
$php_current_version = phpversion();
$this->errors = new \WP_Error();
if (version_compare( $php_min_version, $php_current_version, '>=' ))
$this->errors->add('php_version_error', sprintf(__('PHP version is %s. Required the up to %s PHP version for this Plugin.', $this->domain_name), $php_current_version, $php_min_version));
foreach ($extensions as $extension) {
if (!extension_loaded($extension))
$this->errors->add('lack_extension_error', sprintf(__('Please install the extension %s to run this plugin.', $this->domain_name), $extension));
}
$message = $this->errors->get_error_message();
if (!is_wp_error($this->errors) || empty($message)) {
$this->plugin_enabled = true;
return;
}
unset( $_GET['activate'] );
$this->logger( $message );
printf( '<div class="error"><p>%s</p><p>%s</p></div>', $message, sprintf(__('%s is deactivated.', $this->domain_name), __('Custom DataBase Tables', $this->domain_name)) );
$this->plugin_enabled = false;
deactivate_plugins( $this->plugin_main_file );
}
/**
* Fire an action at the time this plugin has activated.
*
* since 2.0.0
* revised 2.0.4
*/
public function plugin_activate() {
if (!current_user_can('activate_plugins') || $this->plugin_enabled)
return;
$plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
ob_start();
check_admin_referer( "activate-plugin_{$plugin}" );
$buffer = ob_get_contents();
ob_clean();
if ( ! wp_validate_boolean( $buffer ) )
$this->logger( $buffer );
$this->plugin_enabled = true;
//$role = get_role( 'administrator' );
//$role->add_cap( 'cdbt_operate_plugin', false );
// Add rewrite rules
$this->prepend_rewrite_rules();
flush_rewrite_rules();
$message = sprintf(__('Called function: %s; %s', CDBT), __FUNCTION__, __('Custom DataBase Tables plugin has activated.', CDBT));
$this->logger( $message );
// as you fun
}
/**
* Fire an action at the time this plugin was deactivation.
*
* since 2.0.0
*/
public function plugin_deactivation() {
if (!current_user_can('activate_plugins') || !$this->plugin_enabled)
return;
$this->plugin_enabled = false;
//$role = get_role( 'administrator' );
//$role->remove_cap( 'cdbt_operate_plugin' );
$message = sprintf(__('Called function: %s; %s', CDBT), __FUNCTION__, __('Custom DataBase Tables plugin has been deactivation.', CDBT));
$this->logger( $message );
// Delete rewrite rules
flush_rewrite_rules();
}
/**
* Add the extended rule for requesting api.
*
* @since 2.0.0
*
*/
protected function prepend_rewrite_rules() {
add_rewrite_rule( '^cdbt_api/([^/]*)/([^/]*)/([^/]*)?$', 'index.php?cdbt_api_key=$matches[1]&cdbt_table=$matches[2]&cdbt_api_request=$matches[3]', 'top' );
}
}
endif; // end of class_exists()
This diff is collapsed.
This diff is collapsed.
<?php
namespace CustomDataBaseTables\Lib;
if ( !defined( 'CDBT' ) ) exit;
/**
* Instance factory for CustomDataBaseTables plugin
*
* @since v2.0.0
*/
function factory( $type='set_global' ) {
if (is_admin()) {
$call_class = __NAMESPACE__ . '\CdbtAdmin';
} else {
$call_class = __NAMESPACE__ . '\CdbtFrontend';
}
if (isset($type) && $type != 'set_global' ) {
return $call_class::instance();
} else {
global $cdbt;
$cdbt = $call_class::instance();
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
namespace CustomDataBaseTables\Lib;
/**
* Trait for shortcode of "cdbt-submit"
*
* @since 2.1.31
*
*/
trait CdbtSubmit {
/**
* for [cdbt-submit] ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* This shortcode can executes any queries from front-end. (Currently it's deprecated; actually not working)
*
* @since 2.0.x
*
* @param array $attributes [require] - Array in shortcode's attributes
* @param string $content [optional] - Should be actually nothing
* @return string $html_content - The formatted content to the specific list
**/
public function submit_custom_query() {
extract(shortcode_atts(array(
'table' => '', // @attribute string [required] Specifies the table name you want to display the data.
'query' => '', // @attribute string [required] Specifies the sql query to execute after submitted.
'type' => 'button', // @attribute string [optional] Specifies the component type for submitting a query, whether it's a "button" or a "link".
'label' => 'Submit', // @attribute string [optional] Specifies the label name of button or link.
'onclick' => '', // @attribute string [optional] Specifies the custom onclick event (as function name of javascript) to fire when this component will be clicked.
'callback' => '', // @attribute string [optional] Specifies the custom callback function name of javascript to fire after the submitted process has completed.
'final' => '', // @attribute string [optional] Specifies the custom final event name (as function name of javascript) to fire at last after the ajax process.
'add_class' => '', // @attribute string [optional] Specifies a CSS class name for styling the element of listed data table. If there are multiple class, please separated by a single-byte space.
), $atts));
global $cdbt;
// verification for using shortcode
if (empty($table) || !$cdbt->check_table_exists($table))
return __('Specified table is not exist', CDBT_PLUGIN_SLUG);
if (empty($query))
return __('Specifying query is nothing', CDBT_PLUGIN_SLUG);
if (preg_match('/^(insert|update)\s(.*)$/iU', $query, $matches)) {
$query_action = strtolower($matches[1]);
if ($query_action == 'insert' && !cdbt_check_current_table_role('input', $table))
$err_permission = sprintf(__('You do not have a permission to %s this table', CDBT_PLUGIN_SLUG), __('input', CDBT_PLUGIN_SLUG));
if ($query_action == 'update' && !cdbt_check_current_table_role('edit', $table))
$err_permission = sprintf(__('You do not have a permission to %s this table', CDBT_PLUGIN_SLUG), __('edit', CDBT_PLUGIN_SLUG));
} else {
return __('Can not use your specified query', CDBT_PLUGIN_SLUG);
}
if (!isset($query_action))
return __('Specified query is invalid', CDBT_PLUGIN_SLUG);
// verification of sql query
if ($query_action == 'insert') {
if (preg_match('/into\s(.*)(\s|)\((.*)\)\s{1,}values(\s|)\((.*)\)\s{0,}(;|)$/iU', preg_replace('/(?:\n|\r|\r\n)/', '', trim($matches[2])), $parse_query)) {
$query_elms = array();
$query_elms['table_name'] = ($parse_query[1] == '@' || $parse_query[1] != $table) ? $table : trim($parse_query[1]);
$query_elms['columns'] = explode(',', trim($parse_query[3]));
$tmp_values = explode(',', trim($parse_query[5]));
$query_elms['values'] = array();
foreach ($query_elms['columns'] as $i => $col) {
$query_elms['values'][] = $tmp_values[$i];
}
$prepared_query = sprintf('INSERT INTO `%s` (%s) VALUES (%s);', $query_elms['table_name'], implode(',', $query_elms['columns']), implode(',', $query_elms['values']));
} else {
return __('Specified query is invalid', CDBT_PLUGIN_SLUG);
}
}
if ($query_action == 'update') {
if (preg_match('/(.*)\s{1,}set\s{1,}(.*)(where\s{1,}(.*)|)(;|)$/iU', preg_replace('/(?:\n|\r|\r\n)/', '', trim($matches[2])), $parse_query)) {
$query_elms = array();
$query_elms['table_name'] = ($parse_query[1] == '@' || $parse_query[1] != $table) ? $table : trim($parse_query[1]);
$tmp_sets = explode(',', trim($parse_query[2]));
$query_elms['columns'] = $query_elms['values'] = $query_elms['set_clause'] = array();
foreach ($tmp_sets as $val) {
list($str_col, $str_val) = explode('=', trim($val));
$query_elms['columns'][] = trim($str_col);
$query_elms['values'][] = trim($str_val);
$query_elms['set_clause'][] = trim($str_col) .' = '. trim($str_val);
}
$query_elms['where'] = trim($parse_query[4]);
if (empty($query_elms['where'])) {
$prepared_query = sprintf('UPDATE `%s` SET %s;', $query_elms['table_name'], implode(', ', $query_elms['set_clause']));
} else {
$prepared_query = sprintf('UPDATE `%s` SET %s WHERE %s;', $query_elms['table_name'], implode(', ', $query_elms['set_clause']), $query_elms['where']);
}
} else {
return __('Specified query is invalid', CDBT_PLUGIN_SLUG);
}
}
if (empty($prepared_query))
return __('Specified query is invalid', CDBT_PLUGIN_SLUG);
add_action('wp_footer', 'cdbt_create_javascript', 9999);
// create content for rendering at HTML
$hash_id = md5($prepared_query);
if (get_option(CDBT_PLUGIN_SLUG . '_stored_queries') !== false) {
$stored_queries = get_option(CDBT_PLUGIN_SLUG . '_stored_queries');
$stored_queries[$hash_id] = $prepared_query;
update_option(CDBT_PLUGIN_SLUG . '_stored_queries', $stored_queries);
} else {
add_option(CDBT_PLUGIN_SLUG . '_stored_queries', array($hash_id => $prepared_query), '', 'no');
}
$template_content = $type == 'link' ? '<a href="#" id="%s" class="%s" %s>%s</a>' : '<button type="button" id="%s" class="btn %s" %s>%s</button>';
$attributes = array();
if (isset($err_permission) && !empty($err_permission)) {
$content_id = "cdbt-submit";
$attributes[] = sprintf('title="%s"', $err_permission);
$attributes[] = 'disabled="disabled"';
} else {
$content_id = "cdbt-submit-{$hash_id}";
if (!empty($onclick))
$attributes[] = sprintf('data-onclick="%s"', $onclick);
if (!empty($callback))
$attributes[] = sprintf('data-callback="%s"', $callback);
if (!empty($final))
$attributes[] = sprintf('data-final="%s"', $final);
}
$add_class = ($type != 'link' && empty($add_class)) ? 'btn-primary' : $add_class;
$render_content = sprintf($template_content, $content_id, $add_class, implode(' ', $attributes), $label);
return $render_content;
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# Custom DataBase Tables システム構造
custom-database-tables/
├cdbt.php <-- プラグインメインファイル(エントリポイント)
├functions.php <-- ライブラリローダー
││
│└lib/
│ ├utils.php <-- 基底クラス「CdbtUtility」。共用ユーティリティ定義
│ ├core.php <-- プラグインコアクラス「CdbtCore」。「CdbtUtility」を継承する
│ ├config.php <-- プラグイン設定クラス「CdbtConfig」。「CdbtCore」を継承する
│ ├validate.php <-- 各種バリデーションクラス「CdbtValidator」。validate.php内部で「CommonValidator」を継承する独立したクラス
│ ├db.php <-- プラグイン用データベース制御クラス「CdbtDB」。「CdbtConfig」を継承する
│ ├─┬ajax.php <-- AJAX制御用トレイト
│ │ ├tmpl.php <-- テンプレート制御用トレイト。動的テンプレート読み込みクロージャあり
│ │ ├shortcodes.php <-- ショートコード制御用トレイト。
│ │ ├webapis.php <-- WEBAPI制御用トレイト。
│ │ └extras.php <-- プラグイン拡張用トレイト
│ ├admin.php <-- 管理画面用finalクラス「CdbtAdmin」。「CdbtDB」を継承する
│ ├main.php <-- フロントエンド用finalクラス「CdbtFrontend」。「CdbtDB」を継承する
│ └init.php <-- インスタンスファクトリ(ディスパッチャ)
├templates/
│ │
│ ├admin/
│ │ ├cdbt_management_console.php <-- 管理画面テンプレート: マネージメントコンソールTOP画面用
│ │ ├cdbt_tables.php <-- 管理画面テンプレート: テーブル管理画面用
│ │ ├cdbt_shortcodes.php <-- 管理画面テンプレート: ショートコード管理画面用
│ │ ├cdbt_apis.php <-- 管理画面テンプレート: WEBAPI管理画面用
│ │ └cdbt_options.php <-- 管理画面テンプレート: プラグインオプション画面用
│ ├components/
│ │ ├cdbt_forms.php <-- コンポーネントテンプレート: 各種フォーム用(by bootstrap and Fuel UX)
│ │ ├cdbt_modal.php <-- コンポーネントテンプレート: モーダルダイアログ用(by bootstrap)
│ │ ├cdbt_repeater.php <-- コンポーネントテンプレート: リピーター用(by Fuel UX)
│ │ └cdbt_wizard.php <-- コンポーネントテンプレート: ウィザード用(by Fuel UX)
│ └shortcodes/
│   ├cdbt_view.php <-- ショートコードテンプレート: なし
│   ├cdbt_entry.php <-- ショートコードテンプレート: なし
│   └cdbt_edit.php <-- ショートコードテンプレート: なし
├langs/
└sources/
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 15.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="213.987px" height="214px" viewBox="0 0 213.987 214" enable-background="new 0 0 213.987 214" xml:space="preserve">
<path fill-rule="evenodd" clip-rule="evenodd" fill="#555" d="M30.634,15.19c5.18,0,45.23,10.35,55.61,45.46
c1.15-3.74,2.01-32.8-15.28-40.86c-4.03-3.17-19.3-16.11-56.47-8.35c11.24,10.36,7.78,28.2,26.8,47.48
c10.66,11.22,27.66,9.21,34.86,10.93c6.05,4.61,6.34,13.81,6.34,17.84c0.31,4.54,0.99,8.75,1.93,12.63
c-34.54,1.98-60.93,12.63-60.93,25.47c0,14.25,32.46,25.8,72.5,25.8s72.5-11.55,72.5-25.8c0-14.24-32.46-25.79-72.5-25.79
c-1.07,0-2.14,0.01-3.21,0.02c-0.73-1.73-1.29-3.69-1.62-5.91c1.18-15.27,12.08-22.94,17.55-26.85c12.1-5.46,15.56,6.62,46.97,7.2
c14.98,0.57,34.86-12.66,45.81-9.79c-5.76-7.76-15.27-29.63-39.47-31.93c-3.46-0.29-19.6-4.32-43.51,13.52
c44.95-15.54,65.4,6.62,70.3,10.36c-27.08-13.24-51.86-14.96-77.22,1.44c-6.34,3.16-16.42,12.37-20.17,17.55
c-2.27,2.5-3.6,5.36-4.38,7.9c-0.32-0.77-0.59-1.65-0.8-2.72C85.664,79.92,81.054,35.04,30.634,15.19z M95.994,206
c39.71,0,71.97-11.36,72.5-25.44v-0.35v-54.06c-0.09,2.35-1.06,4.62-2.8,6.77v45.81v0.32c-0.51,12.96-31.52,23.42-69.7,23.42
c-38.17,0-69.18-10.46-69.69-23.42v-0.32v-45.8c-1.75-2.16-2.72-4.43-2.81-6.78v54.06v0.35C24.023,194.64,56.284,206,95.994,206z"
/>
</svg>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment