本文整理汇总了PHP中TablePress类的典型用法代码示例。如果您正苦于以下问题:PHP TablePress类的具体用法?PHP TablePress怎么用?PHP TablePress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TablePress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Init the Table model by instantiating a Post model and loading the list of tables option.
*
* @since 1.0.0
*/
public function __construct()
{
parent::__construct();
$this->model_post = TablePress::load_model('post');
$params = array('option_name' => 'tablepress_tables', 'default_value' => $this->default_tables);
$this->tables = TablePress::load_class('TablePress_WP_Option', 'class-wp_option.php', 'classes', $params);
}
示例2: __construct
/**
* Init Options Model by creating the object instances for the Plugin and User Options.
*
* @since 1.0.0
*/
public function __construct()
{
parent::__construct();
$params = array('option_name' => 'tablepress_plugin_options', 'default_value' => $this->default_plugin_options);
$this->plugin_options = TablePress::load_class('TablePress_WP_Option', 'class-wp_option.php', 'classes', $params);
$params = array('option_name' => 'tablepress_user_options', 'default_value' => $this->default_user_options);
$this->user_options = TablePress::load_class('TablePress_WP_User_Option', 'class-wp_user_option.php', 'classes', $params);
// Filter to map Meta capabilities to Primitive Capabilities.
add_filter('map_meta_cap', array($this, 'map_tablepress_meta_caps'), 10, 4);
}
示例3: setup
/**
* Set up the view with data and do things that are specific for this view.
*
* @param string $action Action for this view.
* @param array $data Data for this view.
*/
public function setup($action, array $data)
{
$params = array('option_name' => 'tablepress_stockflock_config', 'default_value' => array());
$this->stockflock_config = TablePress::load_class('TablePress_WP_Option', 'class-wp_option.php', 'classes', $params);
parent::setup($action, $data);
$this->add_header_message('<span>' . __('Please contact stockflock if you get any issue with this plugin.', 'tablepress') . '</span>', 'notice-info');
$this->process_action_messages(array('success_save' => __('Stockflock Changes saved successfully.', 'tablepress'), 'error_save' => __('Error: Stockflock Changes could not be saved.', 'tablepress')));
$this->add_meta_box('stockflock-options', __('Stockflock Options', 'tablepress'), array($this, 'stockflock_plugin_options'), 'normal');
$this->add_text_box('submit', array($this, 'textbox_submit_button'), 'submit');
}
示例4: __construct
/**
* Initialize all controllers, by loading Plugin and User Options, and performing an update check
*
* @since 1.0.0
*/
public function __construct()
{
$this->model_options = TablePress::load_model('options');
$this->model_table = TablePress::load_model('table');
// update check, in all controllers (frontend and admin), to make sure we always have up-to-date options
$this->plugin_update_check();
// should be done very early
// Admin Page Menu entry, needed for construction of plugin URLs
$this->parent_page = apply_filters('tablepress_admin_menu_parent_page', $this->model_options->get('admin_menu_parent_page'));
$this->is_top_level_page = in_array($this->parent_page, array('top', 'middle', 'bottom'), true);
}
示例5: postbox_no_tables
/**
* Print the content of the "No tables found" post meta box
*
* @since 1.0.0
*/
public function postbox_no_tables($data, $box)
{
$add_url = TablePress::url(array('action' => 'add'));
$import_url = TablePress::url(array('action' => 'import'));
?>
<p><?php
_e('No tables found.', 'tablepress');
?>
</p>
<p><?php
printf(__('You should <a href="%s">add</a> or <a href="%s">import</a> a table to get started!', 'tablepress'), $add_url, $import_url);
?>
</p>
<?php
}
示例6: minify_css
/**
* Minify a string of CSS code, that should have been sanitized/tidied before
*
* @since 1.1.0
*
* @uses CSSTidy
*
* @param string $css CSS code
* @return string Minified CSS code
*/
function minify_css($css)
{
$csstidy = TablePress::load_class('csstidy', 'class.csstidy.php', 'libraries/csstidy');
$csstidy->optimise = new csstidy_custom_sanitize($csstidy);
$csstidy->set_cfg('remove_bslash', false);
$csstidy->set_cfg('compress_colors', true);
$csstidy->set_cfg('compress_font-weight', true);
$csstidy->set_cfg('lowercase_s', false);
$csstidy->set_cfg('optimise_shorthands', 1);
$csstidy->set_cfg('remove_last_;', true);
$csstidy->set_cfg('case_properties', false);
$csstidy->set_cfg('sort_properties', false);
$csstidy->set_cfg('sort_selectors', false);
$csstidy->set_cfg('discard_invalid_selectors', false);
$csstidy->set_cfg('discard_invalid_properties', true);
$csstidy->set_cfg('merge_selectors', false);
$csstidy->set_cfg('css_level', 'CSS3.0');
$csstidy->set_cfg('preserve_css', false);
$csstidy->set_cfg('timestamp', false);
$csstidy->set_cfg('template', 'highest');
$csstidy->parse($css);
return $csstidy->print->plain();
}
示例7: print_nav_tab_menu
/**
* Render the navigation menu with links to the possible actions, highlighting the current one.
*
* @since 1.0.0
*/
protected function print_nav_tab_menu()
{
?>
<h1 id="tablepress-nav" class="nav-tab-wrapper">
<?php
echo '<span class="plugin-name">' . __('TablePress', 'tablepress') . '</span><span class="separator"></span>';
foreach ($this->data['view_actions'] as $action => $entry) {
// Special case: Add a separator before the group that starts with "Plugin Options", for some spacing.
if ('options' === $action) {
echo '<span class="separator"></span><span class="separator"></span>';
}
if ('' === $entry['nav_tab_title']) {
continue;
}
if (!current_user_can($entry['required_cap'])) {
continue;
}
$url = esc_url(TablePress::url(array('action' => $action)));
$active = $action === $this->action ? ' nav-tab-active' : '';
echo "<a class=\"nav-tab{$active}\" href=\"{$url}\">{$entry['nav_tab_title']}</a>";
}
?>
</h1>
<?php
}
示例8: ajax_action_preview_table
/**
* Return the live preview data of table that has non-saved changes.
*
* @since 1.0.0
*/
public function ajax_action_preview_table()
{
if (empty($_POST['tablepress']) || empty($_POST['tablepress']['id'])) {
wp_die('-1');
} else {
$preview_table = wp_unslash($_POST['tablepress']);
}
// Check if the submitted nonce matches the generated nonce we created earlier, dies -1 on failure.
TablePress::check_nonce('preview_table', $preview_table['id'], '_ajax_nonce', true);
// Ignore the request if the current user doesn't have sufficient permissions.
if (!current_user_can('tablepress_preview_table', $preview_table['id'])) {
wp_die('-1');
}
// Default response data.
$success = false;
do {
// to be able to "break;" (allows for better readable code)
// Load table, without table data, but with options and visibility settings.
$existing_table = TablePress::$model_table->load($preview_table['id'], false, true);
if (is_wp_error($existing_table)) {
// maybe somehow load a new table here? (TablePress::$model_table->get_table_template())?
break;
}
// Check and convert data that was transmitted as JSON.
if (empty($preview_table['data']) || empty($preview_table['options']) || empty($preview_table['visibility'])) {
break;
}
$preview_table['data'] = (array) json_decode($preview_table['data'], true);
$preview_table['options'] = (array) json_decode($preview_table['options'], true);
$preview_table['visibility'] = (array) json_decode($preview_table['visibility'], true);
// Check consistency of new table, and then merge with existing table.
$table = TablePress::$model_table->prepare_table($existing_table, $preview_table, true, true);
if (is_wp_error($table)) {
break;
}
// DataTables Custom Commands can only be edit by trusted users.
if (!current_user_can('unfiltered_html')) {
$table['options']['datatables_custom_commands'] = $existing_table['options']['datatables_custom_commands'];
}
// If the ID has changed, and the new ID is valid, render with the new ID (important e.g. for CSS classes/HTML ID).
if ($table['id'] !== $table['new_id'] && 0 === preg_match('/[^a-zA-Z0-9_-]/', $table['new_id'])) {
$table['id'] = $table['new_id'];
}
// Sanitize all table data to remove unsafe HTML from the preview output.
$table = TablePress::$model_table->sanitize($table);
// At this point, the table data is valid and sanitized and can be rendered.
$success = true;
} while (false);
// Do-while-loop through this exactly once, to be able to "break;" early.
// Initialize i18n support, load plugin's textdomain, to retrieve correct translations for the description of the preview.
load_plugin_textdomain('tablepress', false, dirname(TABLEPRESS_BASENAME) . '/i18n');
if ($success) {
// Create a render class instance.
$_render = TablePress::load_class('TablePress_Render', 'class-render.php', 'classes');
// Merge desired options with default render options (see TablePress_Controller_Frontend::shortcode_table()).
$default_render_options = $_render->get_default_render_options();
/** This filter is documented in controllers/controller-frontend.php */
$default_render_options = apply_filters('tablepress_shortcode_table_default_shortcode_atts', $default_render_options);
$render_options = shortcode_atts($default_render_options, $table['options']);
/** This filter is documented in controllers/controller-frontend.php */
$render_options = apply_filters('tablepress_shortcode_table_shortcode_atts', $render_options);
$_render->set_input($table, $render_options);
$head_html = $_render->get_preview_css();
$custom_css = TablePress::$model_options->get('custom_css');
if (!empty($custom_css)) {
$head_html .= "<style type=\"text/css\">\n{$custom_css}\n</style>\n";
}
$body_html = '<div id="tablepress-page"><p>' . __('This is a preview of your table.', 'tablepress') . ' ' . __('Because of CSS styling in your theme, the table might look different on your page!', 'tablepress') . ' ' . __('The features of the DataTables JavaScript library are also not available or visible in this preview!', 'tablepress') . '<br />' . sprintf(__('To insert the table into a page, post, or text widget, copy the Shortcode %s and paste it into the editor.', 'tablepress'), '<input type="text" class="table-shortcode table-shortcode-inline" value="' . esc_attr('[' . TablePress::$shortcode . " id={$table['id']} /]") . '" readonly="readonly" />') . '</p>' . $_render->get_output() . '</div>';
} else {
$head_html = '';
$body_html = __('The preview could not be loaded.', 'tablepress');
}
// Generate the response.
$response = array('success' => $success, 'head_html' => $head_html, 'body_html' => $body_html);
// Buffer all outputs, to prevent errors/warnings being printed that make the JSON invalid.
$output_buffer = ob_get_clean();
if (!empty($output_buffer)) {
$response['output_buffer'] = $output_buffer;
}
// Send the response.
wp_send_json($response);
}
示例9: shortcode_table_info
/**
* Handle Shortcode [table-info id=<ID> field=<name> /] in the_content()
*
* @since 1.0.0
*
* @param array $atts list of attributes that where included in the Shortcode
* @return string Text that replaces the Shortcode (error message or asked-for information)
*/
public function shortcode_table_info($shortcode_atts)
{
// parse Shortcode attributes, only allow those that are specified
$default_shortcode_atts = array('id' => 0, 'field' => '', 'format' => '');
$default_shortcode_atts = apply_filters('tablepress_shortcode_table_info_default_shortcode_atts', $default_shortcode_atts);
$shortcode_atts = shortcode_atts($default_shortcode_atts, $shortcode_atts);
$shortcode_atts = apply_filters('tablepress_shortcode_table_info_shortcode_atts', $shortcode_atts);
// allow a filter to determine behavior of this function, by overwriting its behavior, just need to return something other than false
$overwrite = apply_filters('tablepress_shortcode_table_info_overwrite', false, $shortcode_atts);
if ($overwrite) {
return $overwrite;
}
// check, if a table with the given ID exists
$table_id = preg_replace('/[^a-zA-Z0-9_-]/', '', $shortcode_atts['id']);
if (!$this->model_table->table_exists($table_id)) {
$message = "[table “{$table_id}” not found /]<br />\n";
$message = apply_filters('tablepress_table_not_found_message', $message, $table_id);
return $message;
}
// load the table
$table = $this->model_table->load($table_id);
if (false === $table) {
$message = "[table “{$table_id}” could not be loaded /]<br />\n";
$message = apply_filters('tablepress_table_load_error_message', $message, $table_id);
return $message;
}
$field = preg_replace('/[^a-z_]/', '', strtolower($shortcode_atts['field']));
$format = preg_replace('/[^a-z]/', '', strtolower($shortcode_atts['format']));
// generate output, depending on what information (field) was asked for
switch ($field) {
case 'name':
case 'description':
$output = $table[$field];
break;
case 'last_modified':
switch ($format) {
case 'raw':
$output = $table['last_modified'];
break 2;
case 'mysql':
$output = TablePress::format_datetime($table['last_modified'], 'mysql', ' ');
break 2;
case 'human':
$modified_timestamp = strtotime($table['last_modified']);
$current_timestamp = current_time('timestamp');
$time_diff = $current_timestamp - $modified_timestamp;
if ($time_diff >= 0 && $time_diff < DAY_IN_SECONDS) {
// time difference is only shown up to one day
$output = sprintf(__('%s ago', 'tablepress'), human_time_diff($modified_timestamp, $current_timestamp));
} else {
$output = TablePress::format_datetime($table['last_modified'], 'mysql', '<br />');
}
break 2;
default:
$output = TablePress::format_datetime($table['last_modified'], 'mysql', ' ');
}
break;
case 'last_editor':
$output = TablePress::get_user_display_name($table['options']['last_editor']);
break;
case 'author':
$output = TablePress::get_user_display_name($table['author']);
break;
default:
$output = "[table-info field “{$field}” not found in table “{$table_id}” /]<br />\n";
$output = apply_filters('tablepress_table_info_not_found_message', $output, $table, $field, $format);
}
$output = apply_filters('tablepress_shortcode_table_info_output', $output, $table, $shortcode_atts);
return $output;
}
示例10: test_url_toplevel
/**
* Test that the screen URLs for toplevel admin menu entries are correct.
*
* @since 1.1.0
*/
public function test_url_toplevel()
{
TablePress::$controller->is_top_level_page = true;
TablePress::$controller->parent_page = 'middle';
$this->assertSame('http://example.org/wp-admin/admin.php?page=tablepress', TablePress::url());
$this->assertSame('http://example.org/wp-admin/admin.php?page=tablepress', TablePress::url(array(), false));
}
示例11: handle_post_action_stockflock
/**
* Save changes on the Stockflock screen.
*
*/
public function handle_post_action_stockflock()
{
if (!isset($_POST['stockflock'])) {
return;
}
TablePress::check_nonce('stockflock');
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
if (empty($_POST['stockflock']) || !is_array($_POST['stockflock'])) {
TablePress::redirect(array('action' => 'stockflock', 'message' => 'error_save'));
} else {
$stockflock = stripslashes_deep($_POST['stockflock']);
}
$params = array('option_name' => 'tablepress_stockflock_config', 'default_value' => array());
$stockflock_config = TablePress::load_class('TablePress_WP_Option', 'class-wp_option.php', 'classes', $params);
//trim and restrict array length to be not more than 20
$raw_companies = explode(',', $stockflock['companies']);
$valid_companies = array_slice(array_map('trim', $raw_companies), 0, $this->company_limit);
$stockflock['companies'] = strtoupper(implode(',', $valid_companies));
//give default value to data_points
$data_point_list = ['short_name', 'price_value', 'industry_name', 'dividend_yield', 'earning_value', 'dividend_per_share', 'book_value', 'debt_assets', 'net_asset_value', 'gearing_ratio', 'property_yield_ratio'];
if (is_array($stockflock['data_points'])) {
foreach ($data_point_list as $key => $value) {
if (!array_key_exists($value, $stockflock['data_points'])) {
$stockflock['data_points'][$value] = "false";
}
}
}
//store to wp_options
$stockflock_config->update($stockflock);
TablePress::redirect(array('action' => 'stockflock', 'message' => 'success_save'));
}
示例12: textbox_corrupted_table
/**
* Print a notification about a corrupted table
*
* @since 1.4.0
*/
public function textbox_corrupted_table($data, $box)
{
?>
<div class="error">
<p><strong><?php
_e('Attention: Unfortunately, an error occured.', 'tablepress');
?>
</strong></p>
<p>
<?php
printf(__('The internal data of table “%1$s” (ID %2$s) is corrupted.', 'tablepress'), esc_html($data['table']['name']), esc_html($data['table']['id']));
echo ' ';
printf(__('The following error was registered: <code>%s</code>.', 'tablepress'), esc_html($data['table']['json_error']));
?>
</p>
<p>
<?php
_e('Because of this error, the table can not be edited at this time, to prevent possible further data loss.', 'tablepress');
echo ' ';
printf(__('Please see the <a href="%s">TablePress FAQ page</a> for further instructions.', 'tablepress'), 'http://tablepress.org/faq/corrupted-tables/');
?>
</p>
<p>
<?php
echo '<a href="' . TablePress::url(array('action' => 'list')) . '" class="button">' . __('Back to the List of Tables', 'tablepress') . '</a>';
?>
</p>
</div>
<?php
}
示例13: shortcode_table_info
/**
* Handle Shortcode [table-info id=<ID> field=<name> /] in the_content()
*
* @since 1.0.0
*
* @param array $shortcode_atts List of attributes that where included in the Shortcode
* @return string Text that replaces the Shortcode (error message or asked-for information)
*/
public function shortcode_table_info($shortcode_atts)
{
// For empty Shortcodes like [table-info] or [table-info /], an empty string is passed, see Core #26927
$shortcode_atts = (array) $shortcode_atts;
// parse Shortcode attributes, only allow those that are specified
$default_shortcode_atts = array('id' => '', 'field' => '', 'format' => '');
/**
* Filter the available/default attributes for the [table-info] Shortcode.
*
* @since 1.0.0
*
* @param array $default_shortcode_atts The [table-info] Shortcode default attributes.
*/
$default_shortcode_atts = apply_filters('tablepress_shortcode_table_info_default_shortcode_atts', $default_shortcode_atts);
$shortcode_atts = shortcode_atts($default_shortcode_atts, $shortcode_atts);
// Optional third argument left out on purpose. Use filter in the next line instead.
/**
* Filter the attributes that were passed to the [table-info] Shortcode.
*
* @since 1.0.0
*
* @param array $shortcode_atts The attributes passed to the [table-info] Shortcode.
*/
$shortcode_atts = apply_filters('tablepress_shortcode_table_info_shortcode_atts', $shortcode_atts);
/**
* Filter whether the output of the [table-info] Shortcode is overwritten/short-circuited.
*
* @since 1.0.0
*
* @param bool|string $overwrite Whether the [table-info] output is overwritten. Return false for the regular content, and a string to overwrite the output.
* @param array $shortcode_atts The attributes passed to the [table-info] Shortcode.
*/
$overwrite = apply_filters('tablepress_shortcode_table_info_overwrite', false, $shortcode_atts);
if ($overwrite) {
return $overwrite;
}
// check, if a table with the given ID exists
$table_id = preg_replace('/[^a-zA-Z0-9_-]/', '', $shortcode_atts['id']);
if (!TablePress::$model_table->table_exists($table_id)) {
$message = "[table “{$table_id}” not found /]<br />\n";
/** This filter is documented in controllers/controller-frontend.php */
$message = apply_filters('tablepress_table_not_found_message', $message, $table_id);
return $message;
}
// load the table
$table = TablePress::$model_table->load($table_id, true, true);
// Load table, with table data, options, and visibility settings
if (is_wp_error($table)) {
$message = "[table “{$table_id}” could not be loaded /]<br />\n";
/** This filter is documented in controllers/controller-frontend.php */
$message = apply_filters('tablepress_table_load_error_message', $message, $table_id, $table);
return $message;
}
$field = preg_replace('/[^a-z_]/', '', strtolower($shortcode_atts['field']));
$format = preg_replace('/[^a-z]/', '', strtolower($shortcode_atts['format']));
// generate output, depending on what information (field) was asked for
switch ($field) {
case 'name':
case 'description':
$output = $table[$field];
break;
case 'last_modified':
switch ($format) {
case 'raw':
$output = $table['last_modified'];
break 2;
case 'human':
$modified_timestamp = strtotime($table['last_modified']);
$current_timestamp = current_time('timestamp');
$time_diff = $current_timestamp - $modified_timestamp;
if ($time_diff >= 0 && $time_diff < DAY_IN_SECONDS) {
// time difference is only shown up to one day
$output = sprintf(__('%s ago', 'tablepress'), human_time_diff($modified_timestamp, $current_timestamp));
} else {
$output = TablePress::format_datetime($table['last_modified'], 'mysql', '<br />');
}
break 2;
case 'mysql':
default:
$output = TablePress::format_datetime($table['last_modified'], 'mysql', ' ');
break 2;
}
break;
case 'last_editor':
$output = TablePress::get_user_display_name($table['options']['last_editor']);
break;
case 'author':
$output = TablePress::get_user_display_name($table['author']);
break;
case 'number_rows':
$output = count($table['data']);
if ('raw' != $format) {
//.........这里部分代码省略.........
示例14: load_tablepress_in_the_admin
function load_tablepress_in_the_admin()
{
if (is_admin() && defined('DOING_AJAX') && DOING_AJAX) {
TablePress::load_controller('frontend');
// работает на дефолтной теме
// TablePress::$controller = TablePress::load_controller( 'admin_ajax' );
}
}
示例15: save_custom_css_to_file
/**
* Save "Custom CSS" to a file, or return HTML for the credentials form
*
* @since 1.0.0
*
* @return string (if necessary) HTML for the credentials form for the WP_Filesystem API
*/
public function save_custom_css_to_file()
{
// Set current screen to get Screen Icon to have a custom HTML ID, so that we can hide it with CSS
set_current_screen('tablepress_options_invisible');
// Start capturing the output, to get HTML of the credentials form (if needed)
ob_start();
$url = '';
// same page
$credentials = request_filesystem_credentials($url, '', false, false, null);
// do we have credentials already? (Otherwise the form will have been rendered already.)
if (false === $credentials) {
$form_data = ob_get_contents();
ob_end_clean();
$form_data = str_replace('name="upgrade" id="upgrade" class="button"', 'name="upgrade" id="upgrade" class="button button-primary button-large"', $form_data);
return $form_data;
}
// we have received credentials, but don't know if they are valid yet
if (!WP_Filesystem($credentials)) {
// credentials failed, so ask again (with $error flag true)
request_filesystem_credentials($url, '', true, false, null);
$form_data = ob_get_contents();
ob_end_clean();
$form_data = str_replace('name="upgrade" id="upgrade" class="button"', 'name="upgrade" id="upgrade" class="button button-primary button-large"', $form_data);
return $form_data;
}
// we have valid access to the filesystem now -> try to save the file
$filename = WP_CONTENT_DIR . '/tablepress-custom.css';
$filename = apply_filters('tablepress_custom_css_file_name', $filename);
$filename_min = WP_CONTENT_DIR . '/tablepress-custom.min.css';
$filename_min = apply_filters('tablepress_custom_css_minified_file_name', $filename_min);
// Check if file name is valid (0 means yes)
if (0 !== validate_file($filename) || 0 !== validate_file($filename_min)) {
TablePress::redirect(array('action' => 'options', 'message' => 'success_save_error_custom_css'));
}
global $wp_filesystem;
// WP_CONTENT_DIR and (FTP-)Content-Dir can be different (e.g. if FTP working dir is /)
// We need to account for that by replacing the path difference in the filename
$path_difference = str_replace($wp_filesystem->wp_content_dir(), '', trailingslashit(WP_CONTENT_DIR));
if ('' != $path_difference) {
$filename = str_replace($path_difference, '', $filename);
$filename_min = str_replace($path_difference, '', $filename_min);
}
$custom_css = $this->get('custom_css');
$custom_css_minified = $this->get('custom_css_minified');
$result = $wp_filesystem->put_contents($filename, $custom_css, FS_CHMOD_FILE);
$result_min = $wp_filesystem->put_contents($filename_min, $custom_css_minified, FS_CHMOD_FILE);
if (!$result || !$result_min) {
TablePress::redirect(array('action' => 'options', 'message' => 'success_save_error_custom_css'));
}
// at this point, saving was successful, so enable the checkbox again
// (if it was not enabled before, we would never have tried to save)
// and also increase the "Custom CSS" version number (for cache busting)
$this->update(array('use_custom_css_file' => true, 'custom_css_version' => $this->get('custom_css_version') + 1));
TablePress::redirect(array('action' => 'options', 'message' => 'success_save'));
}