PluginProbe
Statify Widget / 1.1.3
Statify Widget v1.1.3
trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 All 39 releases
statify-widget / statify-widget.php

statify-widget.php in Statify Widget 1.1.3, at statify-widget.php

151 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Statify Widget: Beliebte Inhalte
4 Description: Widget für populäre Seiten, Artikel und andere Inhaltstypen auf der Grundlage des datenschutzkonformen Statistik Plugin Statify von Sergej Müller.
5 Author: Finn Dohrn
6 Author URI: http://www.bit01.de/
7 Plugin URI: http://www.bit01.de/blog/statify-widget/
8 Version: 1.1.3
9 */
10
11 require( 'Statify_Posts.class.php' );
12
13 define('DEFAULT_AMOUNT', 5);
14 define('DEFAULT_POST_TYPE','post');
15 define('DEFAULT_SUFFIX', '(%ANZAHL% Aufrufe)');
16
17 class StatifyWidget extends WP_Widget {
18 /*
19 * Register StatifyWidget to Wordpress
20 */
21 function __construct() {
22 $widget_ops = array('classname' => 'statify-widget', 'description' => 'Zeigt beliebte Inhalte auf der Grundlage von Statify.' );
23 parent::__construct(
24 'StatifyWidget',
25 __('Statify Widget', 'text_domain'),
26 $widget_ops
27 );
28 }
29
30 /*
31 * Generating a from for settings
32 */
33 function form($instance) {
34 $instance = wp_parse_args( (array) $instance, array(
35 'title' => '',
36 'amount' => DEFAULT_AMOUNT,
37 'post_type' => DEFAULT_POST_TYPE,
38 'show_visits' => 0,
39 'suffix' => DEFAULT_SUFFIX) );
40 $title = $instance['title'];
41 $amount = $instance['amount'];
42 $post_type = $instance['post_type'];
43 $show_visits = $instance['show_visits'];
44 $suffix = $instance['suffix'];
45 ?>
46 <p>
47 <label for="<?php echo $this->get_field_id('title'); ?>">Titel:
48 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
49 </label>
50 </p>
51 <p>
52 <label for="<?php echo $this->get_field_id('post_type'); ?>">Inhaltstyp:
53 <select class="widefat" id="<?php echo $this->get_field_id('post_type'); ?>" name="<?php echo $this->get_field_name('post_type'); ?>">
54 <?php
55 $post_types = get_post_types( array('public'=>true, 'show_ui'=>true), 'objects' );
56 foreach ( $post_types as $type ) {
57 echo '<option value="'. esc_attr($type->name) . '" '. selected( $post_type, $type->name ) .'>' . esc_attr($type->labels->name) . '</option>';
58 }
59 ?>
60 </select>
61 </p>
62 <p>
63 <label for="<?php echo $this->get_field_id('amount'); ?>">Anzahl:
64 <input id="<?php echo $this->get_field_id('amount'); ?>" name="<?php echo $this->get_field_name('amount'); ?>" type="text" size="3" value="<?php echo esc_attr($amount); ?>" />
65 </label>
66 <label for="<?php echo $this->get_field_id('show_visits'); ?>">
67 <input class="checkbox widget-description" style="margin-left:15px;" type="checkbox" id="<?php echo $this->get_field_id('show_visits'); ?>" name="<?php echo $this->get_field_name('show_visits'); ?>" value="1" <?php checked($show_visits,1); ?>>
68 Aufrufe anzeigen?</label>
69 </p>
70 <p>
71 <label for="<?php echo $this->get_field_id('suffix'); ?>">Benutzerdefinierter Text:
72 <input id="<?php echo $this->get_field_id('suffix'); ?>" class="widefat" name="<?php echo $this->get_field_name('suffix'); ?>" type="text" value="<?php echo esc_attr($suffix); ?>" />
73 </label>
74 <small>%ANZAHL% = Anzahl der Aufrufe</small>
75 </p>
76 <?php
77 }
78
79 /*
80 * Override old instance with new instance.
81 */
82 function update($new_instance, $old_instance) {
83 $instance = array();
84 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : '';
85 $instance['post_type'] = ( ! empty( $new_instance['post_type'] ) ) ? $new_instance['post_type'] : DEFAULT_POST_TYPE;
86 $instance['amount'] = ( ! empty( $new_instance['amount'] ) ) ? sanitize_text_field( $new_instance['amount'] ) : DEFAULT_AMOUNT;
87 $instance['show_visits'] = ( ! empty( $new_instance['show_visits'] ) ) ? $new_instance['show_visits'] : 0;
88 $instance['suffix'] = ( ! empty( $new_instance['suffix'] ) ) ? sanitize_text_field( $new_instance['suffix'] ) : DEFAULT_SUFFIX;
89 return $instance;
90 }
91
92 /*
93 * Print the widget
94 */
95 function widget($args, $instance) {
96 extract($args, EXTR_SKIP);
97
98 echo $before_widget;
99
100 $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
101 $amount = empty($instance['amount']) ? DEFAULT_AMOUNT : $instance['amount'];
102 $post_type = empty($instance['post_type']) ? DEFAULT_POST_TYPE : $instance['post_type'];
103 $show_visits = empty($instance['show_visits']) ? 0 : 1;
104 $suffix = empty($instance['suffix']) ? DEFAULT_SUFFIX : $instance['suffix'];
105
106 if (!empty($title)) echo $before_title . $title . $after_title;
107
108 $popular_content = Statify_Posts::get_posts($post_type, $amount);
109 if (empty( $popular_content )) {
110 echo "<p>Es gibt noch keine Einträge.</p>";
111 } else {
112 echo '<ol class="statify-widget">'."\n";
113 foreach($popular_content as $post) {
114 $_suffix = ($show_visits) ? ' <span>' . str_replace("%ANZAHL%", intval($post['visits']), $suffix) . '</span>' : '';
115 echo '<li><a title="' . esc_html($post['title']) . '" href="' . esc_url($post['url']) . '">' . esc_html($post['title']) . '</a>'. $_suffix .'</li>'."\n";
116 }
117 echo "</ol>"."\n";
118 }
119
120 echo $after_widget;
121 }
122 }
123
124 /*
125 * Print error message in admin interface
126 */
127 function showErrorMessages() {
128 $html = '<div class="error"><p>';
129 $html .= __( 'Bitte installieren und aktivieren Sie zuerst das <a target="_blank" href="http://wordpress.org/plugins/statify/">Statify</a> Plugin von Sergej M&uuml;ller.', 'error-statify-widget' );
130 $html .= '</p></div>';
131 echo $html;
132 }
133
134 /*
135 * Check if Statify is acitivated
136 */
137 function requires_statify_plugin() {
138 $plugin_bcd_plugin = 'statify/statify.php';
139 $plugin = plugin_basename( __FILE__ );
140 $plugin_data = get_plugin_data( __FILE__, false );
141
142 if ( !is_plugin_active( $plugin_bcd_plugin) ) {
143 deactivate_plugins ( $plugin );
144 add_action('admin_notices', 'showErrorMessages');
145 }
146 }
147
148 add_action( 'widgets_init', create_function('', 'return register_widget("StatifyWidget");') );
149 add_action( 'admin_init', 'requires_statify_plugin' );
150 ?>
151