-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopular-widget.php
138 lines (113 loc) · 4.45 KB
/
popular-widget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/*
Plugin Name: Popular Widget
Plugin URI: http://xparkmedia.com/plugins/popular-widget/
Description: Display most viewed, most commented and tags in one widget (with tabs)
Author: Hafid R. Trujillo Huizar
Version: 1.7.8
Author URI: http://www.xparkmedia.com
Requires at least: 3.0.0
Tested up to: 4.0
Copyright 2011-2013 by Hafid Trujillo http://www.xparkmedia.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License,or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not,write to the Free Software
Foundation,Inc.,51 Franklin St,Fifth Floor,Boston,MA 02110-1301 USA
*/
// Stop direct access of the file
if( !defined( 'ABSPATH' ) )
die( );
if( ! class_exists( 'PopularWidget' )
&& ! class_exists( 'PopularWidgetFunctions' )
&& file_exists( dirname( __FILE__ ) . "/_inc/functions.php" ) ){
include_once( dirname( __FILE__ ) . "/_inc/functions.php" );
class PopularWidget extends PopularWidgetFunctions {
public $tabs = array();
public $version = '1.7.8';
public $defaults = array();
public $current_tab = false;
/**
* Constructor
*
* @return void
* @since 0.5.0
*/
function PopularWidget( ){
$this->load_text_domain( );
$this->PopularWidgetFunctions( );
$this->WP_Widget( 'popular-widget', __( 'Popular Widget', 'pop-wid' ),
array( 'classname' => 'popular-widget', 'description' => __( "Display most popular posts and tags", 'pop-wid' ) )
);
define( 'POPWIDGET_FOLDER', plugin_basename( dirname( __FILE__ ) ) );
define( 'POPWIDGET_ABSPATH', str_replace("\\","/", dirname( __FILE__ ) ) );
define( 'POPWIDGET_URL', plugins_url( POPWIDGET_FOLDER ) . "/" );
$this->defaults = apply_filters( 'pop_defaults_settings', array(
'nocomments' => false, 'nocommented' => false, 'noviewed' => false, 'norecent' => false, 'noadvanced' => false,
'userids' => false, 'imgsize' => 'thumbnail', 'counter' => false, 'excerptlength' => 15, 'tlength' => 20,
'meta_key' => '_popular_views', 'calculate' => 'visits', 'title' => '', 'limit'=> 5, 'cats'=>'', 'lastdays' => 90,
'taxonomy' => 'post_tag', 'exclude_users' => false, 'posttypes' => array( 'post' => 'on' ), 'thumb' => false,
'excerpt' => false, 'notags'=> false, 'exclude_cats' => false, 'rel' => 'bookmark',
) );
$this->tabs = apply_filters( 'pop_defaults_tabs', array(
'recent' => __( 'Recent Posts', 'pop-wid' ) ,
'comments' => __( 'Recent Comments', 'pop-wid' ) ,
'commented' => __( 'Most Commented', 'pop-wid' ),
'viewed' => __( 'Most Viewed', 'pop-wid' ),
'tags' => __( 'Tags', 'pop-wid' ),
'advanced' => __('Advanced', 'pop-wid')
) );
}
/**
* Display widget.
*
* @param array $args
* @param array $instance
* @return void
* @since 0.5.0
*/
function widget( $args, $instance ) {
if( file_exists( POPWIDGET_ABSPATH . '/_inc/widget.php' ) )
include( POPWIDGET_ABSPATH . '/_inc/widget.php' );
}
/**
* Configuration form.
*
* @param array $instance
* @return void
* @since 0.5.0
*/
function form( $instance ) {
if( file_exists( POPWIDGET_ABSPATH . '/_inc/form.php' ) )
include( POPWIDGET_ABSPATH . '/_inc/form.php' );
}
/**
* Display widget.
*
* @param array $instance
* @return array
* @since 1.5.6
*/
function update( $new_instance, $old_instance ){
foreach( $new_instance as $key => $val ){
if( is_array( $val ) )
$new_instance[$key] = $val;
elseif( in_array( $key, array( 'lastdays', 'limit', 'tlength', 'excerptlength' ) ) )
$new_instance[$key] = intval( $val );
elseif( in_array( $key,array( 'calculate', 'imgsize', 'cats', 'userids', 'title', 'meta_key' ) ) )
$new_instance[$key] = trim( $val,',' );
}
if( empty($new_instance['meta_key'] ) )
$new_instance['meta_key'] = $this->defaults['meta_key'];
return $new_instance;
}
}
// do that thing you do!
add_action( 'widgets_init' , create_function( '', 'return register_widget("PopularWidget");' ) );
}//end if