Initial Git import

This commit is contained in:
2015-09-18 11:05:56 +02:00
commit 2692f2bd0c
25 changed files with 2399 additions and 0 deletions

View File

@ -0,0 +1,43 @@
<?php
/**
* @package Dashboard
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Add to Right Now Widget
*
* @return void
*/
function wplt_dashboard_right_now() {
$total_files = wp_count_posts( 'wplt_tick' );
echo '<tr>';
echo '<td class="first b b-tags"><a href="edit.php?post_type=wplt_tick">' . $total_files->publish . '</a></td>';
echo '<td class="t tags"><a href="edit.php?post_type=wplt_tick">' . __( 'Ticks', 'wplt2' ) . '</a></td>';
echo '</tr>';
}
add_action( 'right_now_content_table_end' , 'wplt_dashboard_right_now' );
/**
* Register dashboard widgets
*
* @return void
*/
function wplt_register_dashboard_widgets() {
wp_add_dashboard_widget( 'wplt_dashboard_downloads', __( 'Download Stats', 'wplt2' ), 'wplt_dashboard_downloads_widget' );
}
//add_action( 'wp_dashboard_setup', 'wplt_register_dashboard_widgets' );
/**
* Ticks Dashboard Widget
*
* @access private
* @since 1.0
* @return void
*/
function wplt_dashboard_ticks_widget() {
echo 'Content to follow...';
}

View File

@ -0,0 +1,99 @@
<?php
/**
* @package Media Button
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Display Media Button
*
* @param string $content existing media buttons
*
* @return string $content + $output
*/
function wplt_media_button( $context ) {
if( get_post_type() != 'wplt_download' ) {
return $context . '<a href="#" id="sdm-media-button" class="button add-download" data-editor="content" title="Add Download"><span class="wp-media-buttons-icon"></span>Add Download</a>';
}
}
add_filter( 'media_buttons_context', 'wplt_media_button' );
/**
* Add Modal Window to Footer
*
* @return void
*/
function wplt_media_modal() {
global $wplt_options;
$downloads = new WP_Query( 'post_type=wplt_download&nopaging=true&orderby=title&order=ASC' );
?>
<div id="sdm-download-modal" style="display: none">
<div class="media-modal">
<a id="sdm-download-modal-close" class="media-modal-close" href="#" title="Close"><span class="media-modal-icon"></span></a>
<div class="media-modal-content">
<div class="media-frame-title">
<h1><?php _e( 'Insert Download', 'simple-downloads' ); ?></h1>
</div>
<div class="left-panel">
<div class="sdm-download-list">
<ul id="selectable_list">
<?php
while ( $downloads->have_posts() ) {
$downloads->the_post();
echo '<li data-ID="' . get_the_ID() . '">';
echo '<strong>' . get_the_title() . '</strong>';
echo '<span class="download_url">' . get_post_meta( get_the_ID(), '_wplt_file_url', true ) . '</span>';
echo '</li>';
}
?>
</ul>
</div>
</div>
<div class="right-panel">
<div class="download-details" style="display: none">
<h3><?php _e( 'Download Details', 'simple-downloads' ); ?></h3>
<label for="sdm-download-text"><?php _e( 'Text', 'simple-downloads' ); ?>:</label>
<input type="text" name="sdm-download-text" id="sdm-download-text" value="<?php echo $wplt_options['default_text']; ?>"/>
<label for="sdm-download-style"><?php _e( 'Style', 'simple-downloads' ); ?>:</label>
<select name="sdm-download-style" id="sdm-download-style">
<?php
$styles = wplt_get_shortcode_styles();
$default_style = $wplt_options['default_style'];
foreach( $styles as $key => $value ) {
$selected = ( $default_style == $key ? ' selected="selected"' : '' );
echo '<option value="' . $key . '" ' . $selected . '>' . $value . '</option>';
}
?>
</select>
<div class="sdm-download-color-container">
<label for="sdm-download-color"><?php _e( 'Color', 'simple-downloads' ); ?>:</label>
<select name="sdm-download-color" id="sdm-download-color">
<?php
$colors = wplt_get_shortcode_colors();
$default_color = $wplt_options['default_color'];
foreach( $colors as $key => $value ) {
$selected = ( $default_color == $key ? ' selected="selected"' : '' );
echo '<option value="' . $key . '" ' . $selected . '>' . $value . '</option>';
}
?>
</select>
</div>
<input id="sdm-download-button" type="button" value="<?php _e( 'Insert Download', 'simple-downloads' ); ?>" class="button-primary" />
<input id="sdm-filesize-button" type="button" value="<?php _e( 'Insert File Size', 'simple-downloads' ); ?>" class="button" />
<input id="sdm-count-button"type="button" value="<?php _e( 'Insert Download Count', 'simple-downloads' ); ?>" class="button" />
</div>
</div>
</div>
</div>
<div class="media-modal-backdrop"></div>
</div>
<?php
}
add_action( 'admin_footer', 'wplt_media_modal' );

