-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadygraph.php
More file actions
154 lines (133 loc) · 5.04 KB
/
Copy pathreadygraph.php
File metadata and controls
154 lines (133 loc) · 5.04 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
<?php
/*
Plugin Name: ReadyGraph
Plugin URI: http://www.readygraph.com/
Version: 1.0.5
Author: ReadyGraph team
Description: ReadyGraph is a simple friend invite tool that drives large number of traffic to your site
Author URI: http://www.readygraph.com/
*/
// plugin updater
include_once('updater.php');
if (is_admin()) {
$config = array(
'slug' => plugin_basename(__FILE__),
'proper_folder_name' => 'readygraph',
'source_folder_name' => '',
'api_url' => 'https://api.github.com/repos/baddth/readygraph-wordpress',
'raw_url' => 'https://raw.github.com/baddth/readygraph-wordpress/master',
'github_url' => 'https://github.com/baddth/readygraph-wordpress',
'zip_url' => 'https://github.com/baddth/readygraph-wordpress/zipball/master',
'sslverify' => true,
'requires' => '3.0',
'tested' => '3.5',
'readme' => 'README.md',
'access_token' => ''
);
new WP_GitHub_Updater($config);
}
class ReadyGraphSocialPlugins {
function ReadyGraphSocialPlugins() {
add_action('admin_menu', array(&$this, 'rg_create_menu'));
add_action('wp_head', array(&$this, 'rg_script_head'));
add_filter('the_content', array(&$this, 'rg_content_filter'), 10000);
add_filter('post_thumbnail_html', array(&$this, 'rg_post_thumbnail_filter'), 10000);
#add_filter('post_gallery', array(&$this, 'rg_gallery_filter'), 10000);
}
function rg_script_head() {
$app_id = get_option('rg_application_id');
if ($app_id === false) {
return;
}
?>
<script type="text/javascript" src="//www.readygraph.com/scripts/readygraph.js"></script>
<script type="text/javascript">
ReadyGraph.setup({applicationId: '<?php echo $app_id; ?>', overrideFacebookSDK: true});
console.log('<?php echo get_the_title(); ?>');
</script>
<?php
}
function rg_post_thumbnail_filter($content) {
$full_content = apply_filters('the_content', get_the_content());
return $this->replace_content ($content, $this->extract_description($full_content));
}
function rg_content_filter($content) {
return $this->replace_content ($content, $this->extract_description($content));
}
function rg_gallery_filter($output) {
$description = $this->extract_description($output);
if (trim($description) == '') $description = $this->extract_description(the_content());
return $this->replace_content ($output, $description);
}
function extract_description($content) {
$content = preg_replace ('/<script.*?\/script>/is', '', $content);
$content = preg_replace ('/<style.*?\/style>/is', '', $content);
$description = strip_tags($content);
$description = substr(trim($description), 0, 250);
return $description;
}
function replace_content($content, $description) {
preg_match_all ( '/<img [^>]*>/ims',$content, $images );
foreach ( $images[0] as $image) {
$class = preg_replace ('/.*class="([^"]*)/i', '\\1', $image);
if ($class == $image) $class = '';
if (strpos($class, 'rgw-picture-og') !== false) continue;
$src = preg_replace ('/.*src="([^"]*)/i', '\\1', $image);
if ($src == $image) $src = '';
$rgw_data = 'rgw-data-title="'.htmlentities(get_the_title()).'" rgw-data-description="'.htmlentities($description).'" rgw-data-url="'.htmlentities(get_permalink()).'"';
$replace = $image;
if ($src != '') {
if ($class == '') {
$replace = preg_replace ('/class="([^"]*)/i', $rgw_data.' class="\\1 rgw-picture-og', $replace);
}
else {
$replace = preg_replace ('/src="([^"]*)/i', 'src="\\1" '.$rgw_data.' class="rgw-picture-og', $replace);
}
}
$content = str_replace ($image, $replace, $content);
}
return $content;
}
function rg_create_menu() {
//create new top-level menu
add_menu_page('ReadyGraph', 'ReadyGraph', 'administrator', __FILE__, array(&$this, 'rg_settings_page'), plugins_url('/images/rg_logo_sml.png', __FILE__));
//call register settings function
add_action( 'admin_init', array(&$this, 'rg_register_mysettings'));
}
function rg_register_mysettings() {
//register our settings
register_setting( 'rg-settings-group', 'rg_application_id' );
}
function rg_settings_page() {
?>
<div class="wrap">
<h2>ReadyGraph Setting</h2>
<form method="post" action="options.php">
<?php settings_fields( 'rg-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<td scope="row" colspan="2">
To learn more about ReadyGraph™, please visit <a href="http://www.readygraph.com" target="_blank">http://www.readygraph.com</a>
</td>
</tr>
<tr valign="top">
<th scope="row">ReadyGraph™ Application ID</th>
<td>
<input type="text" name="rg_application_id" value="<?php echo get_option('rg_application_id'); ?>" />
</td>
</tr>
<tr valign="top">
<td scope="row" colspan="2">
<hr/>
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
</div>
<?php
}
}
add_action('init', create_function('', '$widget = new ReadyGraphSocialPlugins();'));
?>