PluginProbe
Statify Widget / 1.0
Statify Widget v1.0
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.0, at statify-widget.php

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