first
This commit is contained in:
563
wp-content/plugins/wp-pagenavi/scb/AdminPage.php
Normal file
563
wp-content/plugins/wp-pagenavi/scb/AdminPage.php
Normal file
@ -0,0 +1,563 @@
|
||||
<?php
|
||||
/**
|
||||
* Administration page base class.
|
||||
*/
|
||||
abstract class scbAdminPage {
|
||||
/** Page args
|
||||
* $page_title string (mandatory)
|
||||
* $parent (string) (default: options-general.php)
|
||||
* $capability (string) (default: 'manage_options')
|
||||
* $menu_title (string) (default: $page_title)
|
||||
* $submenu_title (string) (default: $menu_title)
|
||||
* $page_slug (string) (default: sanitized $page_title)
|
||||
* $toplevel (string) If not empty, will create a new top level menu (for expected values see http://codex.wordpress.org/Administration_Menus#Using_add_submenu_page)
|
||||
* - $icon_url (string) URL to an icon for the top level menu
|
||||
* - $position (int) Position of the toplevel menu (caution!)
|
||||
* $nonce string (default: $page_slug)
|
||||
* $action_link (string|bool) Text of the action link on the Plugins page (default: 'Settings')
|
||||
* $admin_action_priority int The priority that the admin_menu action should be executed at (default: 10)
|
||||
*/
|
||||
protected $args;
|
||||
|
||||
// URL to the current plugin directory.
|
||||
// Useful for adding css and js files
|
||||
protected $plugin_url;
|
||||
|
||||
// Created at page init
|
||||
protected $pagehook;
|
||||
|
||||
// scbOptions object holder
|
||||
// Normally, it's used for storing formdata
|
||||
protected $options;
|
||||
protected $option_name;
|
||||
|
||||
// l10n
|
||||
protected $textdomain;
|
||||
|
||||
protected $nonce;
|
||||
protected $file;
|
||||
|
||||
|
||||
// ____________REGISTRATION COMPONENT____________
|
||||
|
||||
|
||||
private static $registered = array();
|
||||
|
||||
/**
|
||||
* Registers class of page.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $file
|
||||
* @param object $options (optional) A scbOptions object.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function register( $class, $file, $options = null ) {
|
||||
if ( isset( self::$registered[ $class ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
self::$registered[ $class ] = array( $file, $options );
|
||||
|
||||
add_action( '_admin_menu', array( __CLASS__, '_pages_init' ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces class of page.
|
||||
*
|
||||
* @param string $old_class
|
||||
* @param string $new_class
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function replace( $old_class, $new_class ) {
|
||||
if ( ! isset( self::$registered[ $old_class ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
self::$registered[ $new_class ] = self::$registered[ $old_class ];
|
||||
unset( self::$registered[ $old_class ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes class of page.
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function remove( $class ) {
|
||||
if ( ! isset( self::$registered[ $class ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unset( self::$registered[ $class ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates classes of pages.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function _pages_init() {
|
||||
foreach ( self::$registered as $class => $args ) {
|
||||
new $class( $args[0], $args[1] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ____________MAIN METHODS____________
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string|bool $file (optional)
|
||||
* @param object $options (optional) A scbOptions object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $file = false, $options = null ) {
|
||||
if ( is_a( $options, 'scbOptions' ) ) {
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
$this->setup();
|
||||
$this->check_args();
|
||||
|
||||
if ( isset( $this->option_name ) ) {
|
||||
add_action( 'admin_init', array( $this, 'option_init' ) );
|
||||
}
|
||||
|
||||
add_action( 'admin_menu', array( $this, 'page_init' ), $this->args['admin_action_priority'] );
|
||||
|
||||
if ( $file ) {
|
||||
$this->file = $file;
|
||||
$this->plugin_url = plugin_dir_url( $file );
|
||||
|
||||
if ( $this->args['action_link'] ) {
|
||||
add_filter( 'plugin_action_links_' . plugin_basename( $file ), array( $this, '_action_link' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is where all the page args can be set.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setup() { }
|
||||
|
||||
/**
|
||||
* Called when the page is loaded, but before any rendering.
|
||||
* Useful for calling $screen->add_help_tab() etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_loaded() {
|
||||
$this->form_handler();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is where the css and js go.
|
||||
* Both wp_enqueue_*() and inline code can be added.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_head() { }
|
||||
|
||||
/**
|
||||
* This is where the contextual help goes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function page_help() { }
|
||||
|
||||
/**
|
||||
* A generic page header.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function page_header() {
|
||||
echo "<div class='wrap'>\n";
|
||||
echo html( 'h2', $this->args['page_title'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* This is where the page content goes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function page_content();
|
||||
|
||||
/**
|
||||
* A generic page footer.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function page_footer() {
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* This is where the form data should be validated.
|
||||
*
|
||||
* @param array $new_data
|
||||
* @param array $old_data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function validate( $new_data, $old_data ) {
|
||||
return $new_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually handle option saving ( use Settings API instead ).
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function form_handler() {
|
||||
if ( empty( $_POST['submit'] ) && empty( $_POST['action'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
check_admin_referer( $this->nonce );
|
||||
|
||||
if ( ! isset( $this->options ) ) {
|
||||
trigger_error( 'options handler not set', E_USER_WARNING );
|
||||
return false;
|
||||
}
|
||||
|
||||
$new_data = wp_array_slice_assoc( $_POST, array_keys( $this->options->get_defaults() ) );
|
||||
|
||||
$new_data = stripslashes_deep( $new_data );
|
||||
|
||||
$new_data = $this->validate( $new_data, $this->options->get() );
|
||||
|
||||
$this->options->set( $new_data );
|
||||
|
||||
add_action( 'admin_notices', array( $this, 'admin_msg' ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually generate a standard admin notice ( use Settings API instead ).
|
||||
*
|
||||
* @param string $msg (optional)
|
||||
* @param string $class (optional)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function admin_msg( $msg = '', $class = 'updated' ) {
|
||||
if ( empty( $msg ) ) {
|
||||
$msg = __( 'Settings <strong>saved</strong>.', $this->textdomain );
|
||||
}
|
||||
|
||||
echo scb_admin_notice( $msg, $class );
|
||||
}
|
||||
|
||||
|
||||
// ____________UTILITIES____________
|
||||
|
||||
|
||||
/**
|
||||
* Generates a form submit button.
|
||||
*
|
||||
* @param string|array $value (optional) Button text or array of arguments.
|
||||
* @param string $action (optional)
|
||||
* @param string $class (optional)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function submit_button( $value = '', $action = 'submit', $class = 'button' ) {
|
||||
|
||||
$args = is_array( $value ) ? $value : compact( 'value', 'action', 'class' );
|
||||
$args = wp_parse_args( $args, array(
|
||||
'value' => null,
|
||||
'action' => $action,
|
||||
'class' => $class,
|
||||
) );
|
||||
|
||||
return get_submit_button( $args['value'], $args['class'], $args['action'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Mimics scbForms::form_wrap()
|
||||
*
|
||||
* $this->form_wrap( $content ); // generates a form with a default submit button
|
||||
*
|
||||
* $this->form_wrap( $content, false ); // generates a form with no submit button
|
||||
*
|
||||
* // the second argument is sent to submit_button()
|
||||
* $this->form_wrap( $content, array(
|
||||
* 'text' => 'Save changes',
|
||||
* 'name' => 'action',
|
||||
* ) );
|
||||
*
|
||||
* @see scbForms::form_wrap()
|
||||
*
|
||||
* @param string $content
|
||||
* @param boolean|string|array $submit_button (optional)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function form_wrap( $content, $submit_button = true ) {
|
||||
if ( is_array( $submit_button ) ) {
|
||||
$content .= $this->submit_button( $submit_button );
|
||||
} else if ( true === $submit_button ) {
|
||||
$content .= $this->submit_button();
|
||||
} else if ( false !== strpos( $submit_button, '<input' ) ) {
|
||||
$content .= $submit_button;
|
||||
} else if ( false !== strpos( $submit_button, '<button' ) ) {
|
||||
$content .= $submit_button;
|
||||
} else if ( false !== $submit_button ) {
|
||||
$button_args = array_slice( func_get_args(), 1 );
|
||||
$content .= call_user_func_array( array( $this, 'submit_button' ), $button_args );
|
||||
}
|
||||
|
||||
return scbForms::form_wrap( $content, $this->nonce );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a table wrapped in a form.
|
||||
*
|
||||
* @param array $rows
|
||||
* @param array|boolean $formdata (optional)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function form_table( $rows, $formdata = false ) {
|
||||
$output = '';
|
||||
foreach ( $rows as $row ) {
|
||||
$output .= $this->table_row( $row, $formdata );
|
||||
}
|
||||
|
||||
$output = $this->form_table_wrap( $output );
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the given content in a <form><table>
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function form_table_wrap( $content ) {
|
||||
$output = $this->table_wrap( $content );
|
||||
$output = $this->form_wrap( $output );
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a form table.
|
||||
*
|
||||
* @param array $rows
|
||||
* @param array|boolean $formdata (optional)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function table( $rows, $formdata = false ) {
|
||||
$output = '';
|
||||
foreach ( $rows as $row ) {
|
||||
$output .= $this->table_row( $row, $formdata );
|
||||
}
|
||||
|
||||
$output = $this->table_wrap( $output );
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a table row.
|
||||
*
|
||||
* @param array $args
|
||||
* @param array|boolean $formdata (optional)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function table_row( $args, $formdata = false ) {
|
||||
return $this->row_wrap( $args['title'], $this->input( $args, $formdata ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Mimic scbForms inheritance.
|
||||
*
|
||||
* @see scbForms
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call( $method, $args ) {
|
||||
if ( in_array( $method, array( 'input', 'form' ) ) ) {
|
||||
if ( empty( $args[1] ) && isset( $this->options ) ) {
|
||||
$args[1] = $this->options->get();
|
||||
}
|
||||
|
||||
if ( 'form' == $method ) {
|
||||
$args[2] = $this->nonce;
|
||||
}
|
||||
}
|
||||
|
||||
return call_user_func_array( array( 'scbForms', $method ), $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a string in a <script> tag.
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function js_wrap( $string ) {
|
||||
return html( "script type='text/javascript'", $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a string in a <style> tag.
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function css_wrap( $string ) {
|
||||
return html( "style type='text/css'", $string );
|
||||
}
|
||||
|
||||
|
||||
// ____________INTERNAL METHODS____________
|
||||
|
||||
|
||||
/**
|
||||
* Registers a page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_init() {
|
||||
|
||||
if ( ! $this->args['toplevel'] ) {
|
||||
$this->pagehook = add_submenu_page(
|
||||
$this->args['parent'],
|
||||
$this->args['page_title'],
|
||||
$this->args['menu_title'],
|
||||
$this->args['capability'],
|
||||
$this->args['page_slug'],
|
||||
array( $this, '_page_content_hook' )
|
||||
);
|
||||
} else {
|
||||
$func = 'add_' . $this->args['toplevel'] . '_page';
|
||||
$this->pagehook = $func(
|
||||
$this->args['page_title'],
|
||||
$this->args['menu_title'],
|
||||
$this->args['capability'],
|
||||
$this->args['page_slug'],
|
||||
null,
|
||||
$this->args['icon_url'],
|
||||
$this->args['position']
|
||||
);
|
||||
|
||||
add_submenu_page(
|
||||
$this->args['page_slug'],
|
||||
$this->args['page_title'],
|
||||
$this->args['submenu_title'],
|
||||
$this->args['capability'],
|
||||
$this->args['page_slug'],
|
||||
array( $this, '_page_content_hook' )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! $this->pagehook ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action( 'load-' . $this->pagehook, array( $this, 'page_loaded' ) );
|
||||
|
||||
add_action( 'admin_print_styles-' . $this->pagehook, array( $this, 'page_head' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a option.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function option_init() {
|
||||
register_setting( $this->option_name, $this->option_name, array( $this, 'validate' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks page args.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function check_args() {
|
||||
if ( empty( $this->args['page_title'] ) ) {
|
||||
trigger_error( 'Page title cannot be empty', E_USER_WARNING );
|
||||
}
|
||||
|
||||
$this->args = wp_parse_args( $this->args, array(
|
||||
'toplevel' => '',
|
||||
'position' => null,
|
||||
'icon_url' => '',
|
||||
'parent' => 'options-general.php',
|
||||
'capability' => 'manage_options',
|
||||
'menu_title' => $this->args['page_title'],
|
||||
'page_slug' => '',
|
||||
'nonce' => '',
|
||||
'action_link' => __( 'Settings', $this->textdomain ),
|
||||
'admin_action_priority' => 10,
|
||||
) );
|
||||
|
||||
if ( empty( $this->args['submenu_title'] ) ) {
|
||||
$this->args['submenu_title'] = $this->args['menu_title'];
|
||||
}
|
||||
|
||||
if ( empty( $this->args['page_slug'] ) ) {
|
||||
$this->args['page_slug'] = sanitize_title_with_dashes( $this->args['menu_title'] );
|
||||
}
|
||||
|
||||
if ( empty( $this->args['nonce'] ) ) {
|
||||
$this->nonce = $this->args['page_slug'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays page content.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function _page_content_hook() {
|
||||
$this->page_header();
|
||||
$this->page_content();
|
||||
$this->page_footer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an action link.
|
||||
*
|
||||
* @param array $links
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _action_link( $links ) {
|
||||
if ( ! is_array( $links ) ) {
|
||||
$links = array();
|
||||
}
|
||||
|
||||
$url = add_query_arg( 'page', $this->args['page_slug'], admin_url( $this->args['parent'] ) );
|
||||
|
||||
$links[] = html_link( $url, $this->args['action_link'] );
|
||||
|
||||
return $links;
|
||||
}
|
||||
}
|
341
wp-content/plugins/wp-pagenavi/scb/BoxesPage.php
Normal file
341
wp-content/plugins/wp-pagenavi/scb/BoxesPage.php
Normal file
@ -0,0 +1,341 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin screen with metaboxes base class.
|
||||
*/
|
||||
abstract class scbBoxesPage extends scbAdminPage {
|
||||
/*
|
||||
A box definition looks like this:
|
||||
array( $slug, $title, $column );
|
||||
|
||||
Available columns: normal, side, column3, column4
|
||||
*/
|
||||
protected $boxes = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string|bool $file (optional)
|
||||
* @param object $options (optional) A scbOptions object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $file = false, $options = null ) {
|
||||
parent::__construct( $file, $options );
|
||||
|
||||
scbUtil::add_uninstall_hook( $this->file, array( $this, 'uninstall' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function page_init() {
|
||||
if ( ! isset( $this->args['columns'] ) ) {
|
||||
$this->args['columns'] = 2;
|
||||
}
|
||||
|
||||
parent::page_init();
|
||||
|
||||
add_action( 'load-' . $this->pagehook, array( $this, 'boxes_init' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints default CSS styles.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function default_css() {
|
||||
?>
|
||||
<style type="text/css">
|
||||
.postbox-container + .postbox-container {
|
||||
margin-left: 18px;
|
||||
}
|
||||
.postbox-container {
|
||||
padding-right: 0;
|
||||
}
|
||||
.inside {
|
||||
clear: both;
|
||||
overflow: hidden;
|
||||
}
|
||||
.inside table {
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
.inside table td {
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
.inside table .regular-text {
|
||||
width: 100% !important;
|
||||
}
|
||||
.inside .form-table th {
|
||||
width: 30%;
|
||||
max-width: 200px;
|
||||
padding: 10px 0 !important;
|
||||
}
|
||||
.inside .widefat .check-column {
|
||||
padding-bottom: 7px !important;
|
||||
}
|
||||
.inside p,
|
||||
.inside table {
|
||||
margin: 0 0 10px !important;
|
||||
}
|
||||
.inside p.submit {
|
||||
float: left !important;
|
||||
padding: 0 !important;
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
.meta-box-sortables {
|
||||
min-height: 100px;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays page content.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function page_content() {
|
||||
$this->default_css();
|
||||
|
||||
global $screen_layout_columns;
|
||||
|
||||
if ( isset( $screen_layout_columns ) ) {
|
||||
$hide2 = $hide3 = $hide4 = '';
|
||||
switch ( $screen_layout_columns ) {
|
||||
case 4:
|
||||
if ( ! isset( $this->args['column_widths'] ) ) {
|
||||
$this->args['column_widths'] = array( 24.5, 24.5, 24.5, 24.5 );
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if ( ! isset( $this->args['column_widths'] ) ) {
|
||||
$this->args['column_widths'] = array( 32.67, 32.67, 32.67 );
|
||||
}
|
||||
$hide4 = 'display:none;';
|
||||
break;
|
||||
case 2:
|
||||
if ( ! isset( $this->args['column_widths'] ) ) {
|
||||
$this->args['column_widths'] = array( 49, 49 );
|
||||
}
|
||||
$hide3 = $hide4 = 'display:none;';
|
||||
break;
|
||||
default:
|
||||
if ( ! isset( $this->args['column_widths'] ) ) {
|
||||
$this->args['column_widths'] = array( 98 );
|
||||
}
|
||||
$hide2 = $hide3 = $hide4 = 'display:none;';
|
||||
}
|
||||
|
||||
$this->args['column_widths'] = array_pad( $this->args['column_widths'], 4, 0 );
|
||||
}
|
||||
?>
|
||||
<div id='<?php echo $this->pagehook; ?>-widgets' class='metabox-holder'>
|
||||
<?php
|
||||
echo "\t<div class='postbox-container' style='width:{$this->args['column_widths'][0]}%'>\n";
|
||||
do_meta_boxes( $this->pagehook, 'normal', '' );
|
||||
|
||||
echo "\t</div><div class='postbox-container' style='width:{$hide2}{$this->args['column_widths'][1]}%'>\n";
|
||||
do_meta_boxes( $this->pagehook, 'side', '' );
|
||||
|
||||
echo "\t</div><div class='postbox-container' style='width:{$hide3}{$this->args['column_widths'][2]}%'>\n";
|
||||
do_meta_boxes( $this->pagehook, 'column3', '' );
|
||||
|
||||
echo "\t</div><div class='postbox-container' style='width:{$hide4}{$this->args['column_widths'][3]}%'>\n";
|
||||
do_meta_boxes( $this->pagehook, 'column4', '' );
|
||||
?>
|
||||
</div></div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays page footer.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function page_footer() {
|
||||
parent::page_footer();
|
||||
$this->_boxes_js_init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles option saving.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function form_handler() {
|
||||
if ( empty( $_POST ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
check_admin_referer( $this->nonce );
|
||||
|
||||
// Box handler
|
||||
foreach ( $this->boxes as $box ) {
|
||||
$args = isset( $box[4] ) ? $box[4] : array();
|
||||
|
||||
$handler = $box[0] . '_handler';
|
||||
|
||||
if ( method_exists( $this, $handler ) ) {
|
||||
call_user_func_array( array( $this, $handler ), $args );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstalls boxes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall() {
|
||||
global $wpdb;
|
||||
|
||||
$hook = str_replace( '-', '', $this->pagehook );
|
||||
|
||||
foreach ( array( 'metaboxhidden', 'closedpostboxes', 'wp_metaboxorder', 'screen_layout' ) as $option ) {
|
||||
$keys[] = "'{$option}_{$hook}'";
|
||||
}
|
||||
|
||||
$keys = '( ' . implode( ', ', $keys ) . ' )';
|
||||
|
||||
$wpdb->query( "
|
||||
DELETE FROM {$wpdb->usermeta}
|
||||
WHERE meta_key IN {$keys}
|
||||
" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds boxes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boxes_init() {
|
||||
wp_enqueue_script( 'postbox' );
|
||||
|
||||
add_screen_option( 'layout_columns', array(
|
||||
'max' => $this->args['columns'],
|
||||
'default' => $this->args['columns']
|
||||
) );
|
||||
|
||||
$registered = array();
|
||||
|
||||
foreach ( $this->boxes as $box_args ) {
|
||||
$box_args = self::numeric_to_assoc( $box_args, array( 'name', 'title', 'context', 'priority', 'args' ) );
|
||||
|
||||
$defaults = array(
|
||||
'title' => ucfirst( $box_args['name'] ),
|
||||
'context' => 'normal',
|
||||
'priority' => 'default',
|
||||
'args' => array()
|
||||
);
|
||||
$box_args = array_merge( $defaults, $box_args );
|
||||
|
||||
$name = $box_args['name'];
|
||||
|
||||
if ( isset( $registered[ $name ] ) ) {
|
||||
if ( empty( $box_args['args'] ) ) {
|
||||
trigger_error( "Duplicate box name: $name", E_USER_NOTICE );
|
||||
}
|
||||
|
||||
$name = $this->_increment( $name );
|
||||
} else {
|
||||
$registered[ $name ] = true;
|
||||
}
|
||||
|
||||
add_meta_box(
|
||||
$name,
|
||||
$box_args['title'],
|
||||
array( $this, '_intermediate_callback' ),
|
||||
$this->pagehook,
|
||||
$box_args['context'],
|
||||
$box_args['priority'],
|
||||
$box_args['args']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms numeric array to associative.
|
||||
*
|
||||
* @param array $argv
|
||||
* @param array $keys
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function numeric_to_assoc( $argv, $keys ) {
|
||||
$args = array();
|
||||
|
||||
foreach ( $keys as $i => $key ) {
|
||||
if ( isset( $argv[ $i ] ) ) {
|
||||
$args[ $key ] = $argv[ $i ];
|
||||
}
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Since we don't pass an object to do_meta_boxes(),
|
||||
* pass $box['args'] directly to each method.
|
||||
*
|
||||
* @param string $_
|
||||
* @param array $box
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function _intermediate_callback( $_, $box ) {
|
||||
list( $name ) = explode( '-', $box['id'] );
|
||||
|
||||
call_user_func_array( array( $this, $name . '_box' ), $box['args'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds/Increments ID in box name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _increment( $name ) {
|
||||
$parts = explode( '-', $name );
|
||||
if ( isset( $parts[1] ) ) {
|
||||
$parts[1]++;
|
||||
} else {
|
||||
$parts[1] = 2;
|
||||
}
|
||||
|
||||
return implode( '-', $parts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds necesary code for JS to work.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _boxes_js_init() {
|
||||
echo $this->js_wrap( <<<EOT
|
||||
jQuery( document ).ready( function( $ ){
|
||||
// close postboxes that should be closed
|
||||
$( '.if-js-closed' ).removeClass( 'if-js-closed' ).addClass( 'closed' );
|
||||
// postboxes setup
|
||||
postboxes.add_postbox_toggles( '$this->pagehook' );
|
||||
} );
|
||||
EOT
|
||||
);
|
||||
?>
|
||||
|
||||
<form style='display: none' method='get' action=''>
|
||||
<p>
|
||||
<?php
|
||||
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
|
||||
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
|
||||
?>
|
||||
</p>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
221
wp-content/plugins/wp-pagenavi/scb/Cron.php
Normal file
221
wp-content/plugins/wp-pagenavi/scb/Cron.php
Normal file
@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/**
|
||||
* WP Cron job container.
|
||||
*/
|
||||
class scbCron {
|
||||
protected $schedule;
|
||||
protected $interval;
|
||||
protected $time;
|
||||
|
||||
protected $hook;
|
||||
protected $callback_args = array();
|
||||
|
||||
/**
|
||||
* Create a new cron job.
|
||||
*
|
||||
* @param array $args List of args:
|
||||
* string $action OR callback $callback
|
||||
* string $schedule OR number $interval
|
||||
* array $callback_args (optional)
|
||||
*
|
||||
* @param string|bool $file (optional) Reference to main plugin file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $args, $file = false ) {
|
||||
|
||||
// Set time & schedule
|
||||
if ( isset( $args['time'] ) ) {
|
||||
$this->time = $args['time'];
|
||||
}
|
||||
|
||||
if ( isset( $args['interval'] ) ) {
|
||||
$this->schedule = $args['interval'] . 'secs';
|
||||
$this->interval = $args['interval'];
|
||||
} elseif ( isset( $args['schedule'] ) ) {
|
||||
$this->schedule = $args['schedule'];
|
||||
}
|
||||
|
||||
// Set hook
|
||||
if ( isset( $args['action'] ) ) {
|
||||
$this->hook = $args['action'];
|
||||
} else if ( isset( $args['callback'] ) ) {
|
||||
$this->hook = self::_callback_to_string( $args['callback'] );
|
||||
add_action( $this->hook, $args['callback'] );
|
||||
} else if ( method_exists( $this, 'callback' ) ) {
|
||||
$this->hook = self::_callback_to_string( array( $this, 'callback' ) );
|
||||
add_action( $this->hook, $args['callback'] );
|
||||
} else {
|
||||
trigger_error( '$action OR $callback not set', E_USER_WARNING );
|
||||
}
|
||||
|
||||
if ( isset( $args['callback_args'] ) ) {
|
||||
$this->callback_args = (array) $args['callback_args'];
|
||||
}
|
||||
|
||||
if ( $file && $this->schedule ) {
|
||||
scbUtil::add_activation_hook( $file, array( $this, 'reset' ) );
|
||||
register_deactivation_hook( $file, array( $this, 'unschedule' ) );
|
||||
}
|
||||
|
||||
add_filter( 'cron_schedules', array( $this, '_add_timing' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the interval of the cron job.
|
||||
*
|
||||
* @param array $args List of args:
|
||||
* string $schedule OR number $interval
|
||||
* timestamp $time ( optional )
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reschedule( $args ) {
|
||||
|
||||
if ( $args['schedule'] && $this->schedule != $args['schedule'] ) {
|
||||
$this->schedule = $args['schedule'];
|
||||
} elseif ( $args['interval'] && $this->interval != $args['interval'] ) {
|
||||
$this->schedule = $args['interval'] . 'secs';
|
||||
$this->interval = $args['interval'];
|
||||
}
|
||||
|
||||
$this->time = $args['time'];
|
||||
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the schedule.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reset() {
|
||||
$this->unschedule();
|
||||
$this->schedule();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cron job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unschedule() {
|
||||
# wp_clear_scheduled_hook( $this->hook, $this->callback_args );
|
||||
self::really_clear_scheduled_hook( $this->hook );
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job now.
|
||||
*
|
||||
* @param array $args (optional) List of arguments to pass to the callback.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function do_now( $args = null ) {
|
||||
if ( is_null( $args ) ) {
|
||||
$args = $this->callback_args;
|
||||
}
|
||||
|
||||
do_action_ref_array( $this->hook, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job with a given delay.
|
||||
*
|
||||
* @param int $delay (optional) Delay in seconds.
|
||||
* @param array $args (optional) List of arguments to pass to the callback.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function do_once( $delay = 0, $args = null ) {
|
||||
if ( is_null( $args ) ) {
|
||||
$args = $this->callback_args;
|
||||
}
|
||||
|
||||
wp_clear_scheduled_hook( $this->hook, $args );
|
||||
wp_schedule_single_event( time() + $delay, $this->hook, $args );
|
||||
}
|
||||
|
||||
|
||||
//_____INTERNAL METHODS_____
|
||||
|
||||
/**
|
||||
* Adds custom schedule timing.
|
||||
*
|
||||
* @param array $schedules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _add_timing( $schedules ) {
|
||||
if ( isset( $schedules[ $this->schedule ] ) ) {
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
$schedules[ $this->schedule ] = array(
|
||||
'interval' => $this->interval,
|
||||
'display' => $this->interval . ' seconds',
|
||||
);
|
||||
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule() {
|
||||
if ( ! $this->time ) {
|
||||
$this->time = time();
|
||||
}
|
||||
|
||||
wp_schedule_event( $this->time, $this->schedule, $this->hook, $this->callback_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears scheduled job.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function really_clear_scheduled_hook( $name ) {
|
||||
$crons = _get_cron_array();
|
||||
|
||||
foreach ( $crons as $timestamp => $hooks ) {
|
||||
foreach ( $hooks as $hook => $args ) {
|
||||
if ( $hook == $name ) {
|
||||
unset( $crons[ $timestamp ][ $hook ] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $crons[ $timestamp ] ) ) {
|
||||
unset( $crons[ $timestamp ] );
|
||||
}
|
||||
}
|
||||
|
||||
_set_cron_array( $crons );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a hook name from given callback.
|
||||
*
|
||||
* @param callback $callback
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function _callback_to_string( $callback ) {
|
||||
if ( ! is_array( $callback ) ) {
|
||||
$str = $callback;
|
||||
} else if ( ! is_string( $callback[0] ) ) {
|
||||
$str = get_class( $callback[0] ) . '_' . $callback[1];
|
||||
} else {
|
||||
$str = $callback[0] . '::' . $callback[1];
|
||||
}
|
||||
|
||||
$str .= '_hook';
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
1052
wp-content/plugins/wp-pagenavi/scb/Forms.php
Normal file
1052
wp-content/plugins/wp-pagenavi/scb/Forms.php
Normal file
File diff suppressed because it is too large
Load Diff
119
wp-content/plugins/wp-pagenavi/scb/Hooks.php
Normal file
119
wp-content/plugins/wp-pagenavi/scb/Hooks.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* Automatic filter binding.
|
||||
*/
|
||||
class scbHooks {
|
||||
private static $mangle_name;
|
||||
|
||||
/**
|
||||
* Adds.
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function add( $class ) {
|
||||
self::_do( 'add_filter', $class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes.
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function remove( $class ) {
|
||||
self::_do( 'remove_filter', $class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints debug.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $mangle_name (optional)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function debug( $class, $mangle_name = false ) {
|
||||
self::$mangle_name = $mangle_name;
|
||||
|
||||
echo "<pre>";
|
||||
self::_do( array( __CLASS__, '_print' ), $class );
|
||||
echo "</pre>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints.
|
||||
*
|
||||
* @param string $tag
|
||||
* @param array $callback
|
||||
* @param int $prio
|
||||
* @param int $argc
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function _print( $tag, $callback, $prio, $argc ) {
|
||||
$static = ! is_object( $callback[0] );
|
||||
|
||||
if ( self::$mangle_name ) {
|
||||
$class = $static ? '__CLASS__' : '$this';
|
||||
} else if ( $static ) {
|
||||
$class = "'" . $callback[0] . "'";
|
||||
} else {
|
||||
$class = '$' . get_class( $callback[0] );
|
||||
}
|
||||
|
||||
$func = "array( $class, '$callback[1]' )";
|
||||
|
||||
echo "add_filter( '$tag', $func";
|
||||
|
||||
if ( $prio != 10 || $argc > 1 ) {
|
||||
echo ", $prio";
|
||||
|
||||
if ( $argc > 1 ) {
|
||||
echo ", $argc";
|
||||
}
|
||||
}
|
||||
|
||||
echo " );\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes.
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function _do( $action, $class ) {
|
||||
$reflection = new ReflectionClass( $class );
|
||||
|
||||
foreach ( $reflection->getMethods() as $method ) {
|
||||
if ( $method->isPublic() && ! $method->isConstructor() ) {
|
||||
$comment = $method->getDocComment();
|
||||
|
||||
if ( preg_match( '/@nohook[ \t\*\n]+/', $comment ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
preg_match_all( '/@hook:?\s+([^\s]+)/', $comment, $matches ) ? $matches[1] : $method->name;
|
||||
if ( empty( $matches[1] ) ) {
|
||||
$hooks = array( $method->name );
|
||||
} else {
|
||||
$hooks = $matches[1];
|
||||
}
|
||||
|
||||
$priority = preg_match( '/@priority:?\s+(\d+)/', $comment, $matches ) ? $matches[1] : 10;
|
||||
|
||||
foreach ( $hooks as $hook ) {
|
||||
call_user_func( $action, $hook, array( $class, $method->name ), $priority, $method->getNumberOfParameters() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
197
wp-content/plugins/wp-pagenavi/scb/Options.php
Normal file
197
wp-content/plugins/wp-pagenavi/scb/Options.php
Normal file
@ -0,0 +1,197 @@
|
||||
<?php
|
||||
/**
|
||||
* Container for an array of options.
|
||||
*/
|
||||
class scbOptions {
|
||||
|
||||
/**
|
||||
* The option name.
|
||||
* @var string
|
||||
*/
|
||||
protected $key;
|
||||
|
||||
/**
|
||||
* The default values.
|
||||
* @var array
|
||||
*/
|
||||
protected $defaults;
|
||||
|
||||
/**
|
||||
* Used by WP hooks.
|
||||
* @var null
|
||||
*/
|
||||
public $wp_filter_id;
|
||||
|
||||
/**
|
||||
* Create a new set of options.
|
||||
*
|
||||
* @param string $key Option name.
|
||||
* @param string $file Reference to main plugin file.
|
||||
* @param array $defaults (optional) An associative array of default values.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $key, $file, $defaults = array() ) {
|
||||
$this->key = $key;
|
||||
$this->defaults = $defaults;
|
||||
|
||||
if ( $file ) {
|
||||
scbUtil::add_activation_hook( $file, array( $this, '_activation' ) );
|
||||
scbUtil::add_uninstall_hook( $file, array( $this, 'delete' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns option name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_key() {
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get option values for one or all fields.
|
||||
*
|
||||
* @param string|array $field (optional) The field to get.
|
||||
* @param mixed $default (optional) The value returned when the key is not found.
|
||||
*
|
||||
* @return mixed Whatever is in those fields.
|
||||
*/
|
||||
public function get( $field = null, $default = null ) {
|
||||
$current_options = get_option( $this->key, array() );
|
||||
$data = array_merge( $this->defaults, is_array( $current_options ) ? $current_options : array() );
|
||||
|
||||
return scbForms::get_value( $field, $data, $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default values for one or all fields.
|
||||
*
|
||||
* @param string|array $field (optional) The field to get.
|
||||
*
|
||||
* @return mixed Whatever is in those fields.
|
||||
*/
|
||||
public function get_defaults( $field = null ) {
|
||||
return scbForms::get_value( $field, $this->defaults );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all data fields, certain fields or a single field.
|
||||
*
|
||||
* @param string|array $field The field to update or an associative array.
|
||||
* @param mixed $value (optional) The new value ( ignored if $field is array ).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set( $field, $value = '' ) {
|
||||
if ( is_array( $field ) ) {
|
||||
$newdata = $field;
|
||||
} else {
|
||||
$newdata = array( $field => $value );
|
||||
}
|
||||
|
||||
$this->update( array_merge( $this->get(), $newdata ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset option to defaults.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reset() {
|
||||
$this->update( $this->defaults, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any keys that are not in the defaults array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cleanup() {
|
||||
$this->update( $this->get(), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update raw data.
|
||||
*
|
||||
* @param mixed $newdata
|
||||
* @param bool $clean (optional) Whether to remove unrecognized keys or not.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update( $newdata, $clean = true ) {
|
||||
if ( $clean ) {
|
||||
$newdata = $this->_clean( $newdata );
|
||||
}
|
||||
|
||||
update_option( $this->key, array_merge( $this->get(), $newdata ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the option.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete() {
|
||||
delete_option( $this->key );
|
||||
}
|
||||
|
||||
|
||||
//_____INTERNAL METHODS_____
|
||||
|
||||
|
||||
/**
|
||||
* Saves an extra query.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function _activation() {
|
||||
add_option( $this->key, $this->defaults );
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep only the keys defined in $this->defaults
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _clean( $data ) {
|
||||
return wp_array_slice_assoc( $data, array_keys( $this->defaults ) );
|
||||
}
|
||||
|
||||
private function &_get( $field, $data ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method: $options->field
|
||||
*
|
||||
* @param string|array $field The field to get.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get( $field ) {
|
||||
return $this->get( $field );
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method: $options->field = $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __set( $field, $value ) {
|
||||
$this->set( $field, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method: isset( $options->field )
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset( $field ) {
|
||||
$data = $this->get();
|
||||
return isset( $data[ $field ] );
|
||||
}
|
||||
}
|
||||
|
346
wp-content/plugins/wp-pagenavi/scb/PostMetabox.php
Normal file
346
wp-content/plugins/wp-pagenavi/scb/PostMetabox.php
Normal file
@ -0,0 +1,346 @@
|
||||
<?php
|
||||
/**
|
||||
* Class that creates metaboxes on the post editing page.
|
||||
*/
|
||||
class scbPostMetabox {
|
||||
|
||||
/**
|
||||
* Metabox ID.
|
||||
* @var string
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* Title.
|
||||
* @var string
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* Post types.
|
||||
* @var array
|
||||
*/
|
||||
private $post_types;
|
||||
|
||||
/**
|
||||
* Post meta data.
|
||||
* @var array
|
||||
*/
|
||||
private $post_data = array();
|
||||
|
||||
/**
|
||||
* Action hooks.
|
||||
* @var array
|
||||
*/
|
||||
protected $actions = array( 'admin_enqueue_scripts', 'post_updated_messages' );
|
||||
|
||||
/**
|
||||
* Sets up metabox.
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $title
|
||||
* @param array $args (optional)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $id, $title, $args = array() ) {
|
||||
$this->id = $id;
|
||||
$this->title = $title;
|
||||
|
||||
$args = wp_parse_args( $args, array(
|
||||
'post_type' => 'post',
|
||||
'context' => 'advanced',
|
||||
'priority' => 'default',
|
||||
) );
|
||||
|
||||
if ( is_string( $args['post_type'] ) ) {
|
||||
$args['post_type'] = array( $args['post_type'] );
|
||||
}
|
||||
|
||||
$this->post_types = $args['post_type'];
|
||||
$this->context = $args['context'];
|
||||
$this->priority = $args['priority'];
|
||||
|
||||
add_action( 'load-post.php', array( $this, 'pre_register' ) );
|
||||
add_action( 'load-post-new.php', array( $this, 'pre_register' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre register the metabox.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final public function pre_register() {
|
||||
if ( ! in_array( get_current_screen()->post_type, $this->post_types ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $this->condition() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $_GET['post'] ) ) {
|
||||
$this->post_data = $this->get_meta( intval( $_GET['post'] ) );
|
||||
}
|
||||
|
||||
add_action( 'add_meta_boxes', array( $this, 'register' ) );
|
||||
add_action( 'save_post', array( $this, '_save_post' ), 10, 2 );
|
||||
|
||||
foreach ( $this->actions as $action ) {
|
||||
if ( method_exists( $this, $action ) ) {
|
||||
add_action( $action, array( $this, $action ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional checks before registering the metabox.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function condition() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the metabox.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final public function register() {
|
||||
add_meta_box( $this->id, $this->title, array( $this, 'display' ), null, $this->context, $this->priority );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter data before display.
|
||||
*
|
||||
* @param array $form_data
|
||||
* @param object $post
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function before_display( $form_data, $post ) {
|
||||
return $form_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays metabox content.
|
||||
*
|
||||
* @param object $post
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function display( $post ) {
|
||||
$form_fields = $this->form_fields();
|
||||
if ( ! $form_fields ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$form_data = $this->post_data;
|
||||
$error_fields = array();
|
||||
|
||||
if ( isset( $form_data['_error_data_' . $this->id ] ) ) {
|
||||
$data = maybe_unserialize( $form_data['_error_data_' . $this->id ] );
|
||||
|
||||
$error_fields = $data['fields'];
|
||||
$form_data = $data['data'];
|
||||
|
||||
$this->display_notices( $data['messages'], 'error' );
|
||||
}
|
||||
|
||||
$form_data = $this->before_display( $form_data, $post );
|
||||
|
||||
$this->before_form( $post );
|
||||
echo $this->table( $form_fields, $form_data, $error_fields );
|
||||
$this->after_form( $post );
|
||||
|
||||
delete_post_meta( $post->ID, '_error_data_' . $this->id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns table.
|
||||
*
|
||||
* @param array $rows
|
||||
* @param array $formdata
|
||||
* @param array $errors (optional)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function table( $rows, $formdata, $errors = array() ) {
|
||||
$output = '';
|
||||
foreach ( $rows as $row ) {
|
||||
$output .= $this->table_row( $row, $formdata, $errors );
|
||||
}
|
||||
|
||||
$output = scbForms::table_wrap( $output );
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns table row.
|
||||
*
|
||||
* @param array $row
|
||||
* @param array $formdata
|
||||
* @param array $errors (optional)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function table_row( $row, $formdata, $errors = array() ) {
|
||||
$input = scbForms::input( $row, $formdata );
|
||||
|
||||
// If row has an error, highlight it
|
||||
$style = ( in_array( $row['name'], $errors ) ) ? 'style="background-color: #FFCCCC"' : '';
|
||||
|
||||
return html( 'tr',
|
||||
html( "th $style scope='row'", $row['title'] ),
|
||||
html( "td $style", $input )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays notices.
|
||||
*
|
||||
* @param array|string $notices
|
||||
* @param string $class (optional)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function display_notices( $notices, $class = 'updated' ) {
|
||||
// add inline class so the notices stays in metabox
|
||||
$class .= ' inline';
|
||||
|
||||
foreach ( (array) $notices as $notice ) {
|
||||
echo scb_admin_notice( $notice, $class );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display some extra HTML before the form.
|
||||
*
|
||||
* @param object $post
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function before_form( $post ) { }
|
||||
|
||||
/**
|
||||
* Return an array of form fields.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function form_fields() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display some extra HTML after the form.
|
||||
*
|
||||
* @param object $post
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function after_form( $post ) { }
|
||||
|
||||
/**
|
||||
* Makes sure that the saving occurs only for the post being edited.
|
||||
*
|
||||
* @param int $post_id
|
||||
* @param object $post
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final public function _save_post( $post_id, $post ) {
|
||||
if ( ! isset( $_POST['action'] ) || $_POST['action'] != 'editpost' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! isset( $_POST['post_ID'] ) || $_POST['post_ID'] != $post_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! in_array( $post->post_type, $this->post_types ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->save( $post->ID );
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves metabox form data.
|
||||
*
|
||||
* @param int $post_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function save( $post_id ) {
|
||||
$form_fields = $this->form_fields();
|
||||
|
||||
$to_update = scbForms::validate_post_data( $form_fields );
|
||||
|
||||
// Filter data
|
||||
$to_update = $this->before_save( $to_update, $post_id );
|
||||
|
||||
// Validate dataset
|
||||
$is_valid = $this->validate_post_data( $to_update, $post_id );
|
||||
if ( $is_valid instanceof WP_Error && $is_valid->get_error_codes() ) {
|
||||
|
||||
$error_data = array(
|
||||
'fields' => $is_valid->get_error_codes(),
|
||||
'messages' => $is_valid->get_error_messages(),
|
||||
'data' => $to_update,
|
||||
);
|
||||
update_post_meta( $post_id, '_error_data_' . $this->id, $error_data );
|
||||
|
||||
$location = add_query_arg( 'message', 1, get_edit_post_link( $post_id, 'url' ) );
|
||||
wp_redirect( esc_url_raw( apply_filters( 'redirect_post_location', $location, $post_id ) ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ( $to_update as $key => $value ) {
|
||||
update_post_meta( $post_id, $key, $value );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter data before save.
|
||||
*
|
||||
* @param array $post_data
|
||||
* @param int $post_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function before_save( $post_data, $post_id ) {
|
||||
return $post_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate posted data.
|
||||
*
|
||||
* @param array $post_data
|
||||
* @param int $post_id
|
||||
*
|
||||
* @return bool|object A WP_Error object if posted data are invalid.
|
||||
*/
|
||||
protected function validate_post_data( $post_data, $post_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of post meta.
|
||||
*
|
||||
* @param int $post_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_meta( $post_id ) {
|
||||
$meta = get_post_custom( $post_id );
|
||||
foreach ( $meta as $key => $values ) {
|
||||
$meta[ $key ] = maybe_unserialize( $meta[ $key ][0] );
|
||||
}
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
}
|
||||
|
66
wp-content/plugins/wp-pagenavi/scb/Table.php
Normal file
66
wp-content/plugins/wp-pagenavi/scb/Table.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Takes care of creating, updating and deleting database tables.
|
||||
*/
|
||||
class scbTable {
|
||||
|
||||
/**
|
||||
* The table name.
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* The table columns.
|
||||
* @var string
|
||||
*/
|
||||
protected $columns;
|
||||
|
||||
/**
|
||||
* The upgrade method.
|
||||
* @var string
|
||||
*/
|
||||
protected $upgrade_method;
|
||||
|
||||
/**
|
||||
* Sets up table.
|
||||
*
|
||||
* @param string $name Table name.
|
||||
* @param string $file Reference to main plugin file.
|
||||
* @param string $columns The SQL columns for the CREATE TABLE statement.
|
||||
* @param array $upgrade_method (optional)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $name, $file, $columns, $upgrade_method = 'dbDelta' ) {
|
||||
$this->name = $name;
|
||||
$this->columns = $columns;
|
||||
$this->upgrade_method = $upgrade_method;
|
||||
|
||||
scb_register_table( $name );
|
||||
|
||||
if ( $file ) {
|
||||
scbUtil::add_activation_hook( $file, array( $this, 'install' ) );
|
||||
scbUtil::add_uninstall_hook( $file, array( $this, 'uninstall' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function install() {
|
||||
scb_install_table( $this->name, $this->columns, $this->upgrade_method );
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstalls table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall() {
|
||||
scb_uninstall_table( $this->name );
|
||||
}
|
||||
}
|
||||
|
476
wp-content/plugins/wp-pagenavi/scb/Util.php
Normal file
476
wp-content/plugins/wp-pagenavi/scb/Util.php
Normal file
@ -0,0 +1,476 @@
|
||||
<?php
|
||||
/**
|
||||
* Various utilities.
|
||||
*/
|
||||
class scbUtil {
|
||||
|
||||
/**
|
||||
* Force script enqueue.
|
||||
*
|
||||
* @param array $handles
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function do_scripts( $handles ) {
|
||||
global $wp_scripts;
|
||||
|
||||
if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
|
||||
$wp_scripts = new WP_Scripts();
|
||||
}
|
||||
|
||||
$wp_scripts->do_items( ( array ) $handles );
|
||||
}
|
||||
|
||||
/**
|
||||
* Force style enqueue.
|
||||
*
|
||||
* @param array $handles
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function do_styles( $handles ) {
|
||||
self::do_scripts( 'jquery' );
|
||||
|
||||
global $wp_styles;
|
||||
|
||||
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
|
||||
$wp_styles = new WP_Styles();
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$wp_styles->do_items( ( array ) $handles );
|
||||
$content = str_replace( array( "'", "\n" ), array( '"', '' ), ob_get_clean() );
|
||||
|
||||
echo "<script type='text/javascript'>\n";
|
||||
echo "//<![CDATA[";
|
||||
echo "jQuery(function ($) { $('head').prepend('$content'); });\n";
|
||||
echo "//]]>";
|
||||
echo "</script>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable delayed plugin activation. To be used with scb_init()
|
||||
*
|
||||
* @param string $plugin
|
||||
* @param string|array $callback
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function add_activation_hook( $plugin, $callback ) {
|
||||
if ( defined( 'SCB_LOAD_MU' ) ) {
|
||||
register_activation_hook( $plugin, $callback );
|
||||
} else {
|
||||
add_action( 'scb_activation_' . plugin_basename( $plugin ), $callback );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute activation hook.
|
||||
* For debugging.
|
||||
*
|
||||
* @param string $plugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function do_activation( $plugin ) {
|
||||
do_action( 'scb_activation_' . plugin_basename( $plugin ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows more than one uninstall hooks.
|
||||
* Also prevents an UPDATE query on each page load.
|
||||
*
|
||||
* @param string $plugin
|
||||
* @param string|array $callback
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function add_uninstall_hook( $plugin, $callback ) {
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
register_uninstall_hook( $plugin, '__return_false' ); // dummy
|
||||
|
||||
add_action( 'uninstall_' . plugin_basename( $plugin ), $callback );
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute uninstall hook.
|
||||
* For debugging.
|
||||
*
|
||||
* @param string $plugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function do_uninstall( $plugin ) {
|
||||
do_action( 'uninstall_' . plugin_basename( $plugin ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current, full URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_current_url() {
|
||||
return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a function to each element of a ( nested ) array recursively.
|
||||
*
|
||||
* @param string|array $callback
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function array_map_recursive( $callback, $array ) {
|
||||
array_walk_recursive( $array, array( __CLASS__, 'array_map_recursive_helper' ), $callback );
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function array_map_recursive_helper( &$val, $key, $callback ) {
|
||||
$val = call_user_func( $callback, $val );
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract certain $keys from $array.
|
||||
*
|
||||
* @deprecated WP 3.1
|
||||
* @deprecated Use wp_array_slice_assoc()
|
||||
* @see wp_array_slice_assoc()
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $keys
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function array_extract( $array, $keys ) {
|
||||
_deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'WP 3.1', 'wp_array_slice_assoc()' );
|
||||
return wp_array_slice_assoc( $array, $keys );
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a certain value from a list of arrays.
|
||||
*
|
||||
* @deprecated WP 3.1
|
||||
* @deprecated Use wp_list_pluck()
|
||||
* @see wp_list_pluck()
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $key
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function array_pluck( $array, $key ) {
|
||||
_deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'WP 3.1', 'wp_list_pluck()' );
|
||||
return wp_list_pluck( $array, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a list of objects into an associative array.
|
||||
*
|
||||
* @deprecated r41
|
||||
* @deprecated Use scb_list_fold()
|
||||
* @see scb_list_fold()
|
||||
*
|
||||
* @param array $objects
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function objects_to_assoc( $objects, $key, $value ) {
|
||||
_deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'r41', 'scb_list_fold()' );
|
||||
return scb_list_fold( $objects, $key, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare an array for an IN statement.
|
||||
*
|
||||
* @param array $values
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function array_to_sql( $values ) {
|
||||
foreach ( $values as &$val ) {
|
||||
$val = "'" . esc_sql( trim( $val ) ) . "'";
|
||||
}
|
||||
|
||||
return implode( ',', $values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: split_at( '</', '<a></a>' ) => array( '<a>', '</a>' )
|
||||
*
|
||||
* @param string $delim
|
||||
* @param string $str
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function split_at( $delim, $str ) {
|
||||
$i = strpos( $str, $delim );
|
||||
|
||||
if ( false === $i ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$start = substr( $str, 0, $i );
|
||||
$finish = substr( $str, $i );
|
||||
|
||||
return array( $start, $finish );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a standard admin notice.
|
||||
*
|
||||
* @param string $msg
|
||||
* @param string $class (optional)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function scb_admin_notice( $msg, $class = 'updated' ) {
|
||||
return html( "div class='$class fade'", html( "p", $msg ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a list of objects into an associative array.
|
||||
*
|
||||
* @param array $objects
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function scb_list_fold( $list, $key, $value ) {
|
||||
$r = array();
|
||||
|
||||
if ( is_array( reset( $list ) ) ) {
|
||||
foreach ( $list as $item ) {
|
||||
$r[ $item[ $key ] ] = $item[ $value ];
|
||||
}
|
||||
} else {
|
||||
foreach ( $list as $item ) {
|
||||
$r[ $item->$key ] = $item->$value;
|
||||
}
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a list into sets, grouped by the result of running each value through $fn.
|
||||
*
|
||||
* @param array $list List of items to be partitioned.
|
||||
* @param callback $fn Function that takes an element and returns a string key.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function scb_list_group_by( $list, $fn ) {
|
||||
$groups = array();
|
||||
|
||||
foreach ( $list as $item ) {
|
||||
$key = call_user_func( $fn, $item );
|
||||
|
||||
if ( null === $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$groups[ $key ][] = $item;
|
||||
}
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
//_____Database Table Utilities_____
|
||||
|
||||
/**
|
||||
* Register a table with $wpdb.
|
||||
*
|
||||
* @param string $key The key to be used on the $wpdb object.
|
||||
* @param string $name (optional) The actual name of the table, without $wpdb->prefix.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function scb_register_table( $key, $name = false ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! $name ) {
|
||||
$name = $key;
|
||||
}
|
||||
|
||||
$wpdb->tables[] = $name;
|
||||
$wpdb->$key = $wpdb->prefix . $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the SQL query for installing/upgrading a table.
|
||||
*
|
||||
* @param string $key The key used in scb_register_table().
|
||||
* @param string $columns The SQL columns for the CREATE TABLE statement.
|
||||
* @param array $opts (optional) Various other options.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function scb_install_table( $key, $columns, $opts = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
$full_table_name = $wpdb->$key;
|
||||
|
||||
if ( is_string( $opts ) ) {
|
||||
$opts = array( 'upgrade_method' => $opts );
|
||||
}
|
||||
|
||||
$opts = wp_parse_args( $opts, array(
|
||||
'upgrade_method' => 'dbDelta',
|
||||
'table_options' => '',
|
||||
) );
|
||||
|
||||
$charset_collate = '';
|
||||
if ( $wpdb->has_cap( 'collation' ) ) {
|
||||
if ( ! empty( $wpdb->charset ) ) {
|
||||
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
||||
}
|
||||
if ( ! empty( $wpdb->collate ) ) {
|
||||
$charset_collate .= " COLLATE $wpdb->collate";
|
||||
}
|
||||
}
|
||||
|
||||
$table_options = $charset_collate . ' ' . $opts['table_options'];
|
||||
|
||||
if ( 'dbDelta' == $opts['upgrade_method'] ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
dbDelta( "CREATE TABLE $full_table_name ( $columns ) $table_options" );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'delete_first' == $opts['upgrade_method'] ) {
|
||||
$wpdb->query( "DROP TABLE IF EXISTS $full_table_name;" );
|
||||
}
|
||||
|
||||
$wpdb->query( "CREATE TABLE IF NOT EXISTS $full_table_name ( $columns ) $table_options;" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the SQL query for uninstalling a table.
|
||||
*
|
||||
* @param string $key The key used in scb_register_table().
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function scb_uninstall_table( $key ) {
|
||||
global $wpdb;
|
||||
|
||||
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->$key );
|
||||
}
|
||||
|
||||
//_____Minimalist HTML framework_____
|
||||
|
||||
/**
|
||||
* Generate an HTML tag. Atributes are escaped. Content is NOT escaped.
|
||||
*
|
||||
* @param string $tag
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
if ( ! function_exists( 'html' ) ):
|
||||
function html( $tag ) {
|
||||
static $SELF_CLOSING_TAGS = array( 'area', 'base', 'basefont', 'br', 'hr', 'input', 'img', 'link', 'meta' );
|
||||
|
||||
$args = func_get_args();
|
||||
|
||||
$tag = array_shift( $args );
|
||||
|
||||
if ( is_array( $args[0] ) ) {
|
||||
$closing = $tag;
|
||||
$attributes = array_shift( $args );
|
||||
foreach ( $attributes as $key => $value ) {
|
||||
if ( false === $value ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( true === $value ) {
|
||||
$value = $key;
|
||||
}
|
||||
|
||||
$tag .= ' ' . $key . '="' . esc_attr( $value ) . '"';
|
||||
}
|
||||
} else {
|
||||
list( $closing ) = explode( ' ', $tag, 2 );
|
||||
}
|
||||
|
||||
if ( in_array( $closing, $SELF_CLOSING_TAGS ) ) {
|
||||
return "<{$tag} />";
|
||||
}
|
||||
|
||||
$content = implode( '', $args );
|
||||
|
||||
return "<{$tag}>{$content}</{$closing}>";
|
||||
}
|
||||
endif;
|
||||
|
||||
/**
|
||||
* Generate an <a> tag.
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $title (optional)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
if ( ! function_exists( 'html_link' ) ):
|
||||
function html_link( $url, $title = '' ) {
|
||||
if ( empty( $title ) ) {
|
||||
$title = $url;
|
||||
}
|
||||
|
||||
return html( 'a', array( 'href' => esc_url( $url ) ), $title );
|
||||
}
|
||||
endif;
|
||||
|
||||
/**
|
||||
* Returns an array of query flags.
|
||||
*
|
||||
* @param object $wp_query (optional)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function scb_get_query_flags( $wp_query = null ) {
|
||||
if ( ! $wp_query ) {
|
||||
$wp_query = $GLOBALS['wp_query'];
|
||||
}
|
||||
|
||||
$flags = array();
|
||||
foreach ( get_object_vars( $wp_query ) as $key => $val ) {
|
||||
if ( 'is_' == substr( $key, 0, 3 ) && $val ) {
|
||||
$flags[] = substr( $key, 3 );
|
||||
}
|
||||
}
|
||||
|
||||
return $flags;
|
||||
}
|
||||
|
||||
//_____Compatibility layer_____
|
||||
|
||||
/**
|
||||
* Update data from a post field based on Post ID.
|
||||
* @see https://core.trac.wordpress.org/ticket/10946
|
||||
*
|
||||
* @param string $field Post field name.
|
||||
* @param string $value Post field value.
|
||||
* @param int $post_id Post ID.
|
||||
*
|
||||
* @return bool Result of UPDATE query.
|
||||
*/
|
||||
if ( ! function_exists( 'set_post_field' ) ) :
|
||||
function set_post_field( $field, $value, $post_id ) {
|
||||
global $wpdb;
|
||||
|
||||
$post_id = absint( $post_id );
|
||||
$value = sanitize_post_field( $field, $value, $post_id, 'db' );
|
||||
|
||||
return $wpdb->update( $wpdb->posts, array( $field => $value ), array( 'ID' => $post_id ) );
|
||||
}
|
||||
endif;
|
||||
|
124
wp-content/plugins/wp-pagenavi/scb/Widget.php
Normal file
124
wp-content/plugins/wp-pagenavi/scb/Widget.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Adds compatibility methods between WP_Widget and scbForms.
|
||||
*/
|
||||
abstract class scbWidget extends WP_Widget {
|
||||
|
||||
/**
|
||||
* Widget defaults.
|
||||
* @var array
|
||||
*/
|
||||
protected $defaults = array();
|
||||
|
||||
/**
|
||||
* Widgets to register.
|
||||
* @var array
|
||||
*/
|
||||
private static $scb_widgets = array();
|
||||
|
||||
/**
|
||||
* Initializes widget.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $file (optional)
|
||||
* @param string $base (optional)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function init( $class, $file = '', $base = '' ) {
|
||||
self::$scb_widgets[] = $class;
|
||||
|
||||
add_action( 'widgets_init', array( __CLASS__, '_scb_register' ) );
|
||||
|
||||
// for auto-uninstall
|
||||
if ( $file && $base && class_exists( 'scbOptions' ) ) {
|
||||
new scbOptions( "widget_$base", $file );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers widgets.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function _scb_register() {
|
||||
foreach ( self::$scb_widgets as $widget ) {
|
||||
register_widget( $widget );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays widget content.
|
||||
*
|
||||
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
|
||||
* @param array $instance The settings for the particular instance of the widget.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
$instance = wp_parse_args( $instance, $this->defaults );
|
||||
|
||||
extract( $args );
|
||||
|
||||
echo $before_widget;
|
||||
|
||||
$title = apply_filters( 'widget_title', isset( $instance['title'] ) ? $instance['title'] : '', $instance, $this->id_base );
|
||||
|
||||
if ( ! empty( $title ) ) {
|
||||
echo $before_title . $title . $after_title;
|
||||
}
|
||||
|
||||
$this->content( $instance );
|
||||
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is where the actual widget content goes.
|
||||
*
|
||||
* @param array $instance The settings for the particular instance of the widget.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function content( $instance ) { }
|
||||
|
||||
|
||||
//_____HELPER METHODS_____
|
||||
|
||||
|
||||
/**
|
||||
* Generates a input form field.
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $formdata (optional)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function input( $args, $formdata = array() ) {
|
||||
$prefix = array( 'widget-' . $this->id_base, $this->number );
|
||||
|
||||
$form = new scbForm( $formdata, $prefix );
|
||||
|
||||
// Add default class
|
||||
if ( ! isset( $args['extra'] ) && 'text' == $args['type'] ) {
|
||||
$args['extra'] = array( 'class' => 'widefat' );
|
||||
}
|
||||
|
||||
// Add default label position
|
||||
if ( ! in_array( $args['type'], array( 'checkbox', 'radio' ) ) && empty( $args['desc_pos'] ) ) {
|
||||
$args['desc_pos'] = 'before';
|
||||
}
|
||||
|
||||
$name = $args['name'];
|
||||
|
||||
if ( ! is_array( $name ) && '[]' == substr( $name, -2 ) ) {
|
||||
$name = array( substr( $name, 0, -2 ), '' );
|
||||
}
|
||||
|
||||
$args['name'] = $name;
|
||||
|
||||
return $form->input( $args );
|
||||
}
|
||||
|
||||
}
|
||||
|
22
wp-content/plugins/wp-pagenavi/scb/composer.json
Normal file
22
wp-content/plugins/wp-pagenavi/scb/composer.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name" : "scribu/scb-framework",
|
||||
"description": "A set of useful classes for faster plugin development",
|
||||
"keywords" : ["wordpress"],
|
||||
"homepage" : "https://github.com/scribu/wp-scb-framework",
|
||||
"license" : "GPL-3.0+",
|
||||
"authors" : [
|
||||
{
|
||||
"name" : "Cristi Burcă",
|
||||
"homepage": "http://scribu.net/"
|
||||
}
|
||||
],
|
||||
"support" : {
|
||||
"issues": "https://github.com/scribu/wp-scb-framework/issues",
|
||||
"source": "https://github.com/scribu/wp-scb-framework",
|
||||
"wiki": "https://github.com/scribu/wp-scb-framework/wiki"
|
||||
},
|
||||
"autoload" : {
|
||||
"classmap": ["."],
|
||||
"files" : ["load-composer.php", "Util.php"]
|
||||
}
|
||||
}
|
12
wp-content/plugins/wp-pagenavi/scb/load-composer.php
Normal file
12
wp-content/plugins/wp-pagenavi/scb/load-composer.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Pass through version to use when Composer handles classes load.
|
||||
*
|
||||
* @param callable $callback
|
||||
*/
|
||||
function scb_init( $callback = null ) {
|
||||
if ( $callback ) {
|
||||
call_user_func( $callback );
|
||||
}
|
||||
}
|
105
wp-content/plugins/wp-pagenavi/scb/load.php
Normal file
105
wp-content/plugins/wp-pagenavi/scb/load.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
$GLOBALS['_scb_data'] = array( 61, __FILE__, array(
|
||||
'scbUtil',
|
||||
'scbOptions',
|
||||
'scbForms',
|
||||
'scbTable',
|
||||
'scbWidget',
|
||||
'scbAdminPage',
|
||||
'scbBoxesPage',
|
||||
'scbPostMetabox',
|
||||
'scbCron',
|
||||
'scbHooks',
|
||||
) );
|
||||
|
||||
if ( ! class_exists( 'scbLoad4' ) ) :
|
||||
/**
|
||||
* The main idea behind this class is to load the most recent version of the scb classes available.
|
||||
*
|
||||
* It waits until all plugins are loaded and then does some crazy hacks to make activation hooks work.
|
||||
*/
|
||||
class scbLoad4 {
|
||||
|
||||
private static $candidates = array();
|
||||
private static $classes;
|
||||
private static $callbacks = array();
|
||||
|
||||
private static $loaded;
|
||||
|
||||
static function init( $callback = '' ) {
|
||||
list( $rev, $file, $classes ) = $GLOBALS['_scb_data'];
|
||||
|
||||
self::$candidates[ $file ] = $rev;
|
||||
self::$classes[ $file ] = $classes;
|
||||
|
||||
if ( ! empty( $callback ) ) {
|
||||
self::$callbacks[ $file ] = $callback;
|
||||
|
||||
add_action( 'activate_plugin', array( __CLASS__, 'delayed_activation' ) );
|
||||
}
|
||||
|
||||
if ( did_action( 'plugins_loaded' ) ) {
|
||||
self::load();
|
||||
} else {
|
||||
add_action( 'plugins_loaded', array( __CLASS__, 'load' ), 9, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
public static function delayed_activation( $plugin ) {
|
||||
$plugin_dir = dirname( $plugin );
|
||||
|
||||
if ( '.' == $plugin_dir ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( self::$callbacks as $file => $callback ) {
|
||||
if ( dirname( dirname( plugin_basename( $file ) ) ) == $plugin_dir ) {
|
||||
self::load( false );
|
||||
call_user_func( $callback );
|
||||
do_action( 'scb_activation_' . $plugin );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function load( $do_callbacks = true ) {
|
||||
arsort( self::$candidates );
|
||||
|
||||
$file = key( self::$candidates );
|
||||
|
||||
$path = dirname( $file ) . '/';
|
||||
|
||||
foreach ( self::$classes[ $file ] as $class_name ) {
|
||||
if ( class_exists( $class_name ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fpath = $path . substr( $class_name, 3 ) . '.php';
|
||||
if ( file_exists( $fpath ) ) {
|
||||
include $fpath;
|
||||
self::$loaded[] = $fpath;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $do_callbacks ) {
|
||||
foreach ( self::$callbacks as $callback ) {
|
||||
call_user_func( $callback );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static function get_info() {
|
||||
arsort( self::$candidates );
|
||||
|
||||
return array( self::$loaded, self::$candidates );
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'scb_init' ) ) :
|
||||
function scb_init( $callback = '' ) {
|
||||
scbLoad4::init( $callback );
|
||||
}
|
||||
endif;
|
||||
|
Reference in New Issue
Block a user