View File

@ -0,0 +1,219 @@
<?php
/**
* @package Meta-Boxes
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Register meta boxes
*
* @return void
*/
function wplt_register_meta_boxes() {
// File
add_meta_box( 'wplt_file', __( 'File', 'wplt2' ), 'wplt_meta_box_file', 'wplt_download', 'normal', 'high' );
// Stats
add_meta_box( 'wplt_stats', __( 'Download Stats', 'wplt2' ), 'wplt_meta_box_stats', 'wplt_download', 'side', 'core' );
}
add_action( 'add_meta_boxes', 'wplt_register_meta_boxes' );
/**
* Add correct enc type for non-ajax uploads
*
* @return void
*/
function wplt_form_enctype() {
if( get_post_type() == 'wplt_download' ) {
echo ' enctype="multipart/form-data"';
}
}
add_action( 'post_edit_form_tag', 'wplt_form_enctype' );
/**
* Render file meta box
*
* @param object $post current post object
*
* @return void
*/
function wplt_meta_box_file( $post ) {
$file_url = get_post_meta( $post->ID, '_wplt_file_url', true );
$file_size = get_post_meta( $post->ID, '_wplt_file_size', true );
global $post;
$plupload_init = array(
'runtimes' => 'html5, silverlight, flash, html4',
'browse_button' => 'plupload-browse-button',
'container' => 'plupload-container',
'file_data_name' => 'async-upload',
'multiple_queues' => false,
'max_file_size' => wp_max_upload_size() . 'b',
'url' => admin_url( 'admin-ajax.php' ),
'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
'filters' => array( array( 'title' => __( 'Allowed Files' ), 'extensions' => '*' ) ),
'multipart' => true,
'urlstream_upload' => true,
// additional post data to send to our ajax hook
'multipart_params' => array(
'_ajax_nonce' => wp_create_nonce( 'wplt_download_upload' ),
'action' => 'wplt_download_upload',
'post_id' => $post->ID
),
);
// Pass to plupload
$plupload_init = apply_filters( 'plupload_init', $plupload_init );
?>
<script type="text/javascript">
var plupload_args = <?php echo json_encode( $plupload_init ); ?>;
</script>
<div id="plupload-container" class="hide-if-no-js">
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">
File URL:
</th>
<td id="plupload-file">
<?php echo ($file_url !== '' ? $file_url : '-----' ); ?>
</td>
</tr>
<tr valign="top">
<th scope="row">
File Size:
</th>
<td id="plupload-file-size">
<?php echo ($file_size !== '' ? wplt_human_filesize( $file_size ) : '-----' ); ?>
</td>
</tr>
<tr valign="top">
<th scope="row">
</th>
<td>
<input id="plupload-browse-button" type="button" value="<?php _e( 'Select File', 'wplt2' ); ?>" class="button" />
<input id="plupload-upload-button" type="button" value="<?php _e( 'Upload', 'wplt2' ); ?>" class="button" style="display: none" />
<a id="plupload-cancel-button" href="#" style="display: none">Cancel</a>
<p class="description"><?php printf( __( 'Maximum file size: %s.', 'wplt2' ), wplt_human_filesize( wp_max_upload_size() ) ); ?></p>
<div id="plupload-progress" style="display: none">
<div class="bar" style="width: 0%"></div>
<div class="percent"><p>Uploading...</p></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div id="plupload-container" class="hide-if-js">
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">
File URL:
</th>
<td id="plupload-file">
<?php echo ($file_url !== '' ? $file_url : '-----' ); ?>
</td>
</tr>
<tr valign="top">
<th scope="row">
File Size:
</th>
<td id="plupload-file-size">
<?php echo ($file_size !== '' ? wplt_human_filesize( $file_size ) : '-----' ); ?>
</td>
</tr>
<tr valign="top">
<th scope="row">
</th>
<td>
<label for="async-upload"><?php _e( 'Upload', 'wplt2' ); ?>:</label>
<input type="file" name="async-upload" id="async-upload" />
<p class="description"><?php printf( __( 'Maximum file size: %s.', 'wplt2' ), wplt_human_filesize( wp_max_upload_size() ) ); ?></p> </td>
</tr>
</tbody>
</table>
</div>
<?php
}
/**
* Save file metabox
*
* @param object $post current post object
*
* @return void
*/
function wplt_meta_box_file_save( $post_id ) {
// First check we have file present
if( isset( $_FILES['async-upload'] ) && $_FILES['async-upload']['size'] > 0 ) {
// Set upload dir
add_filter( 'upload_dir', 'wplt_set_upload_dir' );
// Upload the file
$file = wp_handle_upload( $_FILES['async-upload'], array( 'test_form' => false ) );
// Check for success
if( isset( $file['file'] ) ) {
// Post ID
$post_id = $_REQUEST['post_id'];
// Add/update post meta
update_post_meta( $post_id, '_wplt_file_url', $file['url'] );
update_post_meta( $post_id, '_wplt_file_size', $_FILES['async-upload']['size'] );
update_post_meta( $post_id, '_wplt_file_type', $file['type'] );
}
}
}
add_action( 'save_post', 'wplt_meta_box_file_save' );
/**
* Render stats meta box
*
* @param object $post current post object
*
* @return void
*/
function wplt_meta_box_stats( $post ) {
$file_count = get_post_meta( $post->ID, '_wplt_file_count', true );
?>
<div id="sdm-file-stats-container">
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">
<label for="wplt_file_count"><?php _e( 'Count' , 'wplt2' ); ?>:</label>
</th>
<td>
<input type="text" name="wplt_file_count" class="text-small" value="<?php echo ($file_count !== '' ? $file_count : 0 ); ?>" />
</td>
</tr>
</tbody>
</table>
</div>
<?php
}
/**
* Save stats meta box
*
* @param int $post_id current post id
*
* @return void
*/
function wplt_meta_box_stats_save( $post_id ) {
if( isset( $_POST['wplt_file_count'] ) ) {
update_post_meta( $post_id, '_wplt_file_count', strip_tags( trim( $_POST['wplt_file_count'] ) ) );
}
}
add_action( 'save_post', 'wplt_meta_box_stats_save' );

