Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.48 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Tabs class to display tabs next to user photo
  5. */
  6.  
  7. do_action('kleo_before_bp_tabs');
  8.  
  9. if (!class_exists('BpMembersTabs')):
  10. class BpMembersTabs {
  11.  
  12. private static $instance;
  13. public $tabs;
  14. public $active_tab = false;
  15. public $album_exists = false;
  16. public $has_data = array();
  17. public $fields_data = array();
  18.  
  19. public function __construct($tabs) {
  20.  
  21. self::$instance =& $this;
  22.  
  23. $this->tabs = $tabs;
  24. $this->active_tab = apply_filters( 'kleo_bp_profile_default_top_tab',FALSE );
  25.  
  26. $this->render();
  27. }
  28.  
  29. public static function &get_instance()
  30. {
  31. return self::$instance;
  32. }
  33.  
  34. public function render()
  35. {
  36. if (!is_array($this->tabs)) {
  37. return;
  38. }
  39.  
  40. echo '<dl class="tabs pill custom">';
  41.  
  42. foreach ($this->tabs as $key => $tab)
  43. {
  44. if (empty($tab)) {
  45. continue;
  46. }
  47. if (!isset($tab['group'])) {
  48. $tab['group'] = $tab['name'];
  49. $this->tabs[$key]['group'] = $tab['name'];
  50. }
  51.  
  52. $name = 'BpMembersTab_'.$tab['type'];
  53. if (class_exists($name)) {
  54. $tabcls = new $name($tab);
  55. }
  56. else {
  57. $tabcls = new BpMembersTab($tab);
  58. }
  59.  
  60. if ($tabcls->has_profile_data($tab['group'])) {
  61. echo $tabcls->title();
  62. }
  63.  
  64. }
  65. echo '</dl>';
  66.  
  67. echo '<ul class="tabs-content custom">';
  68. foreach ($this->tabs as $tab)
  69. {
  70.  
  71. if (isset($this->fields_data[$tab['group']]))
  72. {
  73. $active = '';
  74. if($this->active_tab == esc_attr(str_replace("%", "", sanitize_title_with_dashes($tab['name']))) ) {
  75. $active = 'active';
  76. }
  77.  
  78. echo '<li '.$active.' id="'.esc_attr(str_replace("%", "", sanitize_title_with_dashes($tab['name']))).'Tab" class="'.$active." ".$tab['class'].'">';
  79. echo $this->fields_data[$tab['group']];
  80. echo '</li>';
  81. }
  82. }
  83. echo '</ul>';
  84. }
  85.  
  86. }
  87. endif;
  88.  
  89. /**
  90. * Base Tab class that is used to render tab data
  91. * This can be extended by other types you need to define
  92. */
  93. if (!class_exists('BpMembersTab')):
  94. class BpMembersTab
  95. {
  96. /* tabs instance */
  97. public $tabs_instance;
  98. public $args;
  99.  
  100. public function __construct($args)
  101. {
  102. $this->tabs_instance = BpMembersTabs::get_instance();
  103.  
  104. $this->args = $args;
  105. }
  106.  
  107. public function title()
  108. {
  109. $active = '';
  110. if($this->tabs_instance->active_tab === FALSE || $this->tabs_instance->active_tab == $this->args["name"] )
  111. {
  112. $active = 'active';
  113. $this->tabs_instance->active_tab = esc_attr(str_replace("%", "",sanitize_title_with_dashes($this->args["name"])));
  114. }
  115.  
  116. return '<dd class="'.$active.'"><a href="#'.esc_attr(str_replace("%", "",sanitize_title_with_dashes($this->args["name"]))).'">'.$this->args["name"].'</a></dd>';
  117. }
  118.  
  119. public function has_profile_data($name)
  120. {
  121. $this->tabs_instance->has_data[$name] = false;
  122. $this->tabs_instance->fields_data[$name] = '';
  123.  
  124. if ( bp_is_active( 'xprofile' ) && get_group_id_by_name($name) ) :
  125. if ( bp_has_profile( 'profile_group_id='.get_group_id_by_name($name ) ) ) :
  126.  
  127. while ( bp_profile_groups() ) : bp_the_profile_group();
  128. if ( bp_profile_group_has_fields() ) :
  129.  
  130. $this->tabs_instance->fields_data[$name] .= '<dl class="dl-horizontal">';
  131. while ( bp_profile_fields() ) : bp_the_profile_field();
  132. if ( bp_field_has_data() ) :
  133. $this->tabs_instance->has_data[$name] = true;
  134. $this->tabs_instance->fields_data[$name] .= '<dt class="bp-field-name bp-field-id-' . __(bp_get_the_profile_field_id(), 'kleo_framework') . '">'. __(bp_get_the_profile_field_name(), 'kleo_framework') .'</dt>';
  135. $this->tabs_instance->fields_data[$name] .= '<dd class="bp-field-value bp-field-id-' . __(bp_get_the_profile_field_id(), 'kleo_framework') . '">'. __(bp_get_the_profile_field_value(), 'kleo_framework') .'</dd>';
  136. endif;
  137. endwhile;
  138. $this->tabs_instance->fields_data[$name] .= '</dl>';
  139.  
  140. endif;
  141. endwhile;
  142.  
  143. endif;
  144. endif;
  145.  
  146. if ($this->tabs_instance->has_data[$name] == true)
  147. return true;
  148. }
  149. }
  150. endif;
  151.  
  152. add_action('kleo_after_bp_memberstabs', 'my_func');
  153.  
  154.  
  155. /**
  156. * Cite Tab type - A different type to list profile fields
  157. */
  158. if (!class_exists('BpMembersTab_cite')):
  159. class BpMembersTab_cite extends BpMembersTab
  160. {
  161. public function __construct($args) {
  162. parent::__construct($args);
  163. }
  164.  
  165. public function has_profile_data($name)
  166. {
  167. $this->tabs_instance->has_data[$name] = false;
  168. $this->tabs_instance->fields_data[$name] = '';
  169.  
  170. if ( bp_is_active( 'xprofile' ) && get_group_id_by_name($name) ) :
  171. if ( bp_has_profile( 'profile_group_id='.get_group_id_by_name($name ) ) ) :
  172.  
  173. while ( bp_profile_groups() ) : bp_the_profile_group();
  174. if ( bp_profile_group_has_fields() ) :
  175.  
  176. while ( bp_profile_fields() ) : bp_the_profile_field();
  177. if ( bp_field_has_data() ) :
  178. $this->tabs_instance->has_data[$name] = true;
  179. $this->tabs_instance->fields_data[$name] .= '<div class="callout"><div class="bp-profile-details bp-field-id-' . bp_get_the_profile_field_id() . '">';
  180. $this->tabs_instance->fields_data[$name] .= bp_get_the_profile_field_name();
  181. $this->tabs_instance->fields_data[$name] .= '</div><div class="cite">'. bp_get_the_profile_field_value() .'</div></div>';
  182. endif;
  183. endwhile;
  184.  
  185. endif;
  186. endwhile;
  187.  
  188. endif;
  189. endif;
  190.  
  191. if ($this->tabs_instance->has_data[$name] == true)
  192. return true;
  193. }
  194. }
  195. endif;
  196.  
  197.  
  198. /**
  199. * Bp-Album tab type - Display member photos
  200. * extends BpMembersTab
  201. */
  202. if (!class_exists('BpMembersTab_bp_album')):
  203.  
  204. class BpMembersTab_bp_album extends BpMembersTab
  205. {
  206. public function __construct($args) {
  207. parent::__construct($args);
  208. }
  209.  
  210. public function title()
  211. {
  212. $active = '';
  213. if($this->tabs_instance->active_tab === FALSE || $this->tabs_instance->active_tab == $this->args["name"] )
  214. {
  215. $active = 'active';
  216. $this->tabs_instance->active_tab = esc_attr(str_replace("%", "",sanitize_title_with_dashes($this->args["name"])));
  217. }
  218.  
  219. return '<dd class="sliderEvent '.$active.'"><a href="#'.esc_attr(str_replace("%", "",sanitize_title_with_dashes($this->args["name"]))).'">'.$this->args["name"].' <span class="radius label alert">'.bp_album_get_total_picture_count().'</span></a></dd>';
  220. }
  221.  
  222. public function has_profile_data($name)
  223. {
  224. global $bp;
  225. $save_current_action = $bp->current_action;
  226. $bp->current_action = 'hack-to-show-all-albums';
  227.  
  228. if (!function_exists('bp_album_query_pictures')) {
  229. return false;
  230. }
  231.  
  232. bp_album_query_pictures('per_page=100');
  233. if ( bp_album_has_pictures() ) :
  234.  
  235. $this->tabs_instance->has_data[$name] = true;
  236. $this->tabs_instance->fields_data[$name] = '<div id="gallery-carousel">';
  237. while ( bp_album_has_pictures() ) : bp_album_the_picture();
  238. $this->tabs_instance->fields_data[$name] .= '<span class="circle">';
  239. $this->tabs_instance->fields_data[$name] .= '<a href="'.bp_album_get_picture_original_url().'" class="imagelink" data-rel="prettyPhoto[gallery2]">';
  240. $this->tabs_instance->fields_data[$name] .= '<span class="overlay"></span>';
  241. $this->tabs_instance->fields_data[$name] .= '<span class="read"><i class="icon-'. apply_filters('kleo_img_rounded_icon','heart').'"></i></span>';
  242. $this->tabs_instance->fields_data[$name] .= '<img src="'.bp_album_get_picture_original_url().'" alt="">';
  243. $this->tabs_instance->fields_data[$name] .= '</a>';
  244. $this->tabs_instance->fields_data[$name] .= '</span>';
  245. endwhile;
  246. $this->tabs_instance->fields_data[$name] .= '</div><!--end #gallery-carousel-->';
  247. $this->tabs_instance->fields_data[$name] .= '<div class="clearfix"></div>
  248. <div class="four columns centered btn-carousel hide-for-small">
  249. <small><a href="#" id="stanga-prev">'. __("PREVIOUS", 'kleo_framework').'</a>&nbsp; &nbsp; &nbsp;
  250. <a href="#" id="dreapta-next">'. __("NEXT", 'kleo_framework').'</a></small>
  251. </div>';
  252.  
  253. endif;
  254. $bp->current_action = $save_current_action;
  255. bp_album_query_pictures();
  256.  
  257. if ( isset($this->tabs_instance->has_data[$name]) ) {
  258. return true;
  259. }
  260. }
  261.  
  262. }
  263. endif;
  264.  
  265.  
  266. /**
  267. * rtMedia tab type - Display member photos
  268. * extends BpMembersTab
  269. */
  270. if (!class_exists('BpMembersTab_rt_media')):
  271.  
  272. class BpMembersTab_rt_media extends BpMembersTab
  273. {
  274. private $friendship;
  275. private $number = 0;
  276.  
  277. public function __construct($args) {
  278. parent::__construct($args);
  279. $this->friendship = new RTMediaFriends();
  280. }
  281.  
  282. public function title()
  283. {
  284. $active = '';
  285. if($this->tabs_instance->active_tab === FALSE || $this->tabs_instance->active_tab == $this->args["name"] )
  286. {
  287. $active = 'active';
  288. $this->tabs_instance->active_tab = esc_attr(str_replace("%", "",sanitize_title_with_dashes($this->args["name"])));
  289. }
  290.  
  291. return '<dd class="sliderEvent '.$active.'"><a href="#'.esc_attr(str_replace("%", "",sanitize_title_with_dashes($this->args["name"]))).'">'.$this->args["name"].' <span class="radius label alert">'.$this->number.'</span></a></dd>';
  292. }
  293.  
  294. public function has_profile_data ( $name ) {
  295. if (!class_exists('RTMedia')) {
  296. return false;
  297. }
  298.  
  299. global $wpdb;
  300. $user = $this->get_user();
  301. $displayed_user = bp_displayed_user_id();
  302. $table_name = $wpdb->base_prefix."rt_rtm_media";
  303.  
  304. $where = "SELECT * FROM {$table_name}";
  305. $where .= " WHERE {$table_name}.media_type = 'photo' AND media_author = $displayed_user";
  306. $where .= " AND ({$table_name}.privacy is NULL OR {$table_name}.privacy<=0";
  307. $where .= " AND {$table_name}.context = 'profile'";
  308. if ( $user ) {
  309. $where .= " OR {$table_name}.privacy=20";
  310. //if my profile
  311. if ($user == $displayed_user || is_super_admin())
  312. {
  313. $where .= " OR {$table_name}.privacy >= 40" ;
  314. }
  315. else
  316. {
  317. if ( class_exists ( 'BuddyPress' ) && bp_is_active ( 'friends' ) ) {
  318. //my friends
  319. $friends = $this->friendship->get_friends_cache ( $user );
  320. //if displayed user is my friend -> view its pictures
  321. if (in_array($displayed_user, $friends))
  322. {
  323. $where .= " OR {$table_name}.privacy=40";
  324. }
  325. }
  326. }
  327. }
  328. $where .= ") ORDER BY media_id DESC LIMIT ".apply_filters('kleo_rtmedia_photo_limit',100);
  329. $myrows = $wpdb->get_results($where);
  330.  
  331. if( $myrows && count($myrows) > 0 )
  332. {
  333. $this->tabs_instance->has_data[$name] = true;
  334. $this->tabs_instance->fields_data[$name] = '<div id="gallery-carousel" class="rtmedia-list-media rtm-gallery-list">';
  335.  
  336. foreach( $myrows as $row )
  337. {
  338. $this->number ++;
  339. $src = wp_get_attachment_image_src($row->media_id,'rt_media_thumbnail');
  340. $src_full = wp_get_attachment_image_src($row->media_id,'full');
  341.  
  342. $this->tabs_instance->fields_data[$name] .= '<span class="circle">';
  343. $this->tabs_instance->fields_data[$name] .= '<a href="' . trailingslashit( trailingslashit( get_rtmedia_user_link( $displayed_user ) ) . RTMEDIA_MEDIA_SLUG . '/' . rtmedia_id( $row->media_id ) ) . '" class="imagelink">';
  344. $this->tabs_instance->fields_data[$name] .= '<span class="overlay"></span>';
  345. $this->tabs_instance->fields_data[$name] .= '<span class="read"><i class="icon-'. apply_filters('kleo_img_rounded_icon','heart').'"></i></span>';
  346. $this->tabs_instance->fields_data[$name] .= '<img src="'.$src[0].'" alt="">';
  347. $this->tabs_instance->fields_data[$name] .= '</a>';
  348. $this->tabs_instance->fields_data[$name] .= '</span>';
  349.  
  350. }
  351. $this->tabs_instance->fields_data[$name] .= '</div>';
  352. $this->tabs_instance->fields_data[$name] .= '<div class="clearfix"></div>
  353. <div class="four columns centered btn-carousel hide-for-small">
  354. <small><a href="#" id="stanga-prev">'. __("PREVIOUS", 'kleo_framework').'</a>&nbsp; &nbsp; &nbsp;
  355. <a href="#" id="dreapta-next">'. __("NEXT", 'kleo_framework').'</a></small>
  356. </div>';
  357. }
  358.  
  359. if (isset($this->tabs_instance->has_data[$name]) && $this->tabs_instance->has_data[$name] == true)
  360. return true;
  361. }
  362.  
  363. function get_user () {
  364. if ( is_user_logged_in () ) {
  365. $user = get_current_user_id();
  366. } else {
  367. $user = 0;
  368. }
  369.  
  370. return $user;
  371. }
  372.  
  373. }
  374. endif;
  375.  
  376.  
  377. /**
  378. * Render the contents of a page next to user profile
  379. *
  380. */
  381. if (!class_exists('BpMembersTab_page')):
  382. class BpMembersTab_page extends BpMembersTab
  383. {
  384. public function has_profile_data($name)
  385. {
  386. $page = get_page_by_title($name);
  387. if ($page)
  388. {
  389. $this->tabs_instance->has_data[$name] = true;
  390. $content = apply_filters('the_content', $page->post_content);
  391. $this->tabs_instance->fields_data[$name] = $content;
  392.  
  393. return true;
  394. }
  395. else
  396. {
  397. $this->tabs_instance->has_data[$name] = false;
  398. return false;
  399. }
  400. }
  401. }
  402. endif;
  403.  
  404. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement