Open Graph for Facebook, Google+ and Twitter Card Tags - Version 1.5

Version Description

  • Each time a post/page is saved we try to update/purge Facebook Open Graph Tags cache so you can share it right away from the post edit screen
  • Forced Excertps support on Pages so that it can be used as the post description
  • Added HTTP REFERER and USER AGENT to the cURL calls when trying to get image size by url
  • Fix: Some validations when trying to get image size by url
  • Fix: A lot of php notices and warnings were supressed
Download this release

Release Info

Developer webdados
Plugin Icon Open Graph for Facebook, Google+ and Twitter Card Tags
Version 1.5
Comparing to
See all releases

Code changes from version 1.4.2 to 1.5

Files changed (3) hide show
  1. includes/settings-page.php +81 -59
  2. readme.txt +8 -2
  3. wonderm00n-open-graph.php +198 -136
includes/settings-page.php CHANGED
@@ -15,68 +15,70 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
15
  if ( isset($_POST['action']) ) {
16
  if (trim($_POST['action'])=='save') {
17
  //This should also use the $wonderm00n_open_graph_plugin_settings array, but because of intval and trim we still can't
18
- $usersettings['fb_app_id_show']= intval(wonderm00n_open_graph_post('fb_app_id_show'));
19
- $usersettings['fb_app_id']= trim(wonderm00n_open_graph_post('fb_app_id'));
20
- $usersettings['fb_admin_id_show']= intval(wonderm00n_open_graph_post('fb_admin_id_show'));
21
- $usersettings['fb_admin_id']= trim(wonderm00n_open_graph_post('fb_admin_id'));
22
- $usersettings['fb_locale_show']= intval(wonderm00n_open_graph_post('fb_locale_show'));
23
- $usersettings['fb_locale']= trim(wonderm00n_open_graph_post('fb_locale'));
24
- $usersettings['fb_sitename_show']= intval(wonderm00n_open_graph_post('fb_sitename_show'));
25
- $usersettings['fb_title_show']= intval(wonderm00n_open_graph_post('fb_title_show'));
26
- $usersettings['fb_title_show_schema']= intval(wonderm00n_open_graph_post('fb_title_show_schema'));
27
- $usersettings['fb_title_show_twitter']= intval(wonderm00n_open_graph_post('fb_title_show_twitter'));
28
- $usersettings['fb_url_show']= intval(wonderm00n_open_graph_post('fb_url_show'));
29
- $usersettings['fb_url_show_twitter']= intval(wonderm00n_open_graph_post('fb_url_show_twitter'));
30
- $usersettings['fb_url_canonical']= intval(wonderm00n_open_graph_post('fb_url_canonical'));
31
- $usersettings['fb_url_add_trailing']= intval(wonderm00n_open_graph_post('fb_url_add_trailing'));
32
- $usersettings['fb_type_show']= intval(wonderm00n_open_graph_post('fb_type_show'));
33
- $usersettings['fb_type_homepage']= trim(wonderm00n_open_graph_post('fb_type_homepage'));
34
- $usersettings['fb_article_dates_show']= intval(wonderm00n_open_graph_post('fb_article_dates_show'));
35
- $usersettings['fb_article_sections_show']= intval(wonderm00n_open_graph_post('fb_article_sections_show'));
36
- $usersettings['fb_publisher_show']= intval(wonderm00n_open_graph_post('fb_publisher_show'));
37
- $usersettings['fb_publisher']= trim(wonderm00n_open_graph_post('fb_publisher'));
38
- $usersettings['fb_publisher_show_schema']= intval(wonderm00n_open_graph_post('fb_publisher_show_schema'));
39
- $usersettings['fb_publisher_schema']= trim(wonderm00n_open_graph_post('fb_publisher_schema'));
40
- $usersettings['fb_publisher_show_twitter']= intval(wonderm00n_open_graph_post('fb_publisher_show_twitter'));
41
- $usersettings['fb_publisher_twitteruser']= trim(wonderm00n_open_graph_post('fb_publisher_twitteruser'));
42
- $usersettings['fb_author_show']= intval(wonderm00n_open_graph_post('fb_author_show'));
43
- $usersettings['fb_author_show_meta']= intval(wonderm00n_open_graph_post('fb_author_show_meta'));
44
- $usersettings['fb_author_show_linkrelgp']= intval(wonderm00n_open_graph_post('fb_author_show_linkrelgp'));
45
- $usersettings['fb_author_show_twitter']= intval(wonderm00n_open_graph_post('fb_author_show_twitter'));
46
- $usersettings['fb_desc_show']= intval(wonderm00n_open_graph_post('fb_desc_show'));
47
- $usersettings['fb_desc_show_meta']= intval(wonderm00n_open_graph_post('fb_desc_show_meta'));
48
- $usersettings['fb_desc_show_schema']= intval(wonderm00n_open_graph_post('fb_desc_show_schema'));
49
- $usersettings['fb_desc_show_twitter']= intval(wonderm00n_open_graph_post('fb_desc_show_twitter'));
50
- $usersettings['fb_desc_chars']= intval(wonderm00n_open_graph_post('fb_desc_chars'));
51
- $usersettings['fb_desc_homepage']= trim(wonderm00n_open_graph_post('fb_desc_homepage'));
52
- $usersettings['fb_desc_homepage_customtext']= trim(wonderm00n_open_graph_post('fb_desc_homepage_customtext'));
53
- $usersettings['fb_image_show']= intval(wonderm00n_open_graph_post('fb_image_show'));
54
- $usersettings['fb_image_show_schema']= intval(wonderm00n_open_graph_post('fb_image_show_schema'));
55
- $usersettings['fb_image_show_twitter']= intval(wonderm00n_open_graph_post('fb_image_show_twitter'));
56
- $usersettings['fb_image']= trim(wonderm00n_open_graph_post('fb_image'));
57
- $usersettings['fb_image_rss']= intval(wonderm00n_open_graph_post('fb_image_rss'));
58
- $usersettings['fb_image_use_specific']= intval(wonderm00n_open_graph_post('fb_image_use_specific'));
59
- $usersettings['fb_image_use_featured']= intval(wonderm00n_open_graph_post('fb_image_use_featured'));
60
- $usersettings['fb_image_use_content']= intval(wonderm00n_open_graph_post('fb_image_use_content'));
61
- $usersettings['fb_image_use_media']= intval(wonderm00n_open_graph_post('fb_image_use_media'));
62
- $usersettings['fb_image_use_default']= intval(wonderm00n_open_graph_post('fb_image_use_default'));
63
- $usersettings['fb_show_wpseoyoast']= intval(wonderm00n_open_graph_post('fb_show_wpseoyoast'));
64
- $usersettings['fb_show_subheading']= intval(wonderm00n_open_graph_post('fb_show_subheading'));
65
- $usersettings['fb_show_businessdirectoryplugin']= intval(wonderm00n_open_graph_post('fb_show_businessdirectoryplugin'));
66
- $usersettings['fb_adv_force_local']= intval(wonderm00n_open_graph_post('fb_adv_force_local'));
 
 
67
  //Update
68
- update_option('webdados_fb_open_graph_settings', $usersettings);
69
  }
70
  }
71
 
72
  //Load the settings
73
- extract(wonderm00n_open_graph_load_settings());
74
 
75
  ?>
76
  <div class="wrap">
77
 
78
  <?php screen_icon(); ?>
79
- <h2><?php echo $wonderm00n_open_graph_plugin_name; ?> (<?php echo $wonderm00n_open_graph_plugin_version; ?>)</h2>
80
  <br class="clear"/>
81
  <p><?php _e('Please set some default values and which tags should, or should not, be included. It may be necessary to exclude some tags if other plugins are already including them.', 'wd-fb-og'); ?></p>
82
 
@@ -88,7 +90,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
88
  <div id="poststuff">
89
  <form name="form1" method="post">
90
 
91
- <div id="wonderm00n_open_graph-settings" class="postbox">
92
  <h3 id="settings"><?php _e('Settings'); ?></h3>
93
  <div class="inside">
94
  <table width="100%" class="form-table">
@@ -549,7 +551,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
549
  </div>
550
  </div>
551
 
552
- <div id="wonderm00n_open_graph-thirdparty" class="postbox">
553
  <h3 id="thirdparty"><?php _e('3rd Party Integration', 'wd-fb-og');?></h3>
554
  <div class="inside">
555
  <?php
@@ -621,7 +623,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
621
  </div>
622
  </div>
623
 
624
- <div id="wonderm00n_open_graph-advanced" class="postbox">
625
  <h3 id="advanced"><?php _e('Advanced settings', 'wd-fb-og');?></h3>
626
  <div class="inside">
627
  <p><?php _e('Don\'t mess with this unless you know what you\'re doing', 'wd-fb-og');?></p>
@@ -634,6 +636,18 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
634
  <?php _e('May cause problems with some multisite configurations but fix "HTTP request failed" errors', 'wd-fb-og');?>
635
  </td>
636
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
637
  </table>
638
  </div>
639
  </div>
@@ -678,7 +692,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
678
  <div class="postbox-container og_right_col">
679
 
680
  <div id="poststuff">
681
- <div id="wonderm00n_open_graph_links" class="postbox">
682
  <h3 id="settings"><?php _e('Rate this plugin', 'wd-fb-og');?></h3>
683
  <div class="inside">
684
  <?php _e('If you like this plugin,', 'wd-fb-og');?> <a href="http://wordpress.org/extend/plugins/wonderm00ns-simple-facebook-open-graph-tags/" target="_blank"><?php _e('please give it a high Rating', 'wd-fb-og');?></a>.
@@ -687,7 +701,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
687
  </div>
688
 
689
  <div id="poststuff">
690
- <div id="wonderm00n_open_graph_links" class="postbox">
691
  <h3 id="settings"><?php _e('Useful links', 'wd-fb-og');?></h3>
692
  <div class="inside">
693
  <ul>
@@ -700,7 +714,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
700
  </div>
701
 
702
  <div id="poststuff">
703
- <div id="wonderm00n_open_graph_donation" class="postbox">
704
  <h3 id="settings"><?php _e('Donate', 'wd-fb-og');?></h3>
705
  <div class="inside">
706
  <p><?php _e('If you find this plugin useful and want to make a contribution towards future development please consider making a small, or big ;-), donation.', 'wd-fb-og');?></p>
@@ -733,7 +747,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
733
  tb_show('',"media-upload.php?type=image&TB_iframe=true");
734
  });
735
  window.send_to_editor = function(html) {
736
- imgurl = jQuery('img',html).attr('src');
737
  jQuery("input"+"#fb_image").val(imgurl);
738
  tb_remove();
739
  }
@@ -753,6 +767,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
753
  jQuery('#fb_desc_homepage_customtext').hide();
754
  showDescriptionCustomText();
755
  showImageOptions();
 
756
  });
757
  function showAppidOptions() {
758
  if (jQuery('#fb_app_id_show').is(':checked')) {
@@ -864,6 +879,13 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
864
  }*/
865
  jQuery('.fb_image_options').show();
866
  }
 
 
 
 
 
 
 
867
  </script>
868
  <style type="text/css">
869
  .og_left_col {
15
  if ( isset($_POST['action']) ) {
16
  if (trim($_POST['action'])=='save') {
17
  //This should also use the $wonderm00n_open_graph_plugin_settings array, but because of intval and trim we still can't
18
+ $usersettings['fb_app_id_show']= intval(webdados_fb_open_graph_post('fb_app_id_show'));
19
+ $usersettings['fb_app_id']= trim(webdados_fb_open_graph_post('fb_app_id'));
20
+ $usersettings['fb_admin_id_show']= intval(webdados_fb_open_graph_post('fb_admin_id_show'));
21
+ $usersettings['fb_admin_id']= trim(webdados_fb_open_graph_post('fb_admin_id'));
22
+ $usersettings['fb_locale_show']= intval(webdados_fb_open_graph_post('fb_locale_show'));
23
+ $usersettings['fb_locale']= trim(webdados_fb_open_graph_post('fb_locale'));
24
+ $usersettings['fb_sitename_show']= intval(webdados_fb_open_graph_post('fb_sitename_show'));
25
+ $usersettings['fb_title_show']= intval(webdados_fb_open_graph_post('fb_title_show'));
26
+ $usersettings['fb_title_show_schema']= intval(webdados_fb_open_graph_post('fb_title_show_schema'));
27
+ $usersettings['fb_title_show_twitter']= intval(webdados_fb_open_graph_post('fb_title_show_twitter'));
28
+ $usersettings['fb_url_show']= intval(webdados_fb_open_graph_post('fb_url_show'));
29
+ $usersettings['fb_url_show_twitter']= intval(webdados_fb_open_graph_post('fb_url_show_twitter'));
30
+ $usersettings['fb_url_canonical']= intval(webdados_fb_open_graph_post('fb_url_canonical'));
31
+ $usersettings['fb_url_add_trailing']= intval(webdados_fb_open_graph_post('fb_url_add_trailing'));
32
+ $usersettings['fb_type_show']= intval(webdados_fb_open_graph_post('fb_type_show'));
33
+ $usersettings['fb_type_homepage']= trim(webdados_fb_open_graph_post('fb_type_homepage'));
34
+ $usersettings['fb_article_dates_show']= intval(webdados_fb_open_graph_post('fb_article_dates_show'));
35
+ $usersettings['fb_article_sections_show']= intval(webdados_fb_open_graph_post('fb_article_sections_show'));
36
+ $usersettings['fb_publisher_show']= intval(webdados_fb_open_graph_post('fb_publisher_show'));
37
+ $usersettings['fb_publisher']= trim(webdados_fb_open_graph_post('fb_publisher'));
38
+ $usersettings['fb_publisher_show_schema']= intval(webdados_fb_open_graph_post('fb_publisher_show_schema'));
39
+ $usersettings['fb_publisher_schema']= trim(webdados_fb_open_graph_post('fb_publisher_schema'));
40
+ $usersettings['fb_publisher_show_twitter']= intval(webdados_fb_open_graph_post('fb_publisher_show_twitter'));
41
+ $usersettings['fb_publisher_twitteruser']= trim(webdados_fb_open_graph_post('fb_publisher_twitteruser'));
42
+ $usersettings['fb_author_show']= intval(webdados_fb_open_graph_post('fb_author_show'));
43
+ $usersettings['fb_author_show_meta']= intval(webdados_fb_open_graph_post('fb_author_show_meta'));
44
+ $usersettings['fb_author_show_linkrelgp']= intval(webdados_fb_open_graph_post('fb_author_show_linkrelgp'));
45
+ $usersettings['fb_author_show_twitter']= intval(webdados_fb_open_graph_post('fb_author_show_twitter'));
46
+ $usersettings['fb_desc_show']= intval(webdados_fb_open_graph_post('fb_desc_show'));
47
+ $usersettings['fb_desc_show_meta']= intval(webdados_fb_open_graph_post('fb_desc_show_meta'));
48
+ $usersettings['fb_desc_show_schema']= intval(webdados_fb_open_graph_post('fb_desc_show_schema'));
49
+ $usersettings['fb_desc_show_twitter']= intval(webdados_fb_open_graph_post('fb_desc_show_twitter'));
50
+ $usersettings['fb_desc_chars']= intval(webdados_fb_open_graph_post('fb_desc_chars'));
51
+ $usersettings['fb_desc_homepage']= trim(webdados_fb_open_graph_post('fb_desc_homepage'));
52
+ $usersettings['fb_desc_homepage_customtext']= trim(webdados_fb_open_graph_post('fb_desc_homepage_customtext'));
53
+ $usersettings['fb_image_show']= intval(webdados_fb_open_graph_post('fb_image_show'));
54
+ $usersettings['fb_image_show_schema']= intval(webdados_fb_open_graph_post('fb_image_show_schema'));
55
+ $usersettings['fb_image_show_twitter']= intval(webdados_fb_open_graph_post('fb_image_show_twitter'));
56
+ $usersettings['fb_image']= trim(webdados_fb_open_graph_post('fb_image'));
57
+ $usersettings['fb_image_rss']= intval(webdados_fb_open_graph_post('fb_image_rss'));
58
+ $usersettings['fb_image_use_specific']= intval(webdados_fb_open_graph_post('fb_image_use_specific'));
59
+ $usersettings['fb_image_use_featured']= intval(webdados_fb_open_graph_post('fb_image_use_featured'));
60
+ $usersettings['fb_image_use_content']= intval(webdados_fb_open_graph_post('fb_image_use_content'));
61
+ $usersettings['fb_image_use_media']= intval(webdados_fb_open_graph_post('fb_image_use_media'));
62
+ $usersettings['fb_image_use_default']= intval(webdados_fb_open_graph_post('fb_image_use_default'));
63
+ $usersettings['fb_show_wpseoyoast']= intval(webdados_fb_open_graph_post('fb_show_wpseoyoast'));
64
+ $usersettings['fb_show_subheading']= intval(webdados_fb_open_graph_post('fb_show_subheading'));
65
+ $usersettings['fb_show_businessdirectoryplugin']= intval(webdados_fb_open_graph_post('fb_show_businessdirectoryplugin'));
66
+ $usersettings['fb_adv_force_local']= intval(webdados_fb_open_graph_post('fb_adv_force_local'));
67
+ $usersettings['fb_adv_notify_fb']= intval(webdados_fb_open_graph_post('fb_adv_notify_fb'));
68
+ $usersettings['fb_adv_supress_fb_notice']= intval(webdados_fb_open_graph_post('fb_adv_supress_fb_notice'));
69
  //Update
70
+ update_option('wonderm00n_open_graph_settings', $usersettings);
71
  }
72
  }
73
 
74
  //Load the settings
75
+ extract(webdados_fb_open_graph_load_settings());
76
 
77
  ?>
78
  <div class="wrap">
79
 
80
  <?php screen_icon(); ?>
81
+ <h2><?php echo $webdados_fb_open_graph_plugin_name; ?> (<?php echo $webdados_fb_open_graph_plugin_version; ?>)</h2>
82
  <br class="clear"/>
83
  <p><?php _e('Please set some default values and which tags should, or should not, be included. It may be necessary to exclude some tags if other plugins are already including them.', 'wd-fb-og'); ?></p>
84
 
90
  <div id="poststuff">
91
  <form name="form1" method="post">
92
 
93
+ <div id="webdados_fb_open_graph-settings" class="postbox">
94
  <h3 id="settings"><?php _e('Settings'); ?></h3>
95
  <div class="inside">
96
  <table width="100%" class="form-table">
551
  </div>
552
  </div>
553
 
554
+ <div id="webdados_fb_open_graph-thirdparty" class="postbox">
555
  <h3 id="thirdparty"><?php _e('3rd Party Integration', 'wd-fb-og');?></h3>
556
  <div class="inside">
557
  <?php
623
  </div>
624
  </div>
625
 
626
+ <div id="webdados_fb_open_graph-advanced" class="postbox">
627
  <h3 id="advanced"><?php _e('Advanced settings', 'wd-fb-og');?></h3>
628
  <div class="inside">
629
  <p><?php _e('Don\'t mess with this unless you know what you\'re doing', 'wd-fb-og');?></p>
636
  <?php _e('May cause problems with some multisite configurations but fix "HTTP request failed" errors', 'wd-fb-og');?>
637
  </td>
638
  </tr>
639
+ <tr>
640
+ <th scope="row"><i class="dashicons-before dashicons-admin-generic"></i><?php _e('Try to update Facebook Open Graph Tags cache when saving the post', 'wd-fb-og'); ?></th>
641
+ <td>
642
+ <input type="checkbox" name="fb_adv_notify_fb" id="fb_adv_notify_fb" value="1" onclick="showFBNotifyOptions();"<?php echo (intval($fb_adv_notify_fb)==1 ? ' checked="checked"' : ''); ?>/>
643
+ </td>
644
+ </tr>
645
+ <tr class="fb_adv_notify_fb_options">
646
+ <th scope="row"><i class="dashicons-before dashicons-admin-generic"></i><?php _e('Supress Facebook Open Graph Tags cache updated notice', 'wd-fb-og'); ?></th>
647
+ <td>
648
+ <input type="checkbox" name="fb_adv_supress_fb_notice" id="fb_adv_supress_fb_notice" value="1" <?php echo (intval($fb_adv_supress_fb_notice)==1 ? ' checked="checked"' : ''); ?>/>
649
+ </td>
650
+ </tr>
651
  </table>
652
  </div>
653
  </div>
692
  <div class="postbox-container og_right_col">
693
 
694
  <div id="poststuff">
695
+ <div id="webdados_fb_open_graph_links" class="postbox">
696
  <h3 id="settings"><?php _e('Rate this plugin', 'wd-fb-og');?></h3>
697
  <div class="inside">
698
  <?php _e('If you like this plugin,', 'wd-fb-og');?> <a href="http://wordpress.org/extend/plugins/wonderm00ns-simple-facebook-open-graph-tags/" target="_blank"><?php _e('please give it a high Rating', 'wd-fb-og');?></a>.
701
  </div>
702
 
703
  <div id="poststuff">
704
+ <div id="webdados_fb_open_graph_links" class="postbox">
705
  <h3 id="settings"><?php _e('Useful links', 'wd-fb-og');?></h3>
706
  <div class="inside">
707
  <ul>
714
  </div>
715
 
716
  <div id="poststuff">
717
+ <div id="webdados_fb_open_graph_donation" class="postbox">
718
  <h3 id="settings"><?php _e('Donate', 'wd-fb-og');?></h3>
719
  <div class="inside">
720
  <p><?php _e('If you find this plugin useful and want to make a contribution towards future development please consider making a small, or big ;-), donation.', 'wd-fb-og');?></p>
747
  tb_show('',"media-upload.php?type=image&TB_iframe=true");
748
  });
749
  window.send_to_editor = function(html) {
750
+ var imgurl = jQuery('<div>'+html+'</div>').find('img').attr('src');
751
  jQuery("input"+"#fb_image").val(imgurl);
752
  tb_remove();
753
  }
767
  jQuery('#fb_desc_homepage_customtext').hide();
768
  showDescriptionCustomText();
769
  showImageOptions();
770
+ showFBNotifyOptions();
771
  });
772
  function showAppidOptions() {
773
  if (jQuery('#fb_app_id_show').is(':checked')) {
879
  }*/
880
  jQuery('.fb_image_options').show();
881
  }
882
+ function showFBNotifyOptions() {
883
+ if (jQuery('#fb_adv_notify_fb').is(':checked')) {
884
+ jQuery('.fb_adv_notify_fb_options').show();
885
+ } else {
886
+ jQuery('.fb_adv_notify_fb_options').hide();
887
+ }
888
+ }
889
  </script>
890
  <style type="text/css">
891
  .og_left_col {
readme.txt CHANGED
@@ -4,8 +4,7 @@ Donate link: http://blog.wonderm00n.com/2011/10/14/wordpress-plugin-simple-faceb
4
  Tags: facebook, open graph, open graph protocol, seo, share, social, meta, twitter card, twitter, schema, google+, g+, google, google plus, image, like, meta, search engine optimization
5
  Requires at least: 3.5
6
  Tested up to: 4.0.1
7
- Stable tag: 1.4.2
8
-
9
  Inserts Facebook Open Graph, Google+/Schema.org, Twitter and other Meta Tags into your WordPress Website for more efficient sharing results.
10
 
11
  == Description ==
@@ -77,6 +76,13 @@ It allows the user to choose which tags are, or not, included and also the defau
77
 
78
  == Changelog ==
79
 
 
 
 
 
 
 
 
80
  = 1.4.2 =
81
  * Fix: (Another) debug message removed
82
 
4
  Tags: facebook, open graph, open graph protocol, seo, share, social, meta, twitter card, twitter, schema, google+, g+, google, google plus, image, like, meta, search engine optimization
5
  Requires at least: 3.5
6
  Tested up to: 4.0.1
7
+ Stable tag: 1.5
 
8
  Inserts Facebook Open Graph, Google+/Schema.org, Twitter and other Meta Tags into your WordPress Website for more efficient sharing results.
9
 
10
  == Description ==
76
 
77
  == Changelog ==
78
 
79
+ = 1.5 =
80
+ * Each time a post/page is saved we try to update/purge Facebook Open Graph Tags cache so you can share it right away from the post edit screen
81
+ * Forced Excertps support on Pages so that it can be used as the post description
82
+ * Added HTTP REFERER and USER AGENT to the cURL calls when trying to get image size by url
83
+ * Fix: Some validations when trying to get image size by url
84
+ * Fix: A lot of php notices and warnings were supressed
85
+
86
  = 1.4.2 =
87
  * Fix: (Another) debug message removed
88
 
wonderm00n-open-graph.php CHANGED
@@ -1,13 +1,13 @@
1
  <?php
2
  /**
3
  * @package Facebook Open Graph, Google+ and Twitter Card Tags
4
- * @version 1.4.2
5
  */
6
  /*
7
  Plugin Name: Facebook Open Graph, Google+ and Twitter Card Tags
8
  Plugin URI: http://www.webdados.pt/produtos-e-servicos/internet/desenvolvimento-wordpress/facebook-open-graph-meta-tags-wordpress/
9
  Description: Inserts Facebook Open Graph, Google+ / Schema.org and Twitter Card Tags into your WordPress Blog/Website for more effective and efficient Facebook, Google+ and Twitter sharing results. You can also choose to insert the "enclosure" and "media:content" tags to the RSS feeds, so that apps like RSS Graffiti and twitterfeed post the image to Facebook correctly.
10
- Version: 1.4.2
11
  Author: Webdados
12
  Author URI: http://www.webdados.pt
13
  Text Domain: wd-fb-og
@@ -16,9 +16,9 @@ Domain Path: /lang
16
 
17
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
18
 
19
- $wonderm00n_open_graph_plugin_version='1.4.2';
20
- $wonderm00n_open_graph_plugin_name='Facebook Open Graph, Google+ and Twitter Card Tags';
21
- $wonderm00n_open_graph_plugin_settings=array(
22
  'fb_app_id_show',
23
  'fb_app_id',
24
  'fb_admin_id_show',
@@ -69,11 +69,13 @@ $wonderm00n_open_graph_plugin_settings=array(
69
  'fb_show_subheading',
70
  'fb_show_businessdirectoryplugin',
71
  'fb_keep_data_uninstall',
72
- 'fb_adv_force_local'
 
 
73
  );
74
 
75
  //We have to remove canonical NOW because the plugin runs too late - We're also loading the settings which is cool
76
- if ($webdados_fb_open_graph_settings=wonderm00n_open_graph_load_settings()) { //To avoid activation errors
77
  if (intval($webdados_fb_open_graph_settings['fb_url_show'])==1) {
78
  if (intval($webdados_fb_open_graph_settings['fb_url_canonical'])==1) {
79
  remove_action('wp_head', 'rel_canonical');
@@ -82,19 +84,19 @@ if ($webdados_fb_open_graph_settings=wonderm00n_open_graph_load_settings()) { /
82
  }
83
 
84
  //Languages
85
- function wonderm00n_open_graph_init() {
86
  load_plugin_textdomain('wd-fb-og', false, dirname(plugin_basename(__FILE__)) . '/lang/');
87
  }
88
- add_action('plugins_loaded', 'wonderm00n_open_graph_init');
89
 
90
- function wonderm00n_open_graph() {
91
- global $wonderm00n_open_graph_plugin_settings, $wonderm00n_open_graph_plugin_name, $wonderm00n_open_graph_plugin_version, $webdados_fb_open_graph_settings;
92
 
93
  //Upgrade
94
- wonderm00n_open_graph_upgrade();
95
 
96
  //Get options - OLD (until 0.5.4)
97
- /*foreach($wonderm00n_open_graph_plugin_settings as $key) {
98
  $$key=get_option('wonderm00n_open_graph_'.$key);
99
  }*/
100
  //Get options - NEW (after 0.5.4)
@@ -132,7 +134,7 @@ function wonderm00n_open_graph() {
132
  }
133
  $fb_desc=(intval($fb_desc_chars)>0 ? substr(esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))),0,$fb_desc_chars) : esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))));
134
  if (intval($fb_image_show)==1 || intval($fb_image_show_schema)==1 || intval($fb_image_show_twitter)==1) {
135
- $fb_image=wonderm00n_open_graph_post_image($fb_image_use_specific, $fb_image_use_featured, $fb_image_use_content, $fb_image_use_media, $fb_image_use_default, $fb_image);
136
  }
137
  //Author
138
  $author_id=$post->post_author;
@@ -141,11 +143,20 @@ function wonderm00n_open_graph() {
141
  $fb_author_meta=get_the_author_meta('display_name', $author_id);
142
  $fb_author_linkrelgp=get_the_author_meta('googleplus', $author_id);
143
  $fb_author_twitter=get_the_author_meta('twitter', $author_id);
 
 
 
 
 
144
  }
145
  //Published and Modified time
146
  if (is_singular('post')) {
147
  $fb_article_pub_date=get_the_date('c');
148
  $fb_article_mod_date=get_the_modified_date('c');
 
 
 
 
149
  }
150
  //Categories
151
  if (is_singular('post')) {
@@ -156,6 +167,8 @@ function wonderm00n_open_graph() {
156
  $fb_sections[]=$cat->name;
157
  }
158
  }
 
 
159
  }
160
  //Business Directory Plugin
161
  if ($fb_show_businessdirectoryplugin==1) {
@@ -225,6 +238,14 @@ function wonderm00n_open_graph() {
225
  //$fb_url=get_option('home').(intval($fb_url_add_trailing)==1 ? '/' : ''); //2013-11-4 changed from 'siteurl' to 'home'
226
  $fb_url=((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; //Not really canonical but will work for now
227
 
 
 
 
 
 
 
 
 
228
  switch(trim($fb_desc_homepage)) {
229
  case 'custom':
230
  $fb_desc=esc_attr(strip_tags(stripslashes($fb_desc_homepage_customtext)));
@@ -327,7 +348,7 @@ function wonderm00n_open_graph() {
327
  $fb_image = apply_filters('fb_og_image', $fb_image);
328
 
329
  $html='
330
- <!-- START - '.$wonderm00n_open_graph_plugin_name.' '.$wonderm00n_open_graph_plugin_version.' -->
331
  ';
332
  if (intval($fb_app_id_show)==1 && trim($fb_app_id)!='') $html.='<meta property="fb:app_id" content="'.trim(esc_attr($fb_app_id)).'"/>
333
  ';
@@ -354,8 +375,9 @@ function wonderm00n_open_graph() {
354
  ';
355
  if (intval($fb_type_show)==1) $html.='<meta property="og:type" content="'.trim(esc_attr($fb_type)).'"/>
356
  ';
357
- if (intval($fb_article_dates_show)==1) $html.='<meta property="article:published_time" content="'.trim(esc_attr($fb_article_pub_date)).'"/>
358
- <meta property="article:modified_time" content="'.trim(esc_attr($fb_article_mod_date)).'" />
 
359
  <meta property="og:updated_time" content="'.trim(esc_attr($fb_article_mod_date)).'" />
360
  ';
361
  if (intval($fb_article_sections_show)==1 && is_array($fb_sections) && count($fb_sections)>0) {
@@ -394,13 +416,14 @@ if (intval($fb_article_sections_show)==1 && is_array($fb_sections) && count($fb_
394
  ';
395
  if(intval($fb_title_show_twitter)==1 || intval($fb_url_show_twitter)==1 || $fb_author_show_twitter==1 || $fb_publisher_show_twitter==1 || $fb_image_show_twitter==1) $html.='<meta name="twitter:card" content="summary_large_image"/>
396
  ';
397
- $html.='<!-- END - '.$wonderm00n_open_graph_plugin_name.' -->
 
398
  ';
399
  echo $html;
400
  }
401
- add_action('wp_head', 'wonderm00n_open_graph', 9999);
402
 
403
- function wonderm00n_open_graph_add_opengraph_namespace( $output ) {
404
  if (stristr($output,'xmlns:og')) {
405
  //Already there
406
  } else {
@@ -416,25 +439,25 @@ function wonderm00n_open_graph_add_opengraph_namespace( $output ) {
416
  return $output;
417
  }
418
  //We want to be last to add the namespace because some other plugin may already added it ;-)
419
- add_filter('language_attributes', 'wonderm00n_open_graph_add_opengraph_namespace',9999);
420
 
421
  //Add images also to RSS feed. Most code from WP RSS Images by Alain Gonzalez
422
- function wonderm00n_open_graph_images_on_feed($for_comments) {
423
  global $webdados_fb_open_graph_settings;
424
  if (intval($webdados_fb_open_graph_settings['fb_image_rss'])==1) {
425
  if (!$for_comments) {
426
- add_action('rss2_ns', 'wonderm00n_open_graph_images_on_feed_yahoo_media_tag');
427
- add_action('rss_item', 'wonderm00n_open_graph_images_on_feed_image');
428
- add_action('rss2_item', 'wonderm00n_open_graph_images_on_feed_image');
429
  }
430
  }
431
  }
432
- function wonderm00n_open_graph_images_on_feed_yahoo_media_tag() {
433
  echo 'xmlns:media="http://search.yahoo.com/mrss/"';
434
  }
435
- function wonderm00n_open_graph_images_on_feed_image() {
436
  global $webdados_fb_open_graph_settings;
437
- $fb_image = wonderm00n_open_graph_post_image($webdados_fb_open_graph_settings['fb_image_use_specific'], $webdados_fb_open_graph_settings['fb_image_use_featured'], $webdados_fb_open_graph_settings['fb_image_use_content'], $webdados_fb_open_graph_settings['fb_image_use_media'], $webdados_fb_open_graph_settings['fb_image_use_default'], $webdados_fb_open_graph_settings['fb_image']);
438
  if ($fb_image!='') {
439
  $uploads = wp_upload_dir();
440
  $url = parse_url($fb_image);
@@ -447,16 +470,16 @@ function wonderm00n_open_graph_images_on_feed_image() {
447
  $filesize=$header['Content-Length'];
448
  $url=$fb_image;
449
  }
450
- list($width, $height, $type, $attr) = wonderm00n_open_graph_getimagesize($url);
451
  echo '<enclosure url="' . $fb_image . '" length="' . $filesize . '" type="'.image_type_to_mime_type($type).'"/>';
452
  echo '<media:content url="'.$fb_image.'" width="'.$width.'" height="'.$height.'" medium="image" type="'.image_type_to_mime_type($type).'"/>';
453
  }
454
  }
455
- add_action("do_feed_rss","wonderm00n_open_graph_images_on_feed",5,1);
456
- add_action("do_feed_rss2","wonderm00n_open_graph_images_on_feed",5,1);
457
 
458
  //Post image
459
- function wonderm00n_open_graph_post_image($fb_image_use_specific=1,$fb_image_use_featured=1, $fb_image_use_content=1, $fb_image_use_media=1, $fb_image_use_default=1, $default_image='') {
460
  global $post, $webdados_fb_open_graph_settings;
461
  $thumbdone=false;
462
  $fb_image='';
@@ -537,7 +560,7 @@ function wonderm00n_open_graph_post_image($fb_image_use_specific=1,$fb_image_use
537
  );
538
  }
539
  if ($imagetemp) {
540
- if ($img_size = wonderm00n_open_graph_getimagesize($imagetempsize)) {
541
  if ($img_size[0] >= $minsize && $img_size[1] >= $minsize) {
542
  $fb_image=$imagetemp;
543
  $thumbdone=true;
@@ -569,7 +592,7 @@ function wonderm00n_open_graph_post_image($fb_image_use_specific=1,$fb_image_use
569
  :
570
  ABSPATH.str_replace(trailingslashit(site_url()), '', $imagetemp)
571
  );
572
- if ($img_size = wonderm00n_open_graph_getimagesize($imagetempsize)) {
573
  if ($img_size[0] >= $minsize && $img_size[1] >= $minsize) {
574
  $fb_image=$imagetemp;
575
  $thumbdone=true;
@@ -594,8 +617,7 @@ function wonderm00n_open_graph_post_image($fb_image_use_specific=1,$fb_image_use
594
  }
595
 
596
  //Get image size
597
- function wonderm00n_open_graph_getimagesize($image) {
598
- //echo $image;
599
  if (stristr($image, 'http://') || stristr($image, 'https://') || substr($image, 0, 2)=='//') {
600
  if (function_exists('curl_version')) {
601
  //We'll get just a part of the image to speed things up. From http://stackoverflow.com/questions/4635936/super-fast-getimagesize-in-php
@@ -605,27 +627,33 @@ function wonderm00n_open_graph_getimagesize($image) {
605
  $curl = curl_init($image);
606
  curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
607
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 
 
 
608
  if ($data = curl_exec($curl)) {
609
- $im = @imagecreatefromstring($data); //Mute errors because we're not loading the all image
610
- if ($x=imagesx($im)) {
611
- //We have to fake the image type - For RSS
612
- $ext = pathinfo($image, PATHINFO_EXTENSION);
613
- switch(strtolower($ext)) {
614
- case 'gif':
615
- $type=1;
616
- break;
617
- case 'jpg':
618
- case 'jpeg':
619
- $type=2;
620
- break;
621
- case 'png':
622
- $type=3;
623
- break;
624
- default:
625
- $type=2;
626
- break;
 
 
 
 
627
  }
628
- $img_size=array($x, imagesy($im), $type, '');
629
  } else {
630
  $img_size=false;
631
  }
@@ -648,21 +676,27 @@ function wonderm00n_open_graph_getimagesize($image) {
648
  return $img_size;
649
  }
650
 
 
 
 
 
 
 
651
  //Admin
652
  if (is_admin()) {
653
 
654
- add_action('admin_menu', 'wonderm00n_open_graph_add_options');
655
 
656
- register_activation_hook(__FILE__, 'wonderm00n_open_graph_activate');
657
 
658
- function wonderm00n_open_graph_add_options() {
659
- global $wonderm00n_open_graph_plugin_name;
660
  if(function_exists('add_options_page')){
661
- add_options_page($wonderm00n_open_graph_plugin_name, $wonderm00n_open_graph_plugin_name, 'manage_options', basename(__FILE__), 'wonderm00n_open_graph_admin');
662
  }
663
  }
664
 
665
- function wonderm00n_open_graph_activate() {
666
  //Clear WPSEO notices
667
  global $wpdb;
668
  $wpdb->query(
@@ -670,46 +704,46 @@ if (is_admin()) {
670
  );
671
  }
672
 
673
- function wonderm00n_open_graph_settings_link( $links, $file ) {
674
  if( $file == 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php' && function_exists( "admin_url" ) ) {
675
  $settings_link = '<a href="' . admin_url( 'options-general.php?page=wonderm00n-open-graph.php' ) . '">' . __('Settings') . '</a>';
676
  array_push( $links, $settings_link ); // after other links
677
  }
678
  return $links;
679
  }
680
- add_filter('plugin_row_meta', 'wonderm00n_open_graph_settings_link', 9, 2 );
681
 
682
 
683
- function wonderm00n_open_graph_admin() {
684
- global $wonderm00n_open_graph_plugin_settings, $wonderm00n_open_graph_plugin_name, $wonderm00n_open_graph_plugin_version;
685
- wonderm00n_open_graph_upgrade();
686
  include_once 'includes/settings-page.php';
687
  }
688
 
689
- function wonderm00n_open_graph_scripts() {
690
  wp_enqueue_script('media-upload');
691
  wp_enqueue_script('thickbox');
692
  wp_enqueue_script('jquery');
693
  }
694
- function wonderm00n_open_graph_styles() {
695
  wp_enqueue_style('thickbox');
696
  }
697
- add_action('admin_print_scripts', 'wonderm00n_open_graph_scripts');
698
- add_action('admin_print_styles', 'wonderm00n_open_graph_styles');
699
 
700
- function wonderm00n_open_graph_add_posts_options() {
701
- global $webdados_fb_open_graph_settings, $wonderm00n_open_graph_plugin_name;
702
  if (intval($webdados_fb_open_graph_settings['fb_image_use_specific'])==1) {
703
  global $post;
704
  add_meta_box(
705
  'webdados_fb_open_graph',
706
- $wonderm00n_open_graph_plugin_name,
707
- 'wonderm00n_open_graph_add_posts_options_box',
708
  $post->post_type
709
  );
710
  }
711
  }
712
- function wonderm00n_open_graph_add_posts_options_box() {
713
  global $post;
714
  // Add an nonce field so we can check for it later.
715
  wp_nonce_field( 'webdados_fb_open_graph_custom_box', 'webdados_fb_open_graph_custom_box_nonce' );
@@ -733,53 +767,72 @@ if (is_admin()) {
733
  });
734
  </script>';
735
  }
736
- add_action('add_meta_boxes', 'wonderm00n_open_graph_add_posts_options');
737
- function wonderm00n_open_graph_add_posts_options_box_save( $post_id ) {
738
-
739
- /*
740
- * We need to verify this came from the our screen and with proper authorization,
741
- * because save_post can be triggered at other times.
742
- */
743
-
744
- // Check if our nonce is set.
745
- if ( ! isset( $_POST['webdados_fb_open_graph_custom_box_nonce'] ) )
746
- return $post_id;
747
 
748
- $nonce = $_POST['webdados_fb_open_graph_custom_box_nonce'];
749
-
750
- // Verify that the nonce is valid.
751
- if ( ! wp_verify_nonce( $nonce, 'webdados_fb_open_graph_custom_box' ) )
752
- return $post_id;
753
 
754
- // If this is an autosave, our form has not been submitted, so we don't want to do anything.
755
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
756
- return $post_id;
 
 
757
 
758
- // Check the user's permissions.
759
- if ( 'page' == $_POST['post_type'] ) {
 
760
 
761
- if ( ! current_user_can( 'edit_page', $post_id ) )
762
- return $post_id;
763
-
764
- } else {
 
 
 
 
765
 
766
- if ( ! current_user_can( 'edit_post', $post_id ) )
767
- return $post_id;
768
- }
 
 
 
 
769
 
770
- /* OK, its safe for us to save the data now. */
 
 
 
 
 
 
 
771
 
772
- // Sanitize user input.
773
- $mydata = sanitize_text_field( $_POST['webdados_fb_open_graph_specific_image'] );
774
 
775
- // Update the meta field in the database.
776
- update_post_meta( $post_id, '_webdados_fb_open_graph_specific_image', $mydata );
777
  }
778
- add_action('save_post', 'wonderm00n_open_graph_add_posts_options_box_save' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
779
 
780
  // Media insert code
781
  function webdados_fb_open_graph_media_admin_head() {
782
-
783
  ?>
784
  <script type="text/javascript">
785
  function wdfbogFieldsFileMediaTrigger(guid) {
@@ -836,13 +889,13 @@ if (is_admin()) {
836
  //WPSEO warning
837
  function webdados_fb_open_graph_wpseo_notice() {
838
  if (defined('WPSEO_VERSION')) {
839
- global $current_user, $wonderm00n_open_graph_plugin_name;
840
  $user_id=$current_user->ID;
841
  if (!get_user_meta($user_id,'wd_fb_og_wpseo_notice_ignore')) {
842
  ?>
843
  <div class="error">
844
  <p>
845
- <b><?php echo $wonderm00n_open_graph_plugin_name; ?>:</b>
846
  <br/>
847
  <?php _e('Please ignore the (dumb) Yoast WordPress SEO warning regarding open graph issues with this plugin. Just disable WPSEO Social settings at', 'wd-fb-og'); ?>
848
  <a href="admin.php?page=wpseo_social&amp;wd_fb_og_wpseo_notice_ignore=1"><?php _e('SEO &gt; Social','wd-fb-og'); ?></a>
@@ -865,13 +918,21 @@ if (is_admin()) {
865
  }
866
  }
867
  }
868
- add_action('admin_init', 'webdados_fb_open_graph_wpseo_notice_ignore');
 
 
 
 
 
 
 
 
869
 
870
  }
871
 
872
 
873
 
874
- function wonderm00n_open_graph_default_values() {
875
  return array(
876
  'fb_locale_show' => 1,
877
  'fb_sitename_show' => 1,
@@ -892,17 +953,18 @@ function wonderm00n_open_graph_default_values() {
892
  'fb_image_use_media' => 1,
893
  'fb_image_use_default' => 1,
894
  'fb_keep_data_uninstall' => 1,
895
- 'fb_image_min_size' => 200
 
896
  );
897
  }
898
- function wonderm00n_open_graph_load_settings() {
899
- global $wonderm00n_open_graph_plugin_settings;
900
- if (is_array($wonderm00n_open_graph_plugin_settings)) { //To avoid activation errors
901
- $defaults=wonderm00n_open_graph_default_values();
902
  //Load the user settings (if they exist)
903
- if ($usersettings=get_option('webdados_fb_open_graph_settings')) {
904
  //Merge the settings "all together now" (yes, it's a Beatles reference)
905
- foreach($wonderm00n_open_graph_plugin_settings as $key) {
906
  if (isset($usersettings[$key])) {
907
  if (strlen(trim($usersettings[$key]))==0) {
908
  if (!empty($defaults[$key])) {
@@ -926,7 +988,7 @@ function wonderm00n_open_graph_load_settings() {
926
  }
927
  }*/
928
  } else {
929
- foreach($wonderm00n_open_graph_plugin_settings as $key) {
930
  if (!empty($defaults[$key])) {
931
  $usersettings[$key]=$defaults[$key];
932
  } else {
@@ -940,43 +1002,43 @@ function wonderm00n_open_graph_load_settings() {
940
  }
941
  }
942
 
943
- function wonderm00n_open_graph_upgrade() {
944
- global $wonderm00n_open_graph_plugin_version;
945
  $upgrade=false;
946
  //Upgrade from 0.5.4 - Last version with individual settings
947
- if (!$v=get_option('webdados_fb_open_graph_version')) {
948
  //Convert settings
949
  $upgrade=true;
950
- global $wonderm00n_open_graph_plugin_settings;
951
- foreach($wonderm00n_open_graph_plugin_settings as $key) {
952
  $webdados_fb_open_graph_settings[$key]=get_option('wonderm00n_open_graph_'.$key);
953
  }
954
  // New fb_image_use_specific
955
  $webdados_fb_open_graph_settings['fb_image_use_specific']=1;
956
- update_option('webdados_fb_open_graph_settings', $webdados_fb_open_graph_settings);
957
- foreach($wonderm00n_open_graph_plugin_settings as $key) {
958
  delete_option('wonderm00n_open_graph_'.$key);
959
  }
960
  } else {
961
- if ($v<$wonderm00n_open_graph_plugin_version) {
962
  //Any version upgrade
963
  $upgrade=true;
964
  }
965
  }
966
  //Set version on database
967
  if ($upgrade) {
968
- update_option('webdados_fb_open_graph_version', $wonderm00n_open_graph_plugin_version);
969
  }
970
  }
971
 
972
 
973
  //Uninstall stuff
974
- register_uninstall_hook(__FILE__, 'wonderm00n_open_graph_uninstall'); //NOT WORKING! WHY?
975
- function wonderm00n_open_graph_uninstall() {
976
  //NOT WORKING! WHY?
977
- //global $wonderm00n_open_graph_plugin_settings;
978
  //Remove data
979
- /*foreach($wonderm00n_open_graph_plugin_settings as $key) {
980
  delete_option('wonderm00n_open_graph_'.$key);
981
  }
982
  delete_option('wonderm00n_open_graph_activated');*/
@@ -984,6 +1046,6 @@ function wonderm00n_open_graph_uninstall() {
984
 
985
  //To avoid notices when updating options on settings-page.php
986
  //Hey @flynsarmy you are here, see?
987
- function wonderm00n_open_graph_post($var, $default='') {
988
  return isset($_POST[$var]) ? $_POST[$var] : $default;
989
  }
1
  <?php
2
  /**
3
  * @package Facebook Open Graph, Google+ and Twitter Card Tags
4
+ * @version 1.5
5
  */
6
  /*
7
  Plugin Name: Facebook Open Graph, Google+ and Twitter Card Tags
8
  Plugin URI: http://www.webdados.pt/produtos-e-servicos/internet/desenvolvimento-wordpress/facebook-open-graph-meta-tags-wordpress/
9
  Description: Inserts Facebook Open Graph, Google+ / Schema.org and Twitter Card Tags into your WordPress Blog/Website for more effective and efficient Facebook, Google+ and Twitter sharing results. You can also choose to insert the "enclosure" and "media:content" tags to the RSS feeds, so that apps like RSS Graffiti and twitterfeed post the image to Facebook correctly.
10
+ Version: 1.5
11
  Author: Webdados
12
  Author URI: http://www.webdados.pt
13
  Text Domain: wd-fb-og
16
 
17
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
18
 
19
+ $webdados_fb_open_graph_plugin_version='1.5';
20
+ $webdados_fb_open_graph_plugin_name='Facebook Open Graph, Google+ and Twitter Card Tags';
21
+ $webdados_fb_open_graph_plugin_settings=array(
22
  'fb_app_id_show',
23
  'fb_app_id',
24
  'fb_admin_id_show',
69
  'fb_show_subheading',
70
  'fb_show_businessdirectoryplugin',
71
  'fb_keep_data_uninstall',
72
+ 'fb_adv_force_local',
73
+ 'fb_adv_notify_fb',
74
+ 'fb_adv_supress_fb_notice'
75
  );
76
 
77
  //We have to remove canonical NOW because the plugin runs too late - We're also loading the settings which is cool
78
+ if ($webdados_fb_open_graph_settings=webdados_fb_open_graph_load_settings()) { //To avoid activation errors
79
  if (intval($webdados_fb_open_graph_settings['fb_url_show'])==1) {
80
  if (intval($webdados_fb_open_graph_settings['fb_url_canonical'])==1) {
81
  remove_action('wp_head', 'rel_canonical');
84
  }
85
 
86
  //Languages
87
+ function webdados_fb_open_graph_init() {
88
  load_plugin_textdomain('wd-fb-og', false, dirname(plugin_basename(__FILE__)) . '/lang/');
89
  }
90
+ add_action('plugins_loaded', 'webdados_fb_open_graph_init');
91
 
92
+ function webdados_fb_open_graph() {
93
+ global $webdados_fb_open_graph_plugin_settings, $webdados_fb_open_graph_plugin_name, $webdados_fb_open_graph_plugin_version, $webdados_fb_open_graph_settings;
94
 
95
  //Upgrade
96
+ webdados_fb_open_graph_upgrade();
97
 
98
  //Get options - OLD (until 0.5.4)
99
+ /*foreach($webdados_fb_open_graph_plugin_settings as $key) {
100
  $$key=get_option('wonderm00n_open_graph_'.$key);
101
  }*/
102
  //Get options - NEW (after 0.5.4)
134
  }
135
  $fb_desc=(intval($fb_desc_chars)>0 ? substr(esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))),0,$fb_desc_chars) : esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))));
136
  if (intval($fb_image_show)==1 || intval($fb_image_show_schema)==1 || intval($fb_image_show_twitter)==1) {
137
+ $fb_image=webdados_fb_open_graph_post_image($fb_image_use_specific, $fb_image_use_featured, $fb_image_use_content, $fb_image_use_media, $fb_image_use_default, $fb_image);
138
  }
139
  //Author
140
  $author_id=$post->post_author;
143
  $fb_author_meta=get_the_author_meta('display_name', $author_id);
144
  $fb_author_linkrelgp=get_the_author_meta('googleplus', $author_id);
145
  $fb_author_twitter=get_the_author_meta('twitter', $author_id);
146
+ } else {
147
+ $fb_author='';
148
+ $fb_author_meta='';
149
+ $fb_author_linkrelgp='';
150
+ $fb_author_twitter='';
151
  }
152
  //Published and Modified time
153
  if (is_singular('post')) {
154
  $fb_article_pub_date=get_the_date('c');
155
  $fb_article_mod_date=get_the_modified_date('c');
156
+ } else {
157
+ $fb_article_dates_show=0;
158
+ $fb_article_pub_date='';
159
+ $fb_article_mod_date='';
160
  }
161
  //Categories
162
  if (is_singular('post')) {
167
  $fb_sections[]=$cat->name;
168
  }
169
  }
170
+ } else {
171
+ $fb_article_sections_show=0;
172
  }
173
  //Business Directory Plugin
174
  if ($fb_show_businessdirectoryplugin==1) {
238
  //$fb_url=get_option('home').(intval($fb_url_add_trailing)==1 ? '/' : ''); //2013-11-4 changed from 'siteurl' to 'home'
239
  $fb_url=((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; //Not really canonical but will work for now
240
 
241
+ //These are only used in posts/pages
242
+ $fb_article_sections_show=0;
243
+ $fb_article_dates_show=0;
244
+ $fb_author_show=0;
245
+ $fb_author_show_meta=0;
246
+ $fb_author_show_linkrelgp=0;
247
+ $fb_author_show_twitter=0;
248
+
249
  switch(trim($fb_desc_homepage)) {
250
  case 'custom':
251
  $fb_desc=esc_attr(strip_tags(stripslashes($fb_desc_homepage_customtext)));
348
  $fb_image = apply_filters('fb_og_image', $fb_image);
349
 
350
  $html='
351
+ <!-- START - '.$webdados_fb_open_graph_plugin_name.' '.$webdados_fb_open_graph_plugin_version.' -->
352
  ';
353
  if (intval($fb_app_id_show)==1 && trim($fb_app_id)!='') $html.='<meta property="fb:app_id" content="'.trim(esc_attr($fb_app_id)).'"/>
354
  ';
375
  ';
376
  if (intval($fb_type_show)==1) $html.='<meta property="og:type" content="'.trim(esc_attr($fb_type)).'"/>
377
  ';
378
+ if (intval($fb_article_dates_show)==1 && trim($fb_article_pub_date)!='') $html.='<meta property="article:published_time" content="'.trim(esc_attr($fb_article_pub_date)).'"/>
379
+ ';
380
+ if (intval($fb_article_dates_show)==1 && trim($fb_article_mod_date)!='') $html.='<meta property="article:modified_time" content="'.trim(esc_attr($fb_article_mod_date)).'" />
381
  <meta property="og:updated_time" content="'.trim(esc_attr($fb_article_mod_date)).'" />
382
  ';
383
  if (intval($fb_article_sections_show)==1 && is_array($fb_sections) && count($fb_sections)>0) {
416
  ';
417
  if(intval($fb_title_show_twitter)==1 || intval($fb_url_show_twitter)==1 || $fb_author_show_twitter==1 || $fb_publisher_show_twitter==1 || $fb_image_show_twitter==1) $html.='<meta name="twitter:card" content="summary_large_image"/>
418
  ';
419
+ $html.='<!-- END - '.$webdados_fb_open_graph_plugin_name.' -->
420
+
421
  ';
422
  echo $html;
423
  }
424
+ add_action('wp_head', 'webdados_fb_open_graph', 9999);
425
 
426
+ function webdados_fb_open_graph_add_opengraph_namespace( $output ) {
427
  if (stristr($output,'xmlns:og')) {
428
  //Already there
429
  } else {
439
  return $output;
440
  }
441
  //We want to be last to add the namespace because some other plugin may already added it ;-)
442
+ add_filter('language_attributes', 'webdados_fb_open_graph_add_opengraph_namespace',9999);
443
 
444
  //Add images also to RSS feed. Most code from WP RSS Images by Alain Gonzalez
445
+ function webdados_fb_open_graph_images_on_feed($for_comments) {
446
  global $webdados_fb_open_graph_settings;
447
  if (intval($webdados_fb_open_graph_settings['fb_image_rss'])==1) {
448
  if (!$for_comments) {
449
+ add_action('rss2_ns', 'webdados_fb_open_graph_images_on_feed_yahoo_media_tag');
450
+ add_action('rss_item', 'webdados_fb_open_graph_images_on_feed_image');
451
+ add_action('rss2_item', 'webdados_fb_open_graph_images_on_feed_image');
452
  }
453
  }
454
  }
455
+ function webdados_fb_open_graph_images_on_feed_yahoo_media_tag() {
456
  echo 'xmlns:media="http://search.yahoo.com/mrss/"';
457
  }
458
+ function webdados_fb_open_graph_images_on_feed_image() {
459
  global $webdados_fb_open_graph_settings;
460
+ $fb_image = webdados_fb_open_graph_post_image($webdados_fb_open_graph_settings['fb_image_use_specific'], $webdados_fb_open_graph_settings['fb_image_use_featured'], $webdados_fb_open_graph_settings['fb_image_use_content'], $webdados_fb_open_graph_settings['fb_image_use_media'], $webdados_fb_open_graph_settings['fb_image_use_default'], $webdados_fb_open_graph_settings['fb_image']);
461
  if ($fb_image!='') {
462
  $uploads = wp_upload_dir();
463
  $url = parse_url($fb_image);
470
  $filesize=$header['Content-Length'];
471
  $url=$fb_image;
472
  }
473
+ list($width, $height, $type, $attr) = webdados_fb_open_graph_getimagesize($url);
474
  echo '<enclosure url="' . $fb_image . '" length="' . $filesize . '" type="'.image_type_to_mime_type($type).'"/>';
475
  echo '<media:content url="'.$fb_image.'" width="'.$width.'" height="'.$height.'" medium="image" type="'.image_type_to_mime_type($type).'"/>';
476
  }
477
  }
478
+ add_action("do_feed_rss","webdados_fb_open_graph_images_on_feed",5,1);
479
+ add_action("do_feed_rss2","webdados_fb_open_graph_images_on_feed",5,1);
480
 
481
  //Post image
482
+ function webdados_fb_open_graph_post_image($fb_image_use_specific=1,$fb_image_use_featured=1, $fb_image_use_content=1, $fb_image_use_media=1, $fb_image_use_default=1, $default_image='') {
483
  global $post, $webdados_fb_open_graph_settings;
484
  $thumbdone=false;
485
  $fb_image='';
560
  );
561
  }
562
  if ($imagetemp) {
563
+ if ($img_size = webdados_fb_open_graph_getimagesize($imagetempsize)) {
564
  if ($img_size[0] >= $minsize && $img_size[1] >= $minsize) {
565
  $fb_image=$imagetemp;
566
  $thumbdone=true;
592
  :
593
  ABSPATH.str_replace(trailingslashit(site_url()), '', $imagetemp)
594
  );
595
+ if ($img_size = webdados_fb_open_graph_getimagesize($imagetempsize)) {
596
  if ($img_size[0] >= $minsize && $img_size[1] >= $minsize) {
597
  $fb_image=$imagetemp;
598
  $thumbdone=true;
617
  }
618
 
619
  //Get image size
620
+ function webdados_fb_open_graph_getimagesize($image) {
 
621
  if (stristr($image, 'http://') || stristr($image, 'https://') || substr($image, 0, 2)=='//') {
622
  if (function_exists('curl_version')) {
623
  //We'll get just a part of the image to speed things up. From http://stackoverflow.com/questions/4635936/super-fast-getimagesize-in-php
627
  $curl = curl_init($image);
628
  curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
629
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
630
+ //Set HTTP REFERER and USER AGENT just in case. Some servers may have hotlinking protection
631
+ curl_setopt($curl, CURLOPT_REFERER, ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
632
+ curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
633
  if ($data = curl_exec($curl)) {
634
+ if ($im = @imagecreatefromstring($data)) { //Mute errors because we're not loading the all image
635
+ if ($x=imagesx($im)) {
636
+ //We have to fake the image type - For RSS
637
+ $ext = pathinfo($image, PATHINFO_EXTENSION);
638
+ switch(strtolower($ext)) {
639
+ case 'gif':
640
+ $type=1;
641
+ break;
642
+ case 'jpg':
643
+ case 'jpeg':
644
+ $type=2;
645
+ break;
646
+ case 'png':
647
+ $type=3;
648
+ break;
649
+ default:
650
+ $type=2;
651
+ break;
652
+ }
653
+ $img_size=array($x, imagesy($im), $type, '');
654
+ } else {
655
+ $img_size=false;
656
  }
 
657
  } else {
658
  $img_size=false;
659
  }
676
  return $img_size;
677
  }
678
 
679
+ function webdados_fb_open_graph_add_excerpts_to_pages() {
680
+ add_post_type_support('page', 'excerpt');
681
+ }
682
+ add_action('init', 'webdados_fb_open_graph_add_excerpts_to_pages');
683
+
684
+
685
  //Admin
686
  if (is_admin()) {
687
 
688
+ add_action('admin_menu', 'webdados_fb_open_graph_add_options');
689
 
690
+ register_activation_hook(__FILE__, 'webdados_fb_open_graph_activate');
691
 
692
+ function webdados_fb_open_graph_add_options() {
693
+ global $webdados_fb_open_graph_plugin_name;
694
  if(function_exists('add_options_page')){
695
+ add_options_page($webdados_fb_open_graph_plugin_name, $webdados_fb_open_graph_plugin_name, 'manage_options', basename(__FILE__), 'webdados_fb_open_graph_admin');
696
  }
697
  }
698
 
699
+ function webdados_fb_open_graph_activate() {
700
  //Clear WPSEO notices
701
  global $wpdb;
702
  $wpdb->query(
704
  );
705
  }
706
 
707
+ function webdados_fb_open_graph_settings_link( $links, $file ) {
708
  if( $file == 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php' && function_exists( "admin_url" ) ) {
709
  $settings_link = '<a href="' . admin_url( 'options-general.php?page=wonderm00n-open-graph.php' ) . '">' . __('Settings') . '</a>';
710
  array_push( $links, $settings_link ); // after other links
711
  }
712
  return $links;
713
  }
714
+ add_filter('plugin_row_meta', 'webdados_fb_open_graph_settings_link', 9, 2 );
715
 
716
 
717
+ function webdados_fb_open_graph_admin() {
718
+ global $webdados_fb_open_graph_plugin_settings, $webdados_fb_open_graph_plugin_name, $webdados_fb_open_graph_plugin_version;
719
+ webdados_fb_open_graph_upgrade();
720
  include_once 'includes/settings-page.php';
721
  }
722
 
723
+ function webdados_fb_open_graph_scripts() {
724
  wp_enqueue_script('media-upload');
725
  wp_enqueue_script('thickbox');
726
  wp_enqueue_script('jquery');
727
  }
728
+ function webdados_fb_open_graph_styles() {
729
  wp_enqueue_style('thickbox');
730
  }
731
+ add_action('admin_print_scripts', 'webdados_fb_open_graph_scripts');
732
+ add_action('admin_print_styles', 'webdados_fb_open_graph_styles');
733
 
734
+ function webdados_fb_open_graph_add_posts_options() {
735
+ global $webdados_fb_open_graph_settings, $webdados_fb_open_graph_plugin_name;
736
  if (intval($webdados_fb_open_graph_settings['fb_image_use_specific'])==1) {
737
  global $post;
738
  add_meta_box(
739
  'webdados_fb_open_graph',
740
+ $webdados_fb_open_graph_plugin_name,
741
+ 'webdados_fb_open_graph_add_posts_options_box',
742
  $post->post_type
743
  );
744
  }
745
  }
746
+ function webdados_fb_open_graph_add_posts_options_box() {
747
  global $post;
748
  // Add an nonce field so we can check for it later.
749
  wp_nonce_field( 'webdados_fb_open_graph_custom_box', 'webdados_fb_open_graph_custom_box_nonce' );
767
  });
768
  </script>';
769
  }
770
+ add_action('add_meta_boxes', 'webdados_fb_open_graph_add_posts_options');
771
+ function webdados_fb_open_graph_add_posts_options_box_save($post_id) {
772
+ global $webdados_fb_open_graph_settings;
773
+ $save=true;
 
 
 
 
 
 
 
774
 
775
+ // If this is an autosave, our form has not been submitted, so we don't want to do anything.
776
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
777
+ return $post_id;
 
 
778
 
779
+ // Check if our nonce is set.
780
+ if (!isset($_POST['webdados_fb_open_graph_custom_box_nonce']))
781
+ $save=false;
782
+
783
+ $nonce=$_POST['webdados_fb_open_graph_custom_box_nonce'];
784
 
785
+ // Verify that the nonce is valid.
786
+ if (!wp_verify_nonce($nonce, 'webdados_fb_open_graph_custom_box'))
787
+ $save=false;
788
 
789
+ // Check the user's permissions.
790
+ if ('page' == $_POST['post_type']) {
791
+ if (!current_user_can('edit_page', $post_id))
792
+ $save=false;
793
+ } else {
794
+ if (!current_user_can('edit_post', $post_id))
795
+ $save=false;
796
+ }
797
 
798
+ if ($save) {
799
+ /* OK, its safe for us to save the data now. */
800
+ // Sanitize user input.
801
+ $mydata = sanitize_text_field($_POST['webdados_fb_open_graph_specific_image']);
802
+ // Update the meta field in the database.
803
+ update_post_meta($post_id, '_webdados_fb_open_graph_specific_image', $mydata);
804
+ }
805
 
806
+ //Force Facebook update anyway - Our meta box could be hidden
807
+ if (get_post_status($post_id)=='publish' && intval($webdados_fb_open_graph_settings['fb_adv_notify_fb'])==1) {
808
+ $fb_debug_url='https://graph.facebook.com/?id='.urlencode(get_permalink($post_id)).'&scrape=true&method=post';
809
+ $response=wp_remote_get($fb_debug_url);
810
+ if ($response['response']['code']==200 && intval($webdados_fb_open_graph_settings['fb_adv_supress_fb_notice'])==0) {
811
+ $_SESSION['webdados_fb_open_graph_facebook_updated']=1;
812
+ }
813
+ }
814
 
815
+ return $post_id;
 
816
 
 
 
817
  }
818
+ add_action('save_post', 'webdados_fb_open_graph_add_posts_options_box_save');
819
+ function webdados_fb_open_graph_facebook_updated() {
820
+ if ($screen = get_current_screen()) {
821
+ if (isset($_SESSION['webdados_fb_open_graph_facebook_updated']) && $_SESSION['webdados_fb_open_graph_facebook_updated']==1 && $screen->id=='post') {
822
+ ?>
823
+ <div class="updated">
824
+ <p><?php _e('Facebook Open Graph Tags cache updated/purged.', 'wd-fb-og'); ?> <a href="http://www.facebook.com/sharer.php?u=<?php echo urlencode(get_permalink($post_id));?>" target="_blank"><?php _e('Share this on Facebook', 'wd-fb-og'); ?></a></p>
825
+ </div>
826
+ <?php
827
+ }
828
+ }
829
+ unset($_SESSION['webdados_fb_open_graph_facebook_updated']);
830
+ }
831
+ add_action('admin_notices', 'webdados_fb_open_graph_facebook_updated');
832
+
833
 
834
  // Media insert code
835
  function webdados_fb_open_graph_media_admin_head() {
 
836
  ?>
837
  <script type="text/javascript">
838
  function wdfbogFieldsFileMediaTrigger(guid) {
889
  //WPSEO warning
890
  function webdados_fb_open_graph_wpseo_notice() {
891
  if (defined('WPSEO_VERSION')) {
892
+ global $current_user, $webdados_fb_open_graph_plugin_name;
893
  $user_id=$current_user->ID;
894
  if (!get_user_meta($user_id,'wd_fb_og_wpseo_notice_ignore')) {
895
  ?>
896
  <div class="error">
897
  <p>
898
+ <b><?php echo $webdados_fb_open_graph_plugin_name; ?>:</b>
899
  <br/>
900
  <?php _e('Please ignore the (dumb) Yoast WordPress SEO warning regarding open graph issues with this plugin. Just disable WPSEO Social settings at', 'wd-fb-og'); ?>
901
  <a href="admin.php?page=wpseo_social&amp;wd_fb_og_wpseo_notice_ignore=1"><?php _e('SEO &gt; Social','wd-fb-og'); ?></a>
918
  }
919
  }
920
  }
921
+ function webdados_fb_open_graph_register_session(){
922
+ if(!session_id())
923
+ session_start();
924
+ }
925
+ function webdados_fb_open_graph_admin_init() {
926
+ webdados_fb_open_graph_wpseo_notice_ignore();
927
+ webdados_fb_open_graph_register_session();
928
+ }
929
+ add_action('admin_init', 'webdados_fb_open_graph_admin_init');
930
 
931
  }
932
 
933
 
934
 
935
+ function webdados_fb_open_graph_default_values() {
936
  return array(
937
  'fb_locale_show' => 1,
938
  'fb_sitename_show' => 1,
953
  'fb_image_use_media' => 1,
954
  'fb_image_use_default' => 1,
955
  'fb_keep_data_uninstall' => 1,
956
+ 'fb_image_min_size' => 200,
957
+ 'fb_adv_notify_fb' => 1
958
  );
959
  }
960
+ function webdados_fb_open_graph_load_settings() {
961
+ global $webdados_fb_open_graph_plugin_settings;
962
+ if (is_array($webdados_fb_open_graph_plugin_settings)) { //To avoid activation errors
963
+ $defaults=webdados_fb_open_graph_default_values();
964
  //Load the user settings (if they exist)
965
+ if ($usersettings=get_option('wonderm00n_open_graph_settings')) {
966
  //Merge the settings "all together now" (yes, it's a Beatles reference)
967
+ foreach($webdados_fb_open_graph_plugin_settings as $key) {
968
  if (isset($usersettings[$key])) {
969
  if (strlen(trim($usersettings[$key]))==0) {
970
  if (!empty($defaults[$key])) {
988
  }
989
  }*/
990
  } else {
991
+ foreach($webdados_fb_open_graph_plugin_settings as $key) {
992
  if (!empty($defaults[$key])) {
993
  $usersettings[$key]=$defaults[$key];
994
  } else {
1002
  }
1003
  }
1004
 
1005
+ function webdados_fb_open_graph_upgrade() {
1006
+ global $webdados_fb_open_graph_plugin_version;
1007
  $upgrade=false;
1008
  //Upgrade from 0.5.4 - Last version with individual settings
1009
+ if (!$v=get_option('wonderm00n_open_graph_version')) {
1010
  //Convert settings
1011
  $upgrade=true;
1012
+ global $webdados_fb_open_graph_plugin_settings;
1013
+ foreach($webdados_fb_open_graph_plugin_settings as $key) {
1014
  $webdados_fb_open_graph_settings[$key]=get_option('wonderm00n_open_graph_'.$key);
1015
  }
1016
  // New fb_image_use_specific
1017
  $webdados_fb_open_graph_settings['fb_image_use_specific']=1;
1018
+ update_option('wonderm00n_open_graph_settings', $webdados_fb_open_graph_settings);
1019
+ foreach($webdados_fb_open_graph_plugin_settings as $key) {
1020
  delete_option('wonderm00n_open_graph_'.$key);
1021
  }
1022
  } else {
1023
+ if ($v<$webdados_fb_open_graph_plugin_version) {
1024
  //Any version upgrade
1025
  $upgrade=true;
1026
  }
1027
  }
1028
  //Set version on database
1029
  if ($upgrade) {
1030
+ update_option('wonderm00n_open_graph_version', $webdados_fb_open_graph_plugin_version);
1031
  }
1032
  }
1033
 
1034
 
1035
  //Uninstall stuff
1036
+ register_uninstall_hook(__FILE__, 'webdados_fb_open_graph_uninstall'); //NOT WORKING! WHY?
1037
+ function webdados_fb_open_graph_uninstall() {
1038
  //NOT WORKING! WHY?
1039
+ //global $webdados_fb_open_graph_plugin_settings;
1040
  //Remove data
1041
+ /*foreach($webdados_fb_open_graph_plugin_settings as $key) {
1042
  delete_option('wonderm00n_open_graph_'.$key);
1043
  }
1044
  delete_option('wonderm00n_open_graph_activated');*/
1046
 
1047
  //To avoid notices when updating options on settings-page.php
1048
  //Hey @flynsarmy you are here, see?
1049
+ function webdados_fb_open_graph_post($var, $default='') {
1050
  return isset($_POST[$var]) ? $_POST[$var] : $default;
1051
  }