View File

@ -0,0 +1,151 @@
<?php
/**
* @package Settings Page
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Register settings page
*
* @return void
*/
function wplt_register_page_settings() {
add_submenu_page( 'edit.php?post_type=wplt_tick', 'Liveticker2 ' . __( 'Settings', 'wplt2' ), __( 'Settings', 'wplt2' ), 'manage_options', 'wplt_settings', 'wplt_render_page_settings' );
}
add_action( 'admin_menu', 'wplt_register_page_settings' );
/**
* Register settings API
*
* @return void
*/
function wplt_register_settings() {
register_setting( 'wplt_settings', 'wplt2', 'wplt_validate_settings' );
// Form sections
add_settings_section( 'wplt_settings_general', __( 'General', 'wplt2' ), 'wplt_settings_general_section', __FILE__ );
add_settings_section( 'wplt_settings_uninstall', __( 'Uninstall', 'wplt2' ), 'wplt_settings_uninstall_section', __FILE__ );
// Form fields
add_settings_field( 'enable_css', __( 'Default CSS Styles', 'wplt2' ), 'wplt_settings_enable_css_field', __FILE__, 'wplt_settings_general' );
add_settings_field( 'reset_settings', __( 'Reset Settings', 'wplt2' ), 'wplt_settings_reset_settings_field', __FILE__, 'wplt_settings_uninstall' );
}
add_action( 'admin_init', 'wplt_register_settings' );
/**
* Validate settings callback
*
* @return void
*/
function wplt_validate_settings( $input ) {
$defaults = wplt_get_default_options();
$parsed = wp_parse_args( $input, $defaults );
// Fix empty default text textbox
if( trim( $input['default_text'] == '' ) ) {
$parsed['default_text'] = $defaults['default_text'];
}
return $parsed;
}
/**
* Render settings page
*
* @return void
*/
function wplt_render_page_settings() {
?>
<div class="wrap">
<div id="icon-options-general" class="icon32"><br></div>
<h2>Liveticker <?php _e( 'Settings', 'wplt2' ); ?></h2>
<?php if ( isset( $_GET['settings-updated'] ) ) {
echo '<div class="updated"><p>' . __( 'Settings updated successfully.', 'wplt2' ) . '</p></div>';
} ?>
<form action="options.php" method="post">
<?php
settings_fields( 'wplt_settings' );
do_settings_sections( __FILE__ );
?>
<p class="submit">
<input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
</p>
</form>
</div>
<?php
}
/**
* Render general section
*
* @return void
*/
function wplt_settings_general_section() {
return;
}
/**
* Render uninstall section
*
* @return void
*/
function wplt_settings_uninstall_section() {
return;
}
/**
* Render enable css field
*
* @return void
*/
function wplt_settings_enable_css_field() {
global $wplt_options;
$checked = $wplt_options['enable_css'];
echo '<label for="wp-liveticker2[enable_css]">';
echo '<input type="checkbox" name="wp-liveticker2[enable_css]" value="1" ' . checked( $checked, 1, false ) . ' /> ';
echo __( 'Enable', 'wplt2' );
echo '</label>';
echo '<p class="description">' . __( 'Disable this option to remove the default button styling and the Delightful Downloads CSS file.', 'wplt2' ) . '</p>';
}
/**
* Render default style field
*
* @return void
*/
function wplt_settings_default_style_field() {
global $wplt_options;
$styles = wplt_get_shortcode_styles();
$default_style = $wplt_options['default_style'];
echo '<select name="simple-downloads[default_style]">';
foreach( $styles as $key => $value ) {
$selected = ( $default_style == $key ? ' selected="selected"' : '' );
echo '<option value="' . $key . '" ' . $selected . '>' . $value . '</option>';
}
echo '</select>';
echo '<p class="description">' . __( 'The default display style.', 'wplt2' ) . '</p>';
}
/**
* Render reset settings field
*
* @return void
*/
function wplt_settings_reset_settings_field() {
global $wplt_options;
$checked = $wplt_options['reset_settings'];
echo '<label for="simple-downloads[reset_settings]">';
echo '<input type="checkbox" name="simple-downloads[reset_settings]" value="1" ' . checked( $checked, 1, false ) . ' /> ';
echo __( 'Enable', 'wplt2' );
echo '<p class="description">' . __( 'Reset plugin settings on re-activation.', 'wplt2' ) . '</p>';
echo '</label>';
}

