PluginProbe
Statify Widget / 1.1.1
Statify Widget v1.1.1
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.1, at statify-widget.php

122 lines 5.8 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.1
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 function StatifyWidget() {
19 $widget_ops = array('classname' => 'statify-widget', 'description' => 'Zeigt beliebte Inhalte auf der Grundlage von Statify.' );
20 $this->WP_Widget('StatifyWidget', 'Statify Widget', $widget_ops);
21 }
22 function form($instance) {
23 $instance = wp_parse_args( (array) $instance, array(
24 'title' => '',
25 'amount' => DEFAULT_AMOUNT,
26 'post_type' => DEFAULT_POST_TYPE,
27 'show_visits' => false ,
28 'suffix' => DEFAULT_SUFFIX) );
29 $title = $instance['title'];
30 $amount = $instance['amount'];
31 $post_type = $instance['post_type'];
32 $show_visits = $instance['show_visits'];
33 $suffix = $instance['suffix'];
34 ?>
35 <p>
36 <label for="<?php echo $this->get_field_id('title'); ?>">Titel:
37 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" />
38 </label>
39 </p>
40 <p>
41 <label for="<?php echo $this->get_field_id('post_type'); ?>">Inhaltstyp:
42 <select class="widefat" id="<?php echo $this->get_field_id('post_type'); ?>" name="<?php echo $this->get_field_name('post_type'); ?>">
43 <?php
44 $post_types = get_post_types( array('public'=>true, 'show_ui'=>true), 'objects' );
45 foreach ( $post_types as $type ) {
46 $selected = ($post_type == $type->name) ? " selected" : "";
47 echo '<option value="'. $type->name . '"'. $selected .'>' . $type->labels->name . '</option>';
48 }
49 ?>
50 </select>
51 </p>
52 <p>
53 <label for="<?php echo $this->get_field_id('amount'); ?>">Anzahl:
54 <input id="<?php echo $this->get_field_id('amount'); ?>" name="<?php echo $this->get_field_name('amount'); ?>" type="text" size="3" value="<?php echo attribute_escape($amount); ?>" />
55 </label>
56 <label for="<?php echo $this->get_field_id('show_visits'); ?>">
57 <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'); ?>" <?php checked($show_visits,'on'); ?>>
58 Aufrufe anzeigen?</label>
59 </p>
60 <p>
61 <label for="<?php echo $this->get_field_id('suffix'); ?>">Benutzerdefinierter Text:
62 <input id="<?php echo $this->get_field_id('suffix'); ?>" class="widefat" name="<?php echo $this->get_field_name('suffix'); ?>" type="text" value="<?php echo attribute_escape($suffix); ?>" />
63 </label>
64 <small>%ANZAHL% = Anzahl der Aufrufe</small>
65 </p>
66 <?php
67 }
68 function update($new_instance, $old_instance) {
69 $instance = array();
70 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
71 $instance['post_type'] = ( ! empty( $new_instance['post_type'] ) ) ? strip_tags( $new_instance['post_type'] ) : '';
72 $instance['amount'] = ( ! empty( $new_instance['amount'] ) ) ? strip_tags( $new_instance['amount'] ) : '';
73 $instance['show_visits'] = ( ! empty( $new_instance['show_visits'] ) ) ? strip_tags( $new_instance['show_visits'] ) : 0;
74 $instance['suffix'] = ( ! empty( $new_instance['suffix'] ) ) ? strip_tags( $new_instance['suffix'] ) : '';
75 return $instance;
76 }
77 function widget($args, $instance) {
78 extract($args, EXTR_SKIP);
79
80 echo $before_widget;
81 $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
82 $amount = empty($instance['amount']) ? DEFAULT_AMOUNT : $instance['amount'];
83 $post_type = empty($instance['post_type']) ? DEFAULT_POST_TYPE : $instance['post_type'];
84 $show_visits = ($instance['show_visits']) ? 1 : 0;
85 $suffix = empty($instance['suffix']) ? DEFAULT_SUFFIX : $instance['suffix'];
86
87 if (!empty($title)) echo $before_title . $title . $after_title;
88
89 $popular_content = Statify_Posts::get_posts($post_type, $amount);
90 if (empty( $popular_content )) {
91 echo "<p>Es gibt noch keine Einträge.</p>";
92 } else {
93 echo '<ol class="statify-widget">'."\n";
94 foreach($popular_content as $post) {
95 $_suffix = ($show_visits) ? ' <span>' . str_replace("%ANZAHL%", $post['visits'], $suffix) . '</span>' : '';
96 echo '<li><a title="' . $post['title']. '" href="' . $post['url'] . '">' . $post['title'] . '</a>'. $_suffix .'</li>'."\n";
97 }
98 echo "</ol>"."\n";
99 }
100
101 echo $after_widget;
102 }
103 }
104 function showErrorMessages() {
105 $html = '<div class="error"><p>';
106 $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' );
107 $html .= '</p></div>';
108 echo $html;
109 }
110 function requires_statify_plugin() {
111 $plugin_bcd_plugin = 'statify/statify.php';
112 $plugin = plugin_basename( __FILE__ );
113 $plugin_data = get_plugin_data( __FILE__, false );
114
115 if ( !is_plugin_active( $plugin_bcd_plugin) ) {
116 deactivate_plugins ( $plugin );
117 add_action('admin_notices', 'showErrorMessages');
118 }
119 }
120 add_action( 'widgets_init', create_function('', 'return register_widget("StatifyWidget");') );
121 add_action( 'admin_init', 'requires_statify_plugin' );
122 ?>