/themes/_3/inc/brick-meta.class.php
PHP | 167 lines | 92 code | 21 blank | 54 comment | 19 complexity | 6418626ac4d32d5db36405a96d9556f8 MD5 | raw file
Possible License(s): AGPL-1.0
- <?php
- /**
- * _3 Brick Meta Class
- *
- * Long desc
- *
- * @package _3
- * @since 1.0
- */
- class Brick_Meta {
- public $id;
- /**
- * Init
- */
- function __construct( $id = null ) {
- $this->id = $id;
- }
- /**
- * Get Meta
- */
- function get_meta() {
- if ( get_post_type( $this->id ) == 'brick' ) {
- $keys = get_post_custom( $this->id );
- foreach ( $keys as $key => $value ) {
- $data->$key = get_post_meta( $this->id, $key, true );
- }
- return $data;
- }
- }
- /**
- * Get Brick Title
- */
- function get_brick_title() {
- $meta = $this->get_meta();
- if ( isset( $meta->_brick_title ) )
- return esc_html( $meta->_brick_title );
- }
- /**
- * Brick Title
- */
- function brick_title( $wrap = '' ) {
- printf( '<%1$s>%2$s</%3$s>', $wrap, $this->get_brick_title(), $wrap );
- }
- /**
- * Get Brick Columns
- */
- function get_brick_cols() {
- }
- /**
- * Get Brick Value
- */
- function get_brick_value() {
- $meta = $this->get_meta();
- if ( isset( $meta->_brick_value ) )
- return $meta->_brick_value;
- else
- return;
- }
- /**
- * Brick Value
- */
- function brick_value( $wrap = '' ) {
- printf( '<%1$s>%2$s</%3$s>', $wrap, $this->get_brick_value(), $wrap );
- }
- /**
- * Retrieve Stats
- */
- function retrieve_stats( $type = '' ) {
- if ( $type = 'tweets' )
- $url = 'http://api.twitter.com/1/users/show.json?screen_name=DrewAPicture&include_entities=true';
- elseif ( $type = 'forrst' )
- $url = 'http://forrst.com/api/v2/users/posts?username=DrewAPicture';
- elseif ( $type = 'gists' )
- return;
- // Bail if no type
- else
- return;
-
- $resp = wp_remote_retrieve_body( wp_remote_get( $url ) );
-
- $stats = json_decode( $resp );
-
- if ( $type == 'tweets' )
- return $stats->statuses_count;
- elseif ( $type == 'forrst' )
- return $stats->resp[0]->user->posts;
- elseif ( $type == 'gists' )
- return;
- }
-
- /**
- * Get Brick Stats
- */
- function get_brick_stats() {
- $meta = $this->get_meta();
- if ( isset( $meta->_stats_type ) && function_exists( 'stats_count' ) ) {
- $cached = get_transient( $meta->_stats_type . '-count' );
- if ( false == $cached ) {
- $count = number_format( stats_count( $meta->_stats_type ), 0, '', ',' );
- set_transient( $meta->_stats_type . '-count', $count, 3600 );
- }
- return $cached;
- }
- }
-
- /**
- * Brick Stats
- */
- function brick_stats( $wrap = '' ) {
- if ( $this->get_brick_stats() )
- printf( '<%1$s>%2$s</%3$s>', $wrap, $this->get_brick_stats(), $wrap );
- }
-
- /**
- * Get Brick Desc
- */
- function get_brick_desc() {
- $meta = $this->get_meta();
- if ( isset( $meta->_brick_desc ) )
- return $meta->_brick_desc;
- }
- /**
- * Brick Desc
- */
- function brick_desc( $wrap = '' ) {
- printf( '<%1$s>%2$s</%3$s>', $wrap, $this->get_brick_desc(), $wrap );
- }
- /**
- * Brick URL Disabled
- */
- function is_brick_url_disabled() {
- $meta = $this->get_meta();
- if ( isset( $meta->_disable_brick_url ) )
- return true;
- }
- /**
- * Get Brick URL
- */
- function get_brick_url() {
- $meta = $this->get_meta();
- if ( isset( $meta->_brick_url ) && ! isset( $meta->_disable_brick_url ) )
- return esc_url( $meta->_brick_url );
- }
- /**
- * Brick URL
- */
- function brick_url( $title = '' ) {
- $meta = $this->get_meta();
- if ( ! isset( $meta->_disable_brick_url ) )
- printf( '<a href="%1$s">%2$s</a>', $this->get_brick_url(), esc_attr( $title ) );
- }
- }