View File

@ -0,0 +1,73 @@
<?php
/**
* @package Post Types Columns
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Download post type column headings
*
* @param array $columns default columns registered by WordPress
*
* @return void
*/
function wplt_tick_column_headings( $columns ) {
return array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'wplt2' ),
'author' => __( 'Author', 'wplt2' ),
'wplt_ticker' => __( 'Ticker', 'wplt2'),
'date' => __( 'Date', 'wplt2' )
);
}
//add_filter( 'manage_wplt_tick_posts_columns', 'wplt_tick_column_headings' );
/**
* Download post type column contents
*
* @param array $column_name current column
* @param int $post_id current post id provided by WordPress
*
* @return void
*/
function wplt_tick_column_contents( $column_name, $post_id ) {
// Title column
if( $column_name == 'file' ) {
$path = get_post_meta( $post_id, '_wplt_file_url', true );
echo wplt_download_filename( $path );
}
}
add_action( 'manage_wplt_tick_posts_custom_column', 'wplt_tick_column_contents', 10, 2 );
/**
* Download post type sortable columns filter
*
* @param array $columns as set above
*
* @return void
*/
function wplt_tick_column_sortable( $columns ) {
$columns['ticks'] = 'ticks';
return $columns;
}
add_filter( 'manage_edit-wplt_tick_sortable_columns', 'wplt_tick_column_sortable' );
/**
* Download post type sortable columns action
*
* @param array $query
*
* @return void
*/
function wplt_tick_column_orderby( $query ) {
$orderby = $query->get( 'orderby');
if( $orderby == 'ticks' ) {
$query->set('meta_key','_wplt_file_count');
$query->set('orderby','meta_value_num');
}
}
add_action( 'pre_get_posts', 'wplt_tick_column_orderby' );