PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/liguelista/library/classes/javo-post-class.php

https://gitlab.com/oxidigitaluser/liguelista
PHP | 207 lines | 192 code | 6 blank | 9 comment | 17 complexity | ab3b5777bc474612eba1ff14c6311c94 MD5 | raw file
  1. <?php
  2. class get_char{
  3. var $title
  4. , $origin_title
  5. , $post
  6. , $content
  7. , $p_type
  8. , $p_id
  9. , $excerpt
  10. , $excerpt_meta
  11. , $area
  12. , $price
  13. , $sns
  14. , $author
  15. , $author_name
  16. , $lister_page
  17. , $author_item_count;
  18. public function __construct($post){
  19. $this->post = $post;
  20. $this->content = apply_filters('the_content', $this->post->post_content);
  21. $this->origin_title = sprintf("<a href='%s'>%s</a>", get_permalink($post->ID), $post->post_title);
  22. $this->p_type = get_post_type($post->ID);
  23. $this->p_id = $post->ID;
  24. $this->area = sprintf("%s %s", $this->__meta("area"), $this->__meta("area_Postfix"));
  25. $this->price = sprintf("%s%s %s"
  26. , $this->__meta("price_Postfix")
  27. , number_format((int)$this->__meta("sale_price"))
  28. , ((strpos(strtolower($this->__hasStatus()), "rent") !== false)? "/ ".__("M", "javo_fr") : ""));
  29. $sns = Array("sns-facebook", "sns-twitter", "sns-google");
  30. $sns_output = "";
  31. foreach($sns as $index=> $class_name)
  32. $sns_output .= sprintf('<span><i class="%s" data-title="%s" data-url="%s"></i></span>'
  33. ,$class_name, $post->post_title, get_permalink($post->ID)
  34. );
  35. $this->sns = $sns_output;
  36. switch( $this->__meta('item_author') ){
  37. case "admin":
  38. $this->author = get_user_by('email', get_option( 'admin_email' ));
  39. break;
  40. case "other":
  41. if( (int)$this->__meta('item_author_id') > 0){
  42. $this->author = get_userdata((int)$this->__meta('item_author_id'));
  43. }else{
  44. $this->author = get_userdata($post->post_author);
  45. };
  46. break;
  47. default:
  48. $this->author = get_userdata($post->post_author);
  49. };
  50. $this->author_name = !empty($this->author)? sprintf("%s %s", $this->author->first_name, $this->author->last_name):null;
  51. $this->author_item_count = $this->get_author_item_count();
  52. $javo_lister_page = "";
  53. if(!empty($this->author)){
  54. $args = Array("author"=>$this->author->ID, "posts_per_page"=>1, "post_type"=>"lister");
  55. $lister_post = get_posts($args);
  56. $javo_lister_page = get_site_url();
  57. if(!empty($lister_post)){
  58. $javo_lister_page = get_permalink( $lister_post[0]->ID );
  59. };
  60. //wp_reset_postdata();
  61. };
  62. $this->lister_page = $javo_lister_page;
  63. $this->excerpt_meta = sprintf("%s / %s / %s / %s"
  64. , ($this->p_type == "item" ? $this->__meta("area")." ".__("Sq ft", "javo_fr") : null)
  65. , ($this->p_type == "item" ? $this->__meta("bedrooms")." ".__("Beds", "javo_fr") : $this->author->user_login)
  66. , ($this->p_type == "item" ? $this->__meta("bathrooms")." ".__("Baths", "javo_fr") : date("Y-m-d", strtotime($this->post->post_date)))
  67. , ($this->p_type == "item" ? $this->__meta("parking")." ".__("Parking", "javo_fr") : $this->__cate("category", __("No category", 'javo_fr'), true))
  68. );
  69. switch($this->p_type){
  70. case "item": $this->__item($post); break;
  71. case "post": default: $this->__post($post); break;
  72. };
  73. }
  74. public function __item($post){
  75. $this->title = sprintf("<a href='%s'>%s%s%s</a>"
  76. , get_permalink($post->ID)
  77. , $this->__meta("price_Postfix")
  78. , number_format((int)$this->__meta("sale_price"))
  79. , ((strpos(strtolower($this->__hasStatus()), "rent") !== false)? " / ".__("Month", "javo_fr") : "")
  80. );
  81. }
  82. public function __hasStatus(){
  83. /*
  84. $output = "";
  85. $terms = wp_get_post_terms($this->post->ID, "item_status");
  86. if(is_Array($terms))
  87. foreach($terms as $term)
  88. $output = $term->name;
  89. return ($output != "")? $output : false;
  90. */
  91. return "";
  92. }
  93. public function __post($post){
  94. $this->title = sprintf("<a href='%s'>%s</a>", get_permalink($post->ID), $post->post_title);
  95. }
  96. public function __meta($meta_key){
  97. return get_post_meta($this->p_id, $meta_key, true);
  98. }
  99. public function a_meta($meta_key){
  100. return !empty($this->author)? get_user_meta($this->author->ID, $meta_key, true):null;
  101. }
  102. public function __excerpt($length=120, $html=false){
  103. $javo__excerpt = javo_str_cut(strip_tags($this->post->post_content), (int)$length);
  104. if($html){
  105. $javo__excerpt = sprintf('<a href="%s" target="_self">%s</a>'
  106. , get_permalink($this->post->ID)
  107. , $javo__excerpt
  108. );
  109. };
  110. return $javo__excerpt;
  111. }
  112. public function get_avatar($strip_img=false){
  113. $avatar_id = $this->a_meta("avatar");
  114. $avatar_meta = wp_get_attachment_image_src($avatar_id, "javo-avatar");
  115. $output = sprintf("<img src='%s'>", $avatar_meta[0]);
  116. return ($strip_img == false)? $output : $avatar_meta[0];
  117. }
  118. public function in_features($type=0){
  119. global $javo_tso;
  120. if($javo_tso->get('show_unset_features') != 'hidden'){
  121. $terms = get_terms("item_amenities", Array("hide_empty"=> false));
  122. }else{
  123. $terms = wp_get_post_terms($this->post->ID, "item_amenities");
  124. }
  125. $output = "";
  126. switch($type){
  127. case 1:
  128. foreach($terms as $term)
  129. $output .= sprintf("<p class='features %s'><i class='icon'></i> %s</p>"
  130. , ((has_term($term->term_id, "item_amenities", $this->post))? "active" :"" )
  131. , $term->name
  132. );
  133. break;
  134. case 4:
  135. foreach($terms as $term)
  136. $output .= sprintf("<p class='col-md-3 features %s'><i class='icon'></i> %s</p>"
  137. , ((has_term($term->term_id, "item_amenities", $this->post))? "active" :"" )
  138. , $term->name
  139. );
  140. $output = sprintf("<div class='row'>%s</div>", $output);
  141. break;
  142. case 0:
  143. default:
  144. $i = 0;
  145. foreach($terms as $term){
  146. $output .= sprintf("<p class='col-md-4 features %s'><i class='icon'></i> %s</p>"
  147. , ((has_term($term->term_id, "item_amenities", $this->post))? " active":"" )
  148. , $term->name
  149. );
  150. };
  151. break;
  152. }
  153. return sprintf('<div class="row">%s</div>', $output);
  154. }
  155. public function get_author_item_count(){
  156. $args = Array();
  157. if(!empty($this->author)){
  158. $args = Array(
  159. 'author'=> $this->author->ID
  160. , 'post_type'=> 'item'
  161. , 'post_status'=> 'publish'
  162. , 'posts_per_page'=> -1
  163. );
  164. };
  165. return count(get_posts($args));
  166. }
  167. public function author_sns($sns=NULL, $html=true){
  168. if($sns == NULL ) return;
  169. $origin_sns = Array(
  170. 'twitter'=> sprintf('http://twitter.com/%s', $this->a_meta('twitter'))
  171. , 'facebook'=> sprintf('http://facebook.com/%s', $this->a_meta('facebook'))
  172. );
  173. switch($sns){
  174. case 'twitter':
  175. return $html ? sprintf('<a href="%s" target="_blank">%s</a>'
  176. , $origin_sns['twitter']
  177. , $this->a_meta('twitter')) : $origin_sns['twitter'];
  178. break;
  179. case 'facebook':
  180. return $html ? sprintf('<a href="%s" target="_blank">%s</a>'
  181. , $origin_sns['facebook']
  182. , $this->a_meta('facebook')) : $origin_sns['facebook'];
  183. break;
  184. default:
  185. return __('not found information.', 'javo_fr');
  186. };
  187. }
  188. public function __cate($tax_name, $default=null, $just=false){
  189. $terms = wp_get_post_terms($this->post->ID, $tax_name);
  190. if($terms != NULL){
  191. $output = "";
  192. if(!$just){
  193. foreach($terms as $item) $output .= $item->name.", ";
  194. return substr(trim($output), 0, -1);
  195. }else{
  196. return $terms[0]->name;
  197. };
  198. };
  199. return false;
  200. }
  201. };