Begin transformation into classes
Grouped single PHP files with various funcitons into classes for basic, admin and system scope.
This commit is contained in:
@ -1,43 +0,0 @@
|
||||
<?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...';
|
||||
}
|
32
includes/class-wpliveticker2-admin.php
Normal file
32
includes/class-wpliveticker2-admin.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* WP Liveticker 2: Plugin admin class.
|
||||
*
|
||||
* This file contains the derived class for the plugin's administration features.
|
||||
*
|
||||
* @package WPLiveticker2
|
||||
*/
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* WP Liveticker 2 admin configuration.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class WPLiveticker2_Admin extends WPLiveticker2 {
|
||||
/**
|
||||
* Add to Right Now Widget
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function dashboard_right_now() {
|
||||
$total_files = wp_count_posts( 'wplt2_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>';
|
||||
}
|
||||
}
|
41
includes/class-wpliveticker2-system.php
Normal file
41
includes/class-wpliveticker2-system.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* WP Liveticker 2: Plugin system class.
|
||||
*
|
||||
* This file contains the derived class for the plugin's system operations.
|
||||
*
|
||||
* @package WPLiveticker2
|
||||
*/
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* WP Liveticker 2 system configuration.
|
||||
*
|
||||
*/
|
||||
class WPLiveticker2_System extends WPLiveticker2 {
|
||||
|
||||
/**
|
||||
* Activation hook.
|
||||
*
|
||||
* Initializes default options.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function activate() {
|
||||
// Load current options.
|
||||
self::update_options();
|
||||
|
||||
// Add default settings to database.
|
||||
$defaults = self::default_options();
|
||||
|
||||
if ( self::$_options['reset_settings'] ) {
|
||||
// Reset requested, overwrite existing options with default.
|
||||
update_option( self::OPTION, $defaults );
|
||||
} else {
|
||||
// Otherwise add new options.
|
||||
add_option( self::OPTION, $defaults );
|
||||
}
|
||||
}
|
||||
}
|
211
includes/class-wpliveticker2.php
Normal file
211
includes/class-wpliveticker2.php
Normal file
@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/**
|
||||
* WP Liveticker 2: Plugin main class.
|
||||
*
|
||||
* This file contains the plugin's base class.
|
||||
*
|
||||
* @package WPLiveticker2
|
||||
*/
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* WP Liveticker 2.
|
||||
*/
|
||||
class WPLiveticker2 {
|
||||
/**
|
||||
* Options tag.
|
||||
*
|
||||
* @var string OPTIONS
|
||||
*/
|
||||
const OPTION = 'wplt2';
|
||||
|
||||
/**
|
||||
* Plugin options.
|
||||
*
|
||||
* @var array $_options
|
||||
*/
|
||||
protected static $_options;
|
||||
|
||||
/**
|
||||
* Plugin options.
|
||||
*
|
||||
* @var boolean $shortcode_present
|
||||
*/
|
||||
protected static $shortcode_present = false;
|
||||
|
||||
/**
|
||||
* Plugin initialization.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
// Skip on autosave or AJAX.
|
||||
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load plugin options.
|
||||
self::update_options();
|
||||
|
||||
// Load Textdomain.
|
||||
load_plugin_textdomain( 'wplt2', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
|
||||
|
||||
// Allow shortcodes in widgets.
|
||||
add_filter( 'widget_text', 'do_shortcode' );
|
||||
|
||||
// Add shortcode.
|
||||
add_shortcode( 'liveticker', array( 'WPLiveticker2', 'shortcode_ticker_show' ) );
|
||||
|
||||
// Admin only actions.
|
||||
if ( is_admin() ) {
|
||||
// Add dashboard "right now" functionality.
|
||||
add_action( 'right_now_content_table_end', array( 'WPLiveticker2_Admin', 'dashboard_right_now' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register tick post type.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function register_types() {
|
||||
// Add new taxonomy, make it hierarchical (like categories).
|
||||
$labels = array(
|
||||
'name' => _x( 'Ticker', 'taxonomy general name' ),
|
||||
'singular_name' => _x( 'Ticker', 'taxonomy singular name' ),
|
||||
'search_items' => __( 'Search Tickers', 'wplt2' ),
|
||||
'all_items' => __( 'All Tickers', 'wplt2' ),
|
||||
'parent_item' => __( 'Parent Ticker', 'wplt2' ),
|
||||
'parent_item_colon' => __( 'Parent Ticker:', 'wplt2' ),
|
||||
'edit_item' => __( 'Edit Ticker', 'wplt2' ),
|
||||
'update_item' => __( 'Update Ticker', 'wplt2' ),
|
||||
'add_new_item' => __( 'Add New Ticker', 'wplt2' ),
|
||||
'new_item_name' => __( 'New Ticker', 'wplt2' ),
|
||||
'menu_name' => __( 'Ticker', 'wplt2' ),
|
||||
);
|
||||
|
||||
register_taxonomy(
|
||||
'wplt2_ticker',
|
||||
array( 'wplt2_tick' ),
|
||||
array(
|
||||
'hierarchical' => true,
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
)
|
||||
);
|
||||
|
||||
// Post type arguments.
|
||||
$args = array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Ticks', 'wplt2' ),
|
||||
'singular_name' => __( 'Tick', 'wplt2' ),
|
||||
'add_new' => __( 'Add New', 'wplt2' ),
|
||||
'add_new_item' => __( 'Add New Tick', 'wplt2' ),
|
||||
'edit_item' => __( 'Edit Tick', 'wplt2' ),
|
||||
'new_item' => __( 'New Tick', 'wplt2' ),
|
||||
'all_items' => __( 'All Ticks', 'wplt2' ),
|
||||
'view_item' => __( 'View Tick', 'wplt2' ),
|
||||
'search_items' => __( 'Search Ticks', 'wplt2' ),
|
||||
'not_found' => __( 'No Ticks found', 'wplt2' ),
|
||||
'not_found_in_trash' => __( 'No Ticks found in Trash', 'wplt2' ),
|
||||
'parent_item_colon' => '',
|
||||
'menu_name' => __( 'Liveticker', 'wplt2' ),
|
||||
),
|
||||
'public' => false,
|
||||
'show_ui' => true,
|
||||
'show_in_menu' => true,
|
||||
'menu_icon' => 'dashicons-rss',
|
||||
'capability_type' => 'post',
|
||||
'supports' => array( 'title', 'editor', 'author' ),
|
||||
'taxonomies' => array( 'wplt2_ticker' ),
|
||||
);
|
||||
|
||||
register_post_type( 'wplt2_tick', $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output Liveticker
|
||||
*
|
||||
* @param array $atts Shortcode attributes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function shortcode_ticker_show( $atts ) {
|
||||
// Indicate presence of shortcode (to enqueue styles/scripts later).
|
||||
self::$shortcode_present = true;
|
||||
|
||||
// Initialize output.
|
||||
$output = '';
|
||||
|
||||
// Check if first attribute is filled.
|
||||
if ( $atts['ticker'] ) {
|
||||
// Set limit to infinite, if not set explicitly.
|
||||
if ( ! isset( $atts['limit'] ) ) {
|
||||
$atts['limit'] = - 1;
|
||||
}
|
||||
|
||||
$output = '<ul class="wplt2_ticker">';
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'wplt2_tick',
|
||||
'posts_per_page' => $atts['limit'],
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'wplt2_ticker',
|
||||
'field' => 'slug',
|
||||
'terms' => $atts['ticker'],
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_query = new WP_Query( $args );
|
||||
|
||||
while ( $wp_query->have_posts() ) {
|
||||
$wp_query->the_post();
|
||||
$output .= '<li class="wplt2_tick">
|
||||
<p><span class="wplt2_tick_time">' . get_the_time( 'd.m.Y H.i' ) . '</span>
|
||||
<span class="wplt2_tick_title">' . get_the_title() . '</span></p>
|
||||
<p class="wplt2_tick_content">' . get_the_content() . '</p></li>';
|
||||
}
|
||||
|
||||
$output .= '</ul>';
|
||||
|
||||
// Show RSS feed link, if configured.
|
||||
if (1 === self::$_options['show_feed']) {
|
||||
$output .= '<a href="/feed/liveticker/' . esc_html( $atts['ticker'] ) . '"><img class="wplt2_rss" src="/wp-content/plugins/wp-liveticker2/images/rss.jpg" alt="RSS" /></a>';
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update options.
|
||||
*
|
||||
* @param array $options Optional. New options to save.
|
||||
*/
|
||||
protected static function update_options( $options = null ) {
|
||||
self::$_options = wp_parse_args(
|
||||
get_option( self::OPTION ),
|
||||
self::default_options()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create default plugin configuration.
|
||||
*
|
||||
* @return array The options array.
|
||||
*/
|
||||
protected static function default_options() {
|
||||
return array(
|
||||
'enable_ajax' => 1,
|
||||
'enable_css' => 1,
|
||||
'show_feed' => 0,
|
||||
'reset_settings' => 0,
|
||||
);
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Functions
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( !defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
/**
|
||||
* Returns default options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wplt_get_default_options() {
|
||||
return array(
|
||||
'enable_css' => 1,
|
||||
'reset_settings' => 0,
|
||||
'shortcode_present' => false
|
||||
);
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Post Types
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( !defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
/**
|
||||
* Register tick post type
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function wplt_tick_post_type() {
|
||||
$args = array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Ticks', 'wplt2' ),
|
||||
'singular_name' => __( 'Tick', 'wplt2' ),
|
||||
'add_new' => __( 'Add New', 'wplt2' ),
|
||||
'add_new_item' => __( 'Add New Tick', 'wplt2' ),
|
||||
'edit_item' => __( 'Edit Tick', 'wplt2' ),
|
||||
'new_item' => __( 'New Tick', 'wplt2' ),
|
||||
'all_items' => __( 'All Ticks', 'wplt2' ),
|
||||
'view_item' => __( 'View Tick', 'wplt2' ),
|
||||
'search_items' => __( 'Search Ticks', 'wplt2' ),
|
||||
'not_found' => __( 'No Ticks found', 'wplt2' ),
|
||||
'not_found_in_trash' => __( 'No Ticks found in Trash', 'wplt2' ),
|
||||
'parent_item_colon' => '',
|
||||
'menu_name' => __( 'Liveticker', 'wplt2' )
|
||||
),
|
||||
'public' => false,
|
||||
'show_ui' => true,
|
||||
'show_in_menu' => true,
|
||||
'menu_icon' => 'dashicons-rss',
|
||||
'capability_type' => 'post',
|
||||
'supports' => array( 'title', 'editor', 'author'),
|
||||
'taxonomies' => array('wplt_ticker')
|
||||
);
|
||||
|
||||
register_post_type( 'wplt_tick', $args );
|
||||
}
|
||||
add_action( 'init', 'wplt_tick_post_type' );
|
||||
|
||||
|
||||
/**
|
||||
* Register custom taxamony (category)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
//hook into the init action and call create_book_taxonomies when it fires
|
||||
add_action( 'init', 'wplt_ticker_taxonomy', 0 );
|
||||
|
||||
//create two taxonomies, genres and writers for the post type "book"
|
||||
function wplt_ticker_taxonomy()
|
||||
{
|
||||
// Add new taxonomy, make it hierarchical (like categories)
|
||||
$labels = array(
|
||||
'name' => _x( 'Ticker', 'taxonomy general name' ),
|
||||
'singular_name' => _x( 'Ticker', 'taxonomy singular name' ),
|
||||
'search_items' => __( 'Search Tickers', 'wplt2' ),
|
||||
'all_items' => __( 'All Tickers', 'wplt2' ),
|
||||
'parent_item' => __( 'Parent Ticker', 'wplt2' ),
|
||||
'parent_item_colon' => __( 'Parent Ticker:', 'wplt2' ),
|
||||
'edit_item' => __( 'Edit Ticker', 'wplt2' ),
|
||||
'update_item' => __( 'Update Ticker', 'wplt2' ),
|
||||
'add_new_item' => __( 'Add New Ticker', 'wplt2' ),
|
||||
'new_item_name' => __( 'New Ticker', 'wplt2' ),
|
||||
'menu_name' => __( 'Ticker', 'wplt2' ),
|
||||
);
|
||||
|
||||
register_taxonomy('wplt_ticker',array('wplt_tick'), array(
|
||||
'hierarchical' => true,
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
));
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Shortcodes
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( !defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
/**
|
||||
* Allow shortcodes in widgets
|
||||
*/
|
||||
add_filter( 'widget_text', 'do_shortcode' );
|
||||
add_filter( 'wp_ajax_get_new_ticks', array( $this, 'wplt_ajax_get_new_ticks' ) );
|
||||
|
||||
|
||||
/**
|
||||
* Output Liveticker
|
||||
*
|
||||
* @param array atts shortcode options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function wplt_shortcode_ticker_show( $atts ) {
|
||||
global $wplt_options;
|
||||
|
||||
$wplt_options['shortcode_present'] = true;
|
||||
|
||||
/*$wplt_ticker_options = array();
|
||||
|
||||
extract(
|
||||
shortcode_atts( array(
|
||||
'id' => $wplt_ticker_options['id'],
|
||||
'count' => $wplt_ticker_options['count'],
|
||||
'order' => $wplt_ticker_options['order']
|
||||
), $atts )
|
||||
);*/
|
||||
|
||||
if($atts[0])
|
||||
{
|
||||
if(!$atts[1]) $atts[1] = -1;
|
||||
|
||||
$output = '<ul class="wplt_ticker">';
|
||||
|
||||
$args = array( 'post_type' => 'wplt_tick',
|
||||
'posts_per_page' => $atts[1],
|
||||
'tax_query' => array(
|
||||
array( 'taxonomy' => 'wplt_ticker',
|
||||
'field' => 'slug',
|
||||
'terms' => $atts[0]
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_query = new WP_Query($args);
|
||||
|
||||
while ($wp_query->have_posts()) : $wp_query->the_post();
|
||||
$output .= '<li class="wplt_tick">
|
||||
<p><span class="wplt_tick_time">'.get_the_time('d.m.Y H.i').'</span>
|
||||
<span class="wplt_tick_title">'.get_the_title().'</span></p>
|
||||
<p class="wplt_tick_content">'.get_the_content().'</p></li>';
|
||||
endwhile;
|
||||
|
||||
$output .= '</ul>';
|
||||
$output .= '<a href="/feed/liveticker/lager-live"><img class="wplt_rss" src="/wp-content/plugins/wp-liveticker2/images/rss.jpg" alt="RSS" /></a>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
add_shortcode( 'liveticker', 'wplt_shortcode_ticker_show' );
|
@ -1,128 +1,192 @@
|
||||
<?php
|
||||
|
||||
class wplt_widget extends WP_Widget {
|
||||
function wplt_widget() {
|
||||
parent::WP_Widget( false, $name = 'Liveticker' );
|
||||
}
|
||||
function __construct() {
|
||||
parent::__construct( false, $name = 'Liveticker' );
|
||||
}
|
||||
|
||||
function widget( $args, $instance ) {
|
||||
extract( $args );
|
||||
$title = apply_filters( 'wplt_catlit', $instance['title'] );
|
||||
$category = apply_filters( 'wplt_catlit', $instance['category'] );
|
||||
$count = apply_filters( 'wplt_catlit', $instance['count'] );
|
||||
$link = apply_filters( 'wplt_catlit', $instance['link'] );
|
||||
$highlight = apply_filters( 'wplt_catlit', $instance['highlight'] );
|
||||
$highlight_time = apply_filters( 'wplt_catlit', $instance['highlight_time'] );
|
||||
$ajax = apply_filters( 'wplt_catlit', $instance['ajax'] );
|
||||
?>
|
||||
function widget( $args, $instance ) {
|
||||
extract( $args );
|
||||
$title = apply_filters( 'wplt_catlit', $instance['title'] );
|
||||
$category = apply_filters( 'wplt_catlit', $instance['category'] );
|
||||
$count = apply_filters( 'wplt_catlit', $instance['count'] );
|
||||
$link = apply_filters( 'wplt_catlit', $instance['link'] );
|
||||
$highlight = apply_filters( 'wplt_catlit', $instance['highlight'] );
|
||||
$highlight_time = apply_filters( 'wplt_catlit', $instance['highlight_time'] );
|
||||
$ajax = apply_filters( 'wplt_catlit', $instance['ajax'] );
|
||||
?>
|
||||
|
||||
<?php
|
||||
echo $before_widget;
|
||||
?>
|
||||
<?php
|
||||
echo $before_widget;
|
||||
?>
|
||||
|
||||
<?php
|
||||
if ($title) {
|
||||
echo $before_title . $title . $after_title;
|
||||
}
|
||||
|
||||
?>
|
||||
<ul class="wplt_widget">
|
||||
<?php
|
||||
$args = array( 'post_type' => 'wplt_tick',
|
||||
'tax_query' => array(
|
||||
array( 'taxonomy' => 'wplt_ticker',
|
||||
'field' => 'slug',
|
||||
'terms' => $category,
|
||||
)
|
||||
)
|
||||
);
|
||||
<?php
|
||||
if ( $title ) {
|
||||
echo $before_title . $title . $after_title;
|
||||
}
|
||||
|
||||
$wp_query = new WP_Query($args);
|
||||
while ($wp_query->have_posts()) : $wp_query->the_post();
|
||||
?>
|
||||
<li><span class="wplt_widget_time"><?php echo get_the_time('d.m.Y - H.i'); ?></span><span class="wplt_widget_content<?php if($highlight=="1" && get_the_time('U') > (time()-$highlight_time)) echo '_new'; ?>"><br /><?php echo the_title(); ?></span></li>
|
||||
<?php
|
||||
if( $count > 0 && ++$cnt == $count ) break;
|
||||
endwhile;
|
||||
?>
|
||||
</ul>
|
||||
?>
|
||||
<ul class="wplt_widget">
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'wplt_tick',
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'wplt_ticker',
|
||||
'field' => 'slug',
|
||||
'terms' => $category,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
<?php
|
||||
if ($link)
|
||||
print '<p class="wplt_widget_link"><a href="'.$link.'">'.__( 'show all', 'wplt2' ).'...</a></p>';
|
||||
|
||||
echo $after_widget;
|
||||
?>
|
||||
<?php
|
||||
}
|
||||
$wp_query = new WP_Query( $args );
|
||||
while ( $wp_query->have_posts() ) : $wp_query->the_post();
|
||||
?>
|
||||
<li>
|
||||
<span class="wplt_widget_time"><?php echo get_the_time( 'd.m.Y - H.i' ); ?></span><span class="wplt_widget_content<?php if ( $highlight == "1" && get_the_time( 'U' ) > ( time() - $highlight_time ) ) {
|
||||
echo '_new';
|
||||
} ?>"><br /><?php echo the_title(); ?></span></li>
|
||||
<?php
|
||||
if ( $count > 0 && ++ $cnt == $count ) {
|
||||
break;
|
||||
}
|
||||
endwhile;
|
||||
?>
|
||||
</ul>
|
||||
|
||||
function update( $new_instance, $old_instance ) {
|
||||
return $new_instance;
|
||||
}
|
||||
<?php
|
||||
if ( $link ) {
|
||||
print '<p class="wplt_widget_link"><a href="' . $link . '">' . __( 'show all', 'wplt2' ) . '...</a></p>';
|
||||
}
|
||||
|
||||
function form( $instance ) {
|
||||
$title = esc_attr( $instance['title'] );
|
||||
$category = esc_attr( $instance['category'] );
|
||||
$count = esc_attr( $instance['count'] );
|
||||
$link = esc_attr( $instance['link'] );
|
||||
$highlight = esc_attr( $instance['highlight'] );
|
||||
$highlight_time = esc_attr( $instance['highlight_time'] );
|
||||
$ajax = esc_attr( $instance['ajax'] );
|
||||
$categories = get_terms('wplt_ticker', 'orderby=name&order=ASC');
|
||||
?>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label></td>
|
||||
<td><input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> <label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Ticker:', 'wplt2' ); ?></label></td>
|
||||
<td>
|
||||
<select id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>">
|
||||
<?php foreach ($categories as $cat) {
|
||||
echo '<option value="'.$cat->slug.'"'; if($category==$cat->slug) echo ' selected="selected"'; echo '>'.$cat->name.'</option>';
|
||||
} ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e( 'Number of Ticks:', 'wplt2' ); ?></label></td>
|
||||
<td>
|
||||
<select id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>">
|
||||
<option value="0"<?php if($count==0) echo ' selected="selected"' ?>><?php _e('all','wplt2');?></option>
|
||||
<option value="1"<?php if($count==1) echo ' selected="selected"' ?>>1</option><option value="2"<?php if($count==2) echo ' selected="selected"' ?>>2</option>
|
||||
<option value="3"<?php if($count==3) echo ' selected="selected"' ?>>3</option><option value="4"<?php if($count==4) echo ' selected="selected"' ?>>4</option>
|
||||
<option value="5"<?php if($count==5) echo ' selected="selected"' ?>>5</option><option value="6"<?php if($count==6) echo ' selected="selected"' ?>>6</option>
|
||||
<option value="7"<?php if($count==7) echo ' selected="selected"' ?>>7</option><option value="8"<?php if($count==8) echo ' selected="selected"' ?>>8</option>
|
||||
<option value="9"<?php if($count==9) echo ' selected="selected"' ?>>9</option><option value="10"<?php if($count==10) echo ' selected="selected"' ?>>10</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="<?php echo $this->get_field_id( 'link' ); ?>"><?php _e( 'Link (optional):', 'wplt2' ); ?></label></td>
|
||||
<td><input class="widefat" id="<?php echo $this->get_field_id( 'link' ); ?>" name="<?php echo $this->get_field_name( 'link' ); ?>" type="text" value="<?php echo $link; ?>" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="<?php echo $this->get_field_id( 'highlight' ); ?>"><?php _e( 'Highlight new:', 'wplt2' ); ?></label></td>
|
||||
<td><input class="widefat" id="<?php echo $this->get_field_id( 'highlight' ); ?>" name="<?php echo $this->get_field_name( 'highlight' ); ?>" type="checkbox" value="1" <?php if($highlight=="1") echo ' checked="checked"'; ?> /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="<?php echo $this->get_field_id( 'highlight_time' ); ?>"><?php _e( 'Highlight time [s]:', 'wplt2' ); ?></label></td>
|
||||
<td><input class="widefat" id="<?php echo $this->get_field_id( 'highlight_time' ); ?>" name="<?php echo $this->get_field_name( 'highlight_time' ); ?>" type="text" value="<?php echo $highlight_time; ?>" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="<?php echo $this->get_field_id( 'ajax' ); ?>"><?php _e( 'Auto refresh:', 'wplt2' ); ?></label></td>
|
||||
<td><input class="widefat" id="<?php echo $this->get_field_id( 'ajax' ); ?>" name="<?php echo $this->get_field_name( 'ajax' ); ?>" type="checkbox" value="1"<?php if($ajax=="1") echo ' checked="checked"'; ?> disabled="disabled" /> <small><?php _e( '(enables ajax)', 'wplt2' ); ?></small></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
}
|
||||
echo $after_widget;
|
||||
?>
|
||||
<?php
|
||||
}
|
||||
|
||||
function update( $new_instance, $old_instance ) {
|
||||
return $new_instance;
|
||||
}
|
||||
|
||||
function form( $instance ) {
|
||||
$title = esc_attr( $instance['title'] );
|
||||
$category = esc_attr( $instance['category'] );
|
||||
$count = esc_attr( $instance['count'] );
|
||||
$link = esc_attr( $instance['link'] );
|
||||
$highlight = esc_attr( $instance['highlight'] );
|
||||
$highlight_time = esc_attr( $instance['highlight_time'] );
|
||||
$ajax = esc_attr( $instance['ajax'] );
|
||||
$categories = get_terms( 'wplt_ticker', 'orderby=name&order=ASC' );
|
||||
?>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label></td>
|
||||
<td>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Ticker:', 'wplt2' ); ?></label>
|
||||
</td>
|
||||
<td>
|
||||
<select id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>">
|
||||
<?php foreach ( $categories as $cat ) {
|
||||
echo '<option value="' . $cat->slug . '"';
|
||||
if ( $category == $cat->slug ) {
|
||||
echo ' selected="selected"';
|
||||
}
|
||||
echo '>' . $cat->name . '</option>';
|
||||
} ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e( 'Number of Ticks:', 'wplt2' ); ?></label>
|
||||
</td>
|
||||
<td>
|
||||
<select id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>">
|
||||
<option value="0"<?php if ( $count == 0 )
|
||||
echo ' selected="selected"' ?>><?php _e( 'all', 'wplt2' ); ?></option>
|
||||
<option value="1"<?php if ( $count == 1 )
|
||||
echo ' selected="selected"' ?>>1
|
||||
</option>
|
||||
<option value="2"<?php if ( $count == 2 )
|
||||
echo ' selected="selected"' ?>>2
|
||||
</option>
|
||||
<option value="3"<?php if ( $count == 3 )
|
||||
echo ' selected="selected"' ?>>3
|
||||
</option>
|
||||
<option value="4"<?php if ( $count == 4 )
|
||||
echo ' selected="selected"' ?>>4
|
||||
</option>
|
||||
<option value="5"<?php if ( $count == 5 )
|
||||
echo ' selected="selected"' ?>>5
|
||||
</option>
|
||||
<option value="6"<?php if ( $count == 6 )
|
||||
echo ' selected="selected"' ?>>6
|
||||
</option>
|
||||
<option value="7"<?php if ( $count == 7 )
|
||||
echo ' selected="selected"' ?>>7
|
||||
</option>
|
||||
<option value="8"<?php if ( $count == 8 )
|
||||
echo ' selected="selected"' ?>>8
|
||||
</option>
|
||||
<option value="9"<?php if ( $count == 9 )
|
||||
echo ' selected="selected"' ?>>9
|
||||
</option>
|
||||
<option value="10"<?php if ( $count == 10 )
|
||||
echo ' selected="selected"' ?>>10
|
||||
</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="<?php echo $this->get_field_id( 'link' ); ?>"><?php _e( 'Link (optional):', 'wplt2' ); ?></label>
|
||||
</td>
|
||||
<td>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id( 'link' ); ?>" name="<?php echo $this->get_field_name( 'link' ); ?>" type="text" value="<?php echo $link; ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="<?php echo $this->get_field_id( 'highlight' ); ?>"><?php _e( 'Highlight new:', 'wplt2' ); ?></label>
|
||||
</td>
|
||||
<td>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id( 'highlight' ); ?>" name="<?php echo $this->get_field_name( 'highlight' ); ?>" type="checkbox" value="1" <?php if ( $highlight == "1" ) {
|
||||
echo ' checked="checked"';
|
||||
} ?> /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="<?php echo $this->get_field_id( 'highlight_time' ); ?>"><?php _e( 'Highlight time [s]:', 'wplt2' ); ?></label>
|
||||
</td>
|
||||
<td>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id( 'highlight_time' ); ?>" name="<?php echo $this->get_field_name( 'highlight_time' ); ?>" type="text" value="<?php echo $highlight_time; ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="<?php echo $this->get_field_id( 'ajax' ); ?>"><?php _e( 'Auto refresh:', 'wplt2' ); ?></label>
|
||||
</td>
|
||||
<td>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id( 'ajax' ); ?>" name="<?php echo $this->get_field_name( 'ajax' ); ?>" type="checkbox" value="1"<?php if ( $ajax == "1" ) {
|
||||
echo ' checked="checked"';
|
||||
} ?> disabled="disabled" />
|
||||
<small><?php _e( '(enables ajax)', 'wplt2' ); ?></small>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'widgets_init', 'wplt_widget_init' );
|
||||
function wplt_widget_init() {
|
||||
register_widget( 'wplt_widget' );
|
||||
register_widget( 'wplt_widget' );
|
||||
}
|
||||
|
Reference in New Issue
Block a user