-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-camp-webring.php
140 lines (118 loc) · 3.31 KB
/
wp-camp-webring.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
139
140
<?php
/**
* Plugin Name: WP Camp Webring
* Description: We do a webring of pages that are attending to the WP Camp in Germany like it's 1997
* Version: 0.3.10
*/
if ( ! class_exists( 'wp_camp_webring' ) ) {
add_action( 'plugins_loaded', array( 'wp_camp_webring', 'get_object' ) );
class wp_camp_webring {
/**
* The class object
*
* @static
* @since 0.1
* @var string
*/
static private $classobj = NULL;
/**
* The array of the blogs participating in the webring
*
* @since 0.2
* @var array
*/
public $blogs = array();
/**
* The home_url of the blog
*
* @since 0.2
* @var string
*/
public $home_url = NULL;
/**
* Constructor, init on defined hooks of WP and include second class
*
* @access public
* @since 0.1
* @uses add_filter, home_url, shuffle
* @return void
*/
public function __construct() {
$this->home_url = home_url();
// set the blogs array and shuffle it
$this->blogs = array(
'http://blog.drivingralle.de',
'http://danielhuesken.de',
'http://deckerweb.de',
'http://dunkelangst.org',
'http://heikomamerow.de',
'http://hofmannsven.com',
#'http://janreimers.net',
'http://kau-boys.de',
'http://n1da.net',
#'http://pixelmagic.eu/blog/',
#'http://rottig.de',
'http://stefankremer.de',
'http://wpmeetup-berlin.de',
#'http://wpmeetup-hamburg.de',
'http://www.atelier-leonhardt.com',
'http://www.besseronlineblog.de',
'http://www.keksbox.com/microblog/',
#'http://www.opas-blog.de',
);
shuffle( $this->blogs );
// show the webring in footer
add_filter( 'wp_footer', array( $this, 'display_webring' ) );
add_filter( 'wp_enqueue_scripts', array( $this, 'load_style' ) );
}
/**
* Handler for the action 'init'. Instantiates this class.
*
* @access public
* @since 0.1
* @return object $classobj
*/
public function get_object() {
if ( NULL === self::$classobj ) {
self::$classobj = new self;
}
return self::$classobj;
}
/**
* display the webring and choose two random blogs
*
* @access public
* @since 0.1
* @uses get_blog_url
* @return void
*/
public function display_webring() {
?><div class="wp-camp-webring"><a href="<?php echo $this->get_blog_url(); ?>" class="wp-camp-webring-prev">◄</a> <a href="http://wpcamp.de/teilnehmerliste" class="wp-camp-webring-list">WP Camp Webring</a> <a href="<?php echo $this->get_blog_url(); ?>" class="wp-camp-webring-next">►</a></div><?php
}
/**
* Load frontend CSS
*
* @access public
* @since 0.1
* @uses get_blog_url
* @return void
*/
public function load_style() {
wp_enqueue_style( 'wp-camp-webring', plugins_url( 'wp-camp-webring.css', __FILE__ ) );
}
/**
* Get a blog URL from the blogs array excluding the blog matching the home_url
*
* @access public
* @since 0.2
* @uses array_shift
* @return string $blog_url
*/
public function get_blog_url() {
$blog_url = array_shift( $this->blogs );
if ( parse_url( $blog_url, PHP_URL_HOST ) == parse_url( $this->home_url, PHP_URL_HOST ) )
$blog_url = array_shift( $this->blogs );
return $blog_url;
}
} // end class
} // end if class exists