File: /usr/local/www/apache24/noexec/open-the-door/wp-content/plugins/trustedblogs/class.trustedblogs.php
<?php
use Curl\Curl;
class TrustedBlogs {
private static $api_key_option = 'tb_api_key';
public static function init() {
add_action( 'save_post', array( 'TrustedBlogs', 'save_post' ), 99 );
add_action( 'wp_update_comment_count', array( 'TrustedBlogs', 'update_comment_count' ), 99 );
add_action( 'admin_menu', array( 'TrustedBlogs', 'plugin_menu' ) );
}
public static function plugin_activation() {
}
public static function plugin_deactivation() {
update_option( self::$api_key_option, '' );
}
public static function save_post( $post_id ) {
$post = get_post( $post_id );
$data = $post->to_array();
$data['post_link'] = get_permalink( $post_id );
$data['post_thumbnail'] = get_the_post_thumbnail( $post_id );
foreach ( $data['post_category'] as $key => $category ) {
$data['post_category'][ $key ] = get_category( $category )->name;
}
switch ( $post->post_status ) {
case 'publish':
self::api( array( 'data' => $data ), 'post', 'post' );
break;
case 'trash':
self::api( array( 'data' => $data ), 'post/' . $post->ID, 'delete' );
break;
}
}
public static function update_comment_count( $post_id ) {
self::save_post( $post_id );
}
public static function api( $data, $path, $action = 'post' ) {
if ( ! is_array( $data ) ) {
$data = array();
}
if ( ! isset( $data['data']['api_key'] ) ) {
$data['data']['api_key'] = get_option( self::$api_key_option );
}
$curl = new Curl();
$curl->setOpt( CURLOPT_ENCODING, 'gzip' );
$curl->$action( TRUSTEDBLOGS_HOST . '/api/' . TRUSTEDBLOGS_API_VERSION . '/' . $path, $data );
if ( $curl->error ) {
return false;
} else {
return true;
}
}
public static function plugin_menu() {
add_options_page( 'TRUSTED-BLOGS Optionen', 'TRUSTED-BLOGS', 'manage_options', 'trustedblogs-wordpress', array(
'TrustedBlogs',
'plugin_page'
) );
}
public static function plugin_page() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
$api_key = get_option( self::$api_key_option );
?>
<h1><?php _e( 'TRUSTED-BLOGS Plugin', 'trustedblogs-plugin' ) ?></h1>
<?php
if ( isset( $_POST[ self::$api_key_option ] ) ) {
update_option( self::$api_key_option, $_POST[ self::$api_key_option ] );
?>
<div class="updated"><p><strong><?php _e( 'settings saved.', 'trustedblogs-plugin' ) ?></strong></p></div>
<?php
$api_key = get_option( self::$api_key_option );
}
?>
<form name="tb-plugin-form" method="post" action="">
<p><?php _e( "API Key:", 'trustedblogs-plugin' ); ?></p>
<p><input type="text" name="<?php echo self::$api_key_option; ?>" value="<?php echo $api_key; ?>" size="40"
maxlength="32"></p>
<p class="submit"><input type="submit" name="Submit" class="button-primary"
value="<?php esc_attr_e( 'Save Changes' ) ?>"/></p>
</form>
<?php
}
}