Skip to content

Instantly share code, notes, and snippets.

@ocean90
Created February 13, 2012 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ocean90/1819947 to your computer and use it in GitHub Desktop.
Save ocean90/1819947 to your computer and use it in GitHub Desktop.
wpSEO Monitor um Google+ Einkreisungen ergänzen.
<?php
/*
* Plugin Name: wpSEO Monitor Addon: Google+ Kennzahl
* Plugin URI: https://plus.google.com/101675293278434581718/posts/2E88QNTcXjE
* Description: Ergänzt den wpSEO Monitor um Google+ Einkreisungen. In wpSEO 3.0.3 bereits fester Bestandteil des Plugin.
* Version: 0.3
* Author: Dominik Schilling
* Author URI: http://wpgrafie.de
* License: GPLv2
*
* Changelog:
* 0.3 - 17.08.2012
* - Anpassung an API Ausgabe
*
* 0.2 - 20.05.2012
* - Anpassung an API Ausgabe
*
* 0.1 - 14.02.2012
* - Erstes Release
*/
final class DS_Extend_wpSEO_Monitor_with_GooglePlus {
/**
* Google+ User ID.
*
* Anmerkung: Hier die User ID anpassen.
*
* @var string
*/
private static $user_id = '';
/**
* Neue Kennzahl initialisieren.
*
* @link http://helpdesk.wpseo.de/manual/seo-monitor/
*
* @param array $data Vorhandene Kennzahlen
* @return array
*/
public static function init( $data ) {
add_action( 'ds_googleplus_count', array( __CLASS__, 'the_googleplus_circles' ) );
return array_merge(
$data,
array(
array(
'hook' => 'ds_googleplus_count',
'name' => 'Kreise',
'link' => sprintf(
'https://plus.google.com/%s/',
self::$user_id
)
)
)
);
}
/**
* API abfragen und Zähler ausgeben.
*
* @return void
*/
public static function the_googleplus_circles() {
// Cache abfragen
if ( ( $count = get_transient( 'ds_googleplus_circles' ) ) !== false ) {
echo number_format_i18n( $count );
return;
}
// API abfragen
$response = wp_remote_retrieve_body(
wp_remote_get(
sprintf(
'https://plus.google.com/_/socialgraph/lookup/incoming/?o=[null,null,"%s"]&n=1',
self::$user_id
)
)
);
// Fehler abfangen
if ( empty( $response ) ) {
echo '0';
return;
}
// Zahl filtern
preg_match( '/]\s]\s,,(\d+)]\s,/s', $response, $count );
$count = $count[1];
if ( empty( $count ) ) {
echo '0';
return;
}
// Caching
set_transient(
'ds_googleplus_circles',
$count,
60 * 60 * 24 // 1 Tag
);
// Ausgabe
echo number_format_i18n( $count );
}
}
add_filter(
'wpseo_set_monitor',
array(
'DS_Extend_wpSEO_Monitor_with_GooglePlus',
'init'
)
);
<?php
/*
Module Name: wpSEO Monitor Addon: Google+ Kennzahl
Description: Ergänzt den wpSEO Monitor um Google+ Einkreisungen. In wpSEO 3.0.3 bereits fester Bestandteil des Plugin. [Backend]
Author: Dominik Schilling
Author URI: http://wpgrafie.de
*/
/* Sicherheitsabfrage */
if ( !class_exists('Toolbox') ) {
die();
}
final class DS_Extend_wpSEO_Monitor_with_GooglePlus {
/**
* Google+ User ID
*
* Anmerkung: Hier die User ID anpassen.
*
* @var string
*/
private static $user_id = '';
/**
* Neue Kennzahl initialisieren.
*
* @link http://helpdesk.wpseo.de/manual/seo-monitor/
*
* @param array $data Vorhandene Kennzahlen
* @return array
*/
public static function init( $data ) {
add_action( 'ds_googleplus_count', array( __CLASS__, 'the_googleplus_circles' ) );
return array_merge(
$data,
array(
array(
'hook' => 'ds_googleplus_count',
'name' => 'Kreise',
'link' => sprintf(
'https://plus.google.com/%s/',
self::$user_id
)
)
)
);
}
/**
* API abfragen und Zähler ausgeben.
*
* @return void
*/
public static function the_googleplus_circles() {
// Cache abfragen
if ( ( $count = get_transient( 'ds_googleplus_circles' ) ) !== false ) {
echo number_format_i18n( $count );
return;
}
// API abfragen
$response = wp_remote_retrieve_body(
wp_remote_get(
sprintf(
'https://plus.google.com/_/socialgraph/lookup/incoming/?o=[null,null,"%s"]&n=1',
self::$user_id
)
)
);
// Fehler abfangen
if ( empty( $response ) ) {
echo '0';
return;
}
// Zahl filtern
preg_match( '/]\s]\s,,(\d+)]\s,/s', $response, $count );
$count = $count[1];
if ( empty( $count ) ) {
echo '0';
return;
}
// Caching
set_transient(
'ds_googleplus_circles',
$count,
60 * 60 * 24 // 1 Tag
);
// Ausgabe
echo number_format_i18n( $count );
}
}
add_filter(
'wpseo_set_monitor',
array(
'DS_Extend_wpSEO_Monitor_with_GooglePlus',
'init'
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment