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

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