PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/themes/_3/inc/brick-meta.class.php

https://github.com/DrewAPicture/bricks
PHP | 167 lines | 92 code | 21 blank | 54 comment | 19 complexity | 6418626ac4d32d5db36405a96d9556f8 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. * _3 Brick Meta Class
  4. *
  5. * Long desc
  6. *
  7. * @package _3
  8. * @since 1.0
  9. */
  10. class Brick_Meta {
  11. public $id;
  12. /**
  13. * Init
  14. */
  15. function __construct( $id = null ) {
  16. $this->id = $id;
  17. }
  18. /**
  19. * Get Meta
  20. */
  21. function get_meta() {
  22. if ( get_post_type( $this->id ) == 'brick' ) {
  23. $keys = get_post_custom( $this->id );
  24. foreach ( $keys as $key => $value ) {
  25. $data->$key = get_post_meta( $this->id, $key, true );
  26. }
  27. return $data;
  28. }
  29. }
  30. /**
  31. * Get Brick Title
  32. */
  33. function get_brick_title() {
  34. $meta = $this->get_meta();
  35. if ( isset( $meta->_brick_title ) )
  36. return esc_html( $meta->_brick_title );
  37. }
  38. /**
  39. * Brick Title
  40. */
  41. function brick_title( $wrap = '' ) {
  42. printf( '<%1$s>%2$s</%3$s>', $wrap, $this->get_brick_title(), $wrap );
  43. }
  44. /**
  45. * Get Brick Columns
  46. */
  47. function get_brick_cols() {
  48. }
  49. /**
  50. * Get Brick Value
  51. */
  52. function get_brick_value() {
  53. $meta = $this->get_meta();
  54. if ( isset( $meta->_brick_value ) )
  55. return $meta->_brick_value;
  56. else
  57. return;
  58. }
  59. /**
  60. * Brick Value
  61. */
  62. function brick_value( $wrap = '' ) {
  63. printf( '<%1$s>%2$s</%3$s>', $wrap, $this->get_brick_value(), $wrap );
  64. }
  65. /**
  66. * Retrieve Stats
  67. */
  68. function retrieve_stats( $type = '' ) {
  69. if ( $type = 'tweets' )
  70. $url = 'http://api.twitter.com/1/users/show.json?screen_name=DrewAPicture&include_entities=true';
  71. elseif ( $type = 'forrst' )
  72. $url = 'http://forrst.com/api/v2/users/posts?username=DrewAPicture';
  73. elseif ( $type = 'gists' )
  74. return;
  75. // Bail if no type
  76. else
  77. return;
  78. $resp = wp_remote_retrieve_body( wp_remote_get( $url ) );
  79. $stats = json_decode( $resp );
  80. if ( $type == 'tweets' )
  81. return $stats->statuses_count;
  82. elseif ( $type == 'forrst' )
  83. return $stats->resp[0]->user->posts;
  84. elseif ( $type == 'gists' )
  85. return;
  86. }
  87. /**
  88. * Get Brick Stats
  89. */
  90. function get_brick_stats() {
  91. $meta = $this->get_meta();
  92. if ( isset( $meta->_stats_type ) && function_exists( 'stats_count' ) ) {
  93. $cached = get_transient( $meta->_stats_type . '-count' );
  94. if ( false == $cached ) {
  95. $count = number_format( stats_count( $meta->_stats_type ), 0, '', ',' );
  96. set_transient( $meta->_stats_type . '-count', $count, 3600 );
  97. }
  98. return $cached;
  99. }
  100. }
  101. /**
  102. * Brick Stats
  103. */
  104. function brick_stats( $wrap = '' ) {
  105. if ( $this->get_brick_stats() )
  106. printf( '<%1$s>%2$s</%3$s>', $wrap, $this->get_brick_stats(), $wrap );
  107. }
  108. /**
  109. * Get Brick Desc
  110. */
  111. function get_brick_desc() {
  112. $meta = $this->get_meta();
  113. if ( isset( $meta->_brick_desc ) )
  114. return $meta->_brick_desc;
  115. }
  116. /**
  117. * Brick Desc
  118. */
  119. function brick_desc( $wrap = '' ) {
  120. printf( '<%1$s>%2$s</%3$s>', $wrap, $this->get_brick_desc(), $wrap );
  121. }
  122. /**
  123. * Brick URL Disabled
  124. */
  125. function is_brick_url_disabled() {
  126. $meta = $this->get_meta();
  127. if ( isset( $meta->_disable_brick_url ) )
  128. return true;
  129. }
  130. /**
  131. * Get Brick URL
  132. */
  133. function get_brick_url() {
  134. $meta = $this->get_meta();
  135. if ( isset( $meta->_brick_url ) && ! isset( $meta->_disable_brick_url ) )
  136. return esc_url( $meta->_brick_url );
  137. }
  138. /**
  139. * Brick URL
  140. */
  141. function brick_url( $title = '' ) {
  142. $meta = $this->get_meta();
  143. if ( ! isset( $meta->_disable_brick_url ) )
  144. printf( '<a href="%1$s">%2$s</a>', $this->get_brick_url(), esc_attr( $title ) );
  145. }
  146. }