This repository was archived by the owner on Sep 29, 2021. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathgoogleCards.php
More file actions
218 lines (200 loc) · 7.7 KB
/
Copy pathgoogleCards.php
File metadata and controls
218 lines (200 loc) · 7.7 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/*
Plugin Name: googleCards
Plugin URI: http://plusdevs.com/google-wordpress-plugin/
Description: Adds google+ contact card widget to your blog
Version: 0.4.7
Author: Mabujo
Author URI: http://plusdevs.com
License: GPL3
*/
/*
* Copyright (C) 2011 Mabujo
* http://plusdevs.com
* http://plusdevs.com/googlecard-googleplus-php-scraper/
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
define( 'GOOGLECARD_PLUGIN_NAME', 'googleCards');
define( 'GOOGLECARD_PLUGIN_DIRECTORY', 'googlecards');
define( 'GOOGLECARD_CURRENT_VERSION', '0.4.7' );
define( 'GOOGLECARD_DEBUG', false);
// test whether we can write to the cache directory or not
function gc_caching()
{
if (!is_dir(WP_CONTENT_DIR . "/cache"))
{
mkdir (WP_CONTENT_DIR . "/cache", 0777, true);
}
if (is_dir(WP_CONTENT_DIR . "/cache") && is_writable(WP_CONTENT_DIR . "/cache"))
{
$cache = WP_CONTENT_DIR . "/cache/plus_cards.txt";
return true;
}
else
{
return false;
}
}
function googleCards($plus_id, $credit=1, $author, $blank)
{
// include our scraper class
include_once('googleCardClass.php');
// initiate an instance of our scraper class
$plus = new googleCard($plus_id);
// if we can use file caching
if (gc_caching())
{
$plus->cache_data = 1;
$plus->cache_file = WP_CONTENT_DIR . "/cache/plus_cards.txt";
}
// do the scrape
$data = $plus->googleCard();
if (isset($data) && !empty($data['name']) && !empty($data['img']))
{
// setup rel=author and target=blank options
$rel = '';
if(isset($author) && $author > 0)
{
$rel = 'rel="author"';
}
else
{
$rel = '';
}
$tab = '';
if(isset($blank) && $blank > 0)
{
$tab = 'target="_blank"';
}
else
{
$tab = '';
}
?>
<div id="plus_card">
<div id="plus_card_image">
<a <?php echo $rel; ?> href="<?php echo $data['url']; ?>" <?php echo $tab; ?>>
<?php echo '<img src="' . $data['img'] . '" width="80" height="80" />'; ?>
</a>
</div>
<div id="plus_card_name">
<a <?php echo $rel; ?> href="<?php echo $data['url']; ?>" <?php echo $tab; ?>><?php echo $data['name'] ?></a>
</div>
<span id="plus_card_add">
<a <?php echo $rel; ?> href="<?php echo $data['url']; ?>" <?php echo $tab; ?>>Add to circles</a>
</span>
<div id="plusCardCount">
<p>In <?php if (isset($data['count'])) { echo $data['count']; } else { echo 0; } ?> people's circles</p>
</div>
<?php
if (isset($credit) && $credit > 0)
{
?>
<div id="plusCardCredit">
<p>Google+ card by <a href="http://plusdevs.com" <?php echo $tab; ?>>plusdevs</a></p>
</div>
<span id="plusCardShowHide" onclick="togglePlusCredit()">+i</span>
<?php
}
?>
<?php echo '<!--gcVersion = ' . GOOGLECARD_CURRENT_VERSION . ' -->'; ?>
</div>
<?php
}
// else show an error
else
{
echo 'Couldn\'t get data from google+';
echo '<!--gcVersion = ' . GOOGLECARD_CURRENT_VERSION . ' -->';
}
}
class GoogleCardsWidget extends WP_Widget {
/** constructor */
function GoogleCardsWidget() {
parent::WP_Widget(false, $name = 'GoogleCard');
$css = '/wp-content/plugins/googlecards/css/googleCards.css';
wp_enqueue_style('googleCards', $css);
$js = '/wp-content/plugins/googlecards/js/googleCards.min.js';
wp_enqueue_script('googleCards', $js);
}
/** @see WP_Widget::widget */
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
?>
<?php echo $before_widget; ?>
<?php if ( $title )
echo $before_title . $title . $after_title; ?>
<?php googleCards($instance['plus_id'], $instance['credit'], $instance['author'], $instance['blank']); ?>
<?php echo $after_widget; ?>
<?php
}
/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['plus_id'] = strip_tags($new_instance['plus_id']);
$instance['credit'] = ( isset( $new_instance['credit'] ) ? 1 : 0 );
$instance['author'] = ( isset( $new_instance['author'] ) ? 1 : 0 );
$instance['blank'] = ( isset( $new_instance['blank'] ) ? 1 : 0 );
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
$title = 'Follow me on Google+';
$plus_id = '';
$credit = true;
$author = false;
$blank = false;
if ($instance) {
$title = esc_attr($instance['title']);
$plus_id = esc_attr($instance['plus_id']);
$credit = isset($instance['credit']) ? $instance['credit'] : true;
$author = isset($instance['author']) ? $instance['author'] : true;
$blank = isset($instance['blank']) ? $instance['blank'] : true;
}
else
{
$defaults = array('title' => 'Follow me on Google+', 'plus_id' => '', 'credit' => 'true');
$instance = wp_parse_args( (array) $instance, $defaults );
}
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('plus_id'); ?>"><?php _e('Google Plus ID:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('plus_id'); ?>" name="<?php echo $this->get_field_name('plus_id'); ?>" type="text" value="<?php echo $plus_id; ?>" />
</p>
<p>
<?php (isset($instance['credit']) && $instance['credit'] == true) ? $color = 'green' : $color = 'red'; ?>
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['credit'], true ); ?> id="<?php echo $this->get_field_id( 'credit' ); ?>" name="<?php echo $this->get_field_name( 'credit' ); ?>" />
<label for="<?php echo $this->get_field_id( 'credit' ); ?>"><?php _e('Show developer credit '); ?><abbr style="border-bottom: 1px dotted black; color:<?php echo $color;?>; font-weight:bold;" title="Whether to show the 'Google+ card by plusdevs' message when a user clicks on '+i'. You don't have to leave this enabled but it is the best way for other people to find out about this plugin (which we've worked very hard on!) and we promise to love you forever if you do. The message is inobtrusive, your circles are always shown.">?</abbr></label>
</p>
<p>
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['author'], true ); ?> id="<?php echo $this->get_field_id( 'author' ); ?>" name="<?php echo $this->get_field_name( 'author' ); ?>" />
<label for="<?php echo $this->get_field_id( 'author' ); ?>"><?php _e('Add rel="author" to links?'); ?></label>
</p>
<p>
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['blank'], true ); ?> id="<?php echo $this->get_field_id( 'blank' ); ?>" name="<?php echo $this->get_field_name( 'blank' ); ?>" />
<label for="<?php echo $this->get_field_id( 'blank' ); ?>"><?php _e('Open links in new window/tab?'); ?></label>
</p>
<?php
}
} // class GoogleCardsWidget
// register GoogleCardsWidget widget
add_action('widgets_init', create_function('', 'return register_widget("GoogleCardsWidget");'));
?>