/app/main/controllers/template/rtmedia-functions.php

  1. <?php 
  2.  
  3. /** 
  4. * Checks at any point of time any media is left to be processed in the db pool 
  5. * 
  6. * @global RTMediaQuery $rtmedia_query 
  7. * 
  8. * @return bool 
  9. */ 
  10. function have_rtmedia() { 
  11.  
  12. global $rtmedia_query; 
  13.  
  14. return $rtmedia_query->have_media(); 
  15.  
  16.  
  17. /** 
  18. * Rewinds the db pool of media album and resets it to beginning 
  19. * 
  20. * @global RTMediaQuery $rtmedia_query 
  21. * 
  22. * @return bool 
  23. */ 
  24. function rewind_rtmedia() { 
  25.  
  26. global $rtmedia_query; 
  27.  
  28. return $rtmedia_query->rewind_media(); 
  29.  
  30.  
  31. /** 
  32. * moves ahead in the loop of media within the album 
  33. * 
  34. * @global RTMediaQuery $rtmedia_query 
  35. * 
  36. * @return object 
  37. */ 
  38. function rtmedia() { 
  39.  
  40. global $rtmedia_query; 
  41.  
  42. return $rtmedia_query->rtmedia(); 
  43.  
  44.  
  45. /** 
  46. * echo the number of media in particular album 
  47. * 
  48. * @global array $rtmedia_backbone 
  49. * @global object $rtmedia_media 
  50. * 
  51. * @return number 
  52. */ 
  53. function rtmedia_album_mediacounter() { 
  54.  
  55. global $rtmedia_backbone; 
  56.  
  57. if ( $rtmedia_backbone['backbone'] ) { 
  58. echo '<%= media_count %>'; 
  59. } else { 
  60. global $rtmedia_media; 
  61.  
  62. return rtm_get_album_media_count( $rtmedia_media->id ); 
  63.  
  64.  
  65. /** 
  66. * echo the title of the media 
  67. * 
  68. * @global array $rtmedia_backbone 
  69. * @global object $rtmedia_media 
  70. * 
  71. * @return string 
  72. */ 
  73. function rtmedia_title() { 
  74.  
  75. global $rtmedia_backbone; 
  76.  
  77. if ( $rtmedia_backbone['backbone'] ) { 
  78. echo '<%= media_title %>'; 
  79. } else { 
  80. global $rtmedia_media; 
  81.  
  82. return stripslashes( esc_html( $rtmedia_media->media_title ) ); 
  83.  
  84.  
  85. /** 
  86. * echo the album name of the media 
  87. * 
  88. * @global object $rtmedia_media 
  89. * 
  90. * @return bool/string 
  91. */ 
  92. function rtmedia_album_name() { 
  93.  
  94. global $rtmedia_media; 
  95.  
  96. if ( $rtmedia_media->album_id ) { 
  97. if ( 'album' === rtmedia_type( $rtmedia_media->album_id ) ) { 
  98. return get_rtmedia_title( $rtmedia_media->album_id ); 
  99. } else { 
  100. return false; 
  101. } else { 
  102. return false; 
  103.  
  104.  
  105. /** 
  106. * Get Title for RTMedia Gallery 
  107. * 
  108. * @global RTMediaQuery $rtmedia_query 
  109. * @global RTMedia $rtmedia 
  110. * 
  111. * @return bool|string 
  112. */ 
  113. function get_rtmedia_gallery_title() { 
  114.  
  115. global $rtmedia_query, $rtmedia; 
  116.  
  117. $title = false; 
  118.  
  119. if ( isset( $rtmedia_query->query['media_type'] ) && 'album' === $rtmedia_query->query['media_type'] && isset( $rtmedia_query->media_query['album_id'] ) && '' !== $rtmedia_query->media_query['album_id'] ) { 
  120. $id = $rtmedia_query->media_query['album_id']; 
  121. $title = get_rtmedia_title( $id ); 
  122. } elseif ( isset( $rtmedia_query->media_query['media_type'] ) && ! is_array( $rtmedia_query->media_query['media_type'] ) && '' !== $rtmedia_query->media_query['media_type'] ) { 
  123. $current_media_type = $rtmedia_query->media_query['media_type']; 
  124.  
  125. if ( ! empty( $current_media_type ) && is_array( $rtmedia->allowed_types ) && isset( $rtmedia->allowed_types[ $current_media_type ] ) && is_array( $rtmedia->allowed_types[ $current_media_type ] ) && isset( $rtmedia->allowed_types[ $current_media_type ]['plural_label'] ) ) { 
  126. $title = sprintf( '%s %s', esc_html__( 'All', 'buddypress-media' ), $rtmedia->allowed_types[ $current_media_type ]['plural_label'] ); 
  127.  
  128. $title = apply_filters( 'rtmedia_gallery_title', $title ); 
  129.  
  130. return $title; 
  131.  
  132.  
  133. /** 
  134. * Get media title using media ID 
  135. * 
  136. * @param int $id media id 
  137. * 
  138. * @return string 
  139. */ 
  140. function get_rtmedia_title( $id ) { 
  141.  
  142. $rtmedia_model = new RTMediaModel(); 
  143. $title = $rtmedia_model->get( array( 
  144. 'id' => $id,  
  145. ) ); 
  146.  
  147. return $title[0]->media_title; 
  148.  
  149.  
  150. /** 
  151. * Media author's profile pic 
  152. * 
  153. * @global array $rtmedia_backbone 
  154. * @global object $rtmedia_media 
  155. * 
  156. * @param bool $show_link 
  157. * @param bool $echo 
  158. * @param bool $author_id 
  159. * 
  160. * @return string 
  161. */ 
  162. function rtmedia_author_profile_pic( $show_link = true, $echo = true, $author_id = false ) { 
  163.  
  164. global $rtmedia_backbone; 
  165.  
  166. if ( $rtmedia_backbone['backbone'] ) { 
  167. echo ''; 
  168. } else { 
  169. if ( empty( $author_id ) ) { 
  170. global $rtmedia_media; 
  171.  
  172. $author_id = $rtmedia_media->media_author; 
  173.  
  174. $show_link = apply_filters( 'rtmedia_single_media_show_profile_picture_link', $show_link ); 
  175. $profile_pic = ''; 
  176.  
  177. if ( $show_link ) { 
  178. $profile_pic .= "<a href='" . esc_url( get_rtmedia_user_link( $author_id ) ) . "' title='" . esc_attr( rtmedia_get_author_name( $author_id ) ) . "'>"; 
  179.  
  180. $size = apply_filters( 'rtmedia_single_media_profile_picture_size', 90 ); 
  181.  
  182. if ( function_exists( 'bp_get_user_has_avatar' ) ) { 
  183. if ( bp_core_fetch_avatar( array( 
  184. 'item_id' => $author_id,  
  185. 'object' => 'user',  
  186. 'no_grav' => false,  
  187. 'html' => false,  
  188. ) ) !== bp_core_avatar_default() 
  189. ) { 
  190. $profile_pic .= bp_core_fetch_avatar( array( 
  191. 'item_id' => $author_id,  
  192. 'object' => 'user',  
  193. 'no_grav' => false,  
  194. 'html' => true,  
  195. 'width' => $size,  
  196. 'height' => $size,  
  197. ) ); 
  198. } else { 
  199. $profile_pic .= "<img src='" . esc_url( bp_core_avatar_default() ) . "' width='" . esc_attr( $size ) . "' height='" . esc_attr( $size ) . "' />"; 
  200. } else { 
  201. $profile_pic .= get_avatar( $author_id, $size ); 
  202.  
  203. if ( $show_link ) { 
  204. $profile_pic .= '</a>'; 
  205.  
  206. if ( $echo ) { 
  207. echo $profile_pic; // @codingStandardsIgnoreLine 
  208. } else { 
  209. return $profile_pic; 
  210. }// End if(). 
  211.  
  212.  
  213. /** 
  214. * Media's author link 
  215. * 
  216. * @global array $rtmedia_backbone 
  217. * @global object $rtmedia_media 
  218. * 
  219. * @param bool $show_link 
  220. */ 
  221. function rtmedia_author_name( $show_link = true ) { 
  222.  
  223. global $rtmedia_backbone; 
  224.  
  225. if ( $rtmedia_backbone['backbone'] ) { 
  226. echo apply_filters( 'rtmedia_media_author_backbone', '', $show_link ); // @codingStandardsIgnoreLine 
  227. } else { 
  228. global $rtmedia_media; 
  229.  
  230. $show_link = apply_filters( 'rtmedia_single_media_show_profile_name_link', $show_link ); 
  231.  
  232. if ( $show_link ) { 
  233. echo "<a href='" . esc_url( get_rtmedia_user_link( $rtmedia_media->media_author ) ) . "' title='" . esc_attr( rtmedia_get_author_name( $rtmedia_media->media_author ) ) . "'>"; 
  234.  
  235. echo esc_html( rtmedia_get_author_name( $rtmedia_media->media_author ) ); 
  236.  
  237. if ( $show_link ) { 
  238. echo '</a>'; 
  239.  
  240.  
  241. /** 
  242. * Get media author name using user ID 
  243. * 
  244. * @param $user_id 
  245. * 
  246. * @return string 
  247. */ 
  248. function rtmedia_get_author_name( $user_id ) { 
  249. if ( function_exists( 'bp_core_get_user_displayname' ) ) { 
  250. return bp_core_get_user_displayname( $user_id ); 
  251. } else { 
  252. $user = get_userdata( $user_id ); 
  253.  
  254. if ( $user ) { 
  255. return $user->display_name; 
  256.  
  257.  
  258. /** 
  259. * Media Gallery CSS classes 
  260. * 
  261. * @global RTMediaQuery $rtmedia_query 
  262. */ 
  263. function rtmedia_media_gallery_class() { 
  264.  
  265. global $rtmedia_query; 
  266.  
  267. $classes = ''; 
  268.  
  269. if ( isset( $rtmedia_query->media_query ) && isset( $rtmedia_query->media_query['context_id'] ) ) { 
  270. $classes = 'context-id-' . esc_attr( $rtmedia_query->media_query['context_id'] ); 
  271.  
  272. echo esc_attr( apply_filters( 'rtmedia_gallery_class_filter', $classes ) ); 
  273.  
  274. /** 
  275. * Get RTMedia ID using Post(Media) ID 
  276. * 
  277. * @global array $rtmedia_backbone 
  278. * @global object $rtmedia_media 
  279. * 
  280. * @param bool|int $media_id 
  281. * 
  282. * @return bool|string 
  283. */ 
  284. function rtmedia_id( $media_id = false ) { 
  285.  
  286. global $rtmedia_backbone; 
  287.  
  288. if ( $rtmedia_backbone['backbone'] ) { 
  289. return '<%= id %>'; 
  290.  
  291. if ( $media_id ) { 
  292. $model = new RTMediaModel(); 
  293. $media = $model->get_media( array( 
  294. 'media_id' => $media_id,  
  295. ), 0, 1 ); 
  296.  
  297. if ( isset( $media ) && count( $media ) > 0 ) { 
  298. return $media[0]->id; 
  299.  
  300. return false; 
  301. } else { 
  302. global $rtmedia_media; 
  303.  
  304. return $rtmedia_media->id; 
  305.  
  306.  
  307. /** 
  308. * Get Post(Media) ID using RTMedia ID 
  309. * 
  310. * @global object $rtmedia_media 
  311. * 
  312. * @param bool|int $id 
  313. * 
  314. * @return int 
  315. */ 
  316. function rtmedia_media_id( $id = false ) { 
  317.  
  318. if ( $id ) { 
  319. $model = new RTMediaModel(); 
  320. $media = $model->get_media( array( 
  321. 'id' => $id,  
  322. ), 0, 1 ); 
  323.  
  324. return $media[0]->media_id; 
  325. } else { 
  326. global $rtmedia_media; 
  327.  
  328. return $rtmedia_media->media_id; 
  329.  
  330.  
  331. /** 
  332. * Get Media extension using ID 
  333. * 
  334. * @global object $rtmedia_media 
  335. * 
  336. * @param bool|int $id 
  337. * 
  338. * @return string 
  339. */ 
  340. function rtmedia_media_ext( $id = false ) { 
  341.  
  342. if ( $id ) { 
  343. $model = new RTMediaModel(); 
  344. $media = $model->get_media( array( 
  345. 'id' => $id,  
  346. ), 0, 1 ); 
  347.  
  348. if ( isset( $media[0] ) ) { 
  349. $filepath = get_attached_file( $media[0]->media_id ); 
  350. $filetype = wp_check_filetype( $filepath ); 
  351.  
  352. return $filetype['ext']; 
  353. } else { 
  354. global $rtmedia_media; 
  355.  
  356. $filepath = get_attached_file( $rtmedia_media->media_id ); 
  357. $filetype = wp_check_filetype( $filepath ); 
  358.  
  359. return $filetype['ext']; 
  360.  
  361.  
  362. /** 
  363. * Get Activity ID using Media ID 
  364. * 
  365. * @global object $rtmedia_media 
  366. * 
  367. * @param bool|int $id 
  368. * 
  369. * @return int 
  370. */ 
  371. function rtmedia_activity_id( $id = false ) { 
  372.  
  373. if ( $id ) { 
  374. $model = new RTMediaModel(); 
  375. $media = $model->get_media( array( 
  376. 'id' => $id,  
  377. ), 0, 1 ); 
  378.  
  379. return $media[0]->activity_id; 
  380. } else { 
  381. global $rtmedia_media; 
  382.  
  383. return $rtmedia_media->activity_id; 
  384.  
  385.  
  386. /** 
  387. * Get Media type using Media ID 
  388. * 
  389. * @global object $rtmedia_media 
  390. * 
  391. * @param bool|int $id 
  392. * 
  393. * @return bool|string 
  394. */ 
  395. function rtmedia_type( $id = false ) { 
  396.  
  397. if ( $id ) { 
  398. $model = new RTMediaModel(); 
  399. $media = $model->get_media( array( 
  400. 'id' => $id,  
  401. ), 0, 1 ); 
  402.  
  403. if ( isset( $media[0] ) && isset( $media[0]->media_type ) ) { 
  404. return $media[0]->media_type; 
  405. } else { 
  406. return false; 
  407. } else { 
  408. global $rtmedia_media; 
  409.  
  410. return $rtmedia_media->media_type; 
  411.  
  412.  
  413. /** 
  414. * Get cover art using Media ID 
  415. * 
  416. * @global object $rtmedia_media 
  417. * 
  418. * @param bool|int $id 
  419. * 
  420. * @return string 
  421. */ 
  422. function rtmedia_cover_art( $id = false ) { 
  423.  
  424. if ( $id ) { 
  425. $model = new RTMediaModel(); 
  426. $media = $model->get_media( array( 
  427. 'id' => $id,  
  428. ), 0, 1 ); 
  429.  
  430. return $media[0]->cover_art; 
  431. } else { 
  432. global $rtmedia_media; 
  433.  
  434. return $rtmedia_media->cover_art; 
  435.  
  436.  
  437. /** 
  438. * echo parmalink of the media 
  439. * 
  440. * @global array $rtmedia_backbone 
  441. * 
  442. * @param bool|int $media_id 
  443. */ 
  444. function rtmedia_permalink( $media_id = false ) { 
  445.  
  446. global $rtmedia_backbone; 
  447.  
  448. if ( $rtmedia_backbone['backbone'] ) { 
  449. echo '<%= rt_permalink %>'; 
  450. } else { 
  451. echo esc_url( get_rtmedia_permalink( rtmedia_id( $media_id ) ) ); 
  452.  
  453.  
  454. /** 
  455. * echo parmalink of the album 
  456. * 
  457. * @global object $rtmedia_media 
  458. */ 
  459. function rtmedia_album_permalink() { 
  460.  
  461. global $rtmedia_media; 
  462.  
  463. echo esc_url( get_rtmedia_permalink( $rtmedia_media->album_id ) ); 
  464.  
  465.  
  466. /** 
  467. * Get media 
  468. * 
  469. * @global object $rtmedia_media 
  470. * @global RTMedia $rtmedia 
  471. * 
  472. * @param bool $size_flag 
  473. * @param bool $echo 
  474. * @param string $media_size 
  475. * 
  476. * @return bool|string 
  477. */ 
  478. function rtmedia_media( $size_flag = true, $echo = true, $media_size = 'rt_media_single_image' ) { 
  479.  
  480. $size_flag = true; 
  481.  
  482. global $rtmedia_media, $rtmedia; 
  483.  
  484. if ( isset( $rtmedia_media->media_type ) ) { 
  485. if ( 'photo' === $rtmedia_media->media_type ) { 
  486. $src = wp_get_attachment_image_src( $rtmedia_media->media_id, $media_size ); 
  487. $html = "<img src='" . esc_url( $src[0] ) . "' alt='" . esc_attr( $rtmedia_media->post_name ) . "' />"; 
  488. } elseif ( 'video' === $rtmedia_media->media_type ) { 
  489. $height = $rtmedia->options['defaultSizes_video_singlePlayer_height']; 
  490. $height = ( $height * 75 ) / 640; 
  491. $size = ' width="' . esc_attr( $rtmedia->options['defaultSizes_video_singlePlayer_width'] ) . '" height="' . esc_attr( $height ) . '%" '; 
  492. $html = "<div id='rtm-mejs-video-container' style='width:" . esc_attr( $rtmedia->options['defaultSizes_video_singlePlayer_width'] ) . 'px;height:' . esc_attr( $height ) . "%; max-width:96%;max-height:80%;'>"; 
  493. $html .= '<video poster="" src="' . esc_url( wp_get_attachment_url( $rtmedia_media->media_id ) ) . '" ' . esc_attr( $size ) . ' type="video/mp4" class="wp-video-shortcode" id="bp_media_video_' . esc_attr( $rtmedia_media->id ) . '" controls="controls" preload="true"></video>'; 
  494. $html .= '</div>'; 
  495. } elseif ( 'music' === $rtmedia_media->media_type ) { 
  496. $width = $rtmedia->options['defaultSizes_music_singlePlayer_width']; 
  497. $width = ( $width * 75 ) / 640; 
  498. $size = ' width= ' . esc_attr( $width ) . '% height=30 '; 
  499.  
  500. if ( ! $size_flag ) { 
  501. $size = ''; 
  502.  
  503. $html = '<audio src="' . esc_url( wp_get_attachment_url( $rtmedia_media->media_id ) ) . '" ' . esc_attr( $size ) . ' type="audio/mp3" class="wp-audio-shortcode" id="bp_media_audio_' . esc_attr( $rtmedia_media->id ) . '" controls="controls" preload="none"></audio>'; 
  504. } else { 
  505. $html = false; 
  506. } else { 
  507. $html = false; 
  508.  
  509. do_action( 'rtmedia_after_' . $rtmedia_media->media_type, $rtmedia_media->id ); 
  510.  
  511. $html = apply_filters( 'rtmedia_single_content_filter', $html, $rtmedia_media ); 
  512.  
  513. if ( $echo ) { 
  514. echo $html; // @codingStandardsIgnoreLine 
  515. } else { 
  516. return $html; 
  517.  
  518.  
  519. /** 
  520. * Get media src 
  521. * 
  522. * @global array $rtmedia_backbone 
  523. * @global object $rtmedia_media 
  524. * @global RTMedia $rtmedia 
  525. * 
  526. * @param string $size 
  527. * @param bool|int $id 
  528. * @param bool $recho 
  529. * 
  530. * @return bool|int|string|void 
  531. */ 
  532. function rtmedia_image( $size = 'rt_media_thumbnail', $id = false, $recho = true ) { 
  533.  
  534. global $rtmedia_backbone; 
  535.  
  536. if ( $rtmedia_backbone['backbone'] ) { 
  537. echo '<%= guid %>'; 
  538.  
  539. return; 
  540.  
  541. if ( $id ) { 
  542. $model = new RTMediaModel(); 
  543. $media = $model->get_media( array( 
  544. 'id' => $id,  
  545. ), false, false ); 
  546.  
  547. if ( isset( $media[0] ) ) { 
  548. $media_object = $media[0]; 
  549. } else { 
  550. return false; 
  551. } else { 
  552. global $rtmedia_media; 
  553.  
  554. $media_object = $rtmedia_media; 
  555.  
  556. $thumbnail_id = 0; 
  557.  
  558. if ( isset( $media_object->media_type ) ) { 
  559. if ( 'album' === $media_object->media_type || 'photo' !== $media_object->media_type || 'video' === $media_object->media_type ) { 
  560. $thumbnail_id = ( isset( $media_object->cover_art ) 
  561. && ( ( false !== filter_var( $media_object->cover_art, FILTER_VALIDATE_URL ) ) // Cover art might be an absolute URL 
  562. || ( 0 !== intval( $media_object->cover_art ) ) // Cover art might be a media ID 
  563. ) ) ? $media_object->cover_art : false; 
  564. $thumbnail_id = apply_filters( 'show_custom_album_cover', $thumbnail_id, $media_object->media_type, $media_object->id ); // for rtMedia pro users 
  565. } elseif ( 'photo' === $media_object->media_type ) { 
  566. $thumbnail_id = $media_object->media_id; 
  567. } else { 
  568. $thumbnail_id = false; 
  569.  
  570. if ( 'music' === $media_object->media_type && empty( $thumbnail_id ) ) { 
  571. $thumbnail_id = rtm_get_music_cover_art( $media_object ); 
  572.  
  573. if ( 'music' === $media_object->media_type && -1 === intval( $thumbnail_id ) ) { 
  574. $thumbnail_id = false; 
  575.  
  576. if ( ! $thumbnail_id ) { 
  577. global $rtmedia; 
  578.  
  579. // Getting the extension of the uploaded file 
  580. $extension = rtmedia_get_extension(); 
  581.  
  582. // Checking if custom thumbnail for this file extension is set or not 
  583. if ( isset( $rtmedia->allowed_types[ $media_object->media_type ] ) && isset( $rtmedia->allowed_types[ $media_object->media_type ]['ext_thumb'] ) && isset( $rtmedia->allowed_types[ $media_object->media_type ]['ext_thumb'][ $extension ] ) ) { 
  584. $src = $rtmedia->allowed_types[ $media_object->media_type ]['ext_thumb'][ $extension ]; 
  585. } else if ( isset( $rtmedia->allowed_types[ $media_object->media_type ] ) && isset( $rtmedia->allowed_types[ $media_object->media_type ]['thumbnail'] ) ) { 
  586. $src = $rtmedia->allowed_types[ $media_object->media_type ]['thumbnail']; 
  587. } elseif ( 'album' === $media_object->media_type ) { 
  588. $src = rtmedia_album_image( $size, $id ); 
  589. } else { 
  590. $src = false; 
  591. } else { 
  592. if ( is_numeric( $thumbnail_id ) && 0 !== intval( $thumbnail_id ) ) { 
  593. list( $src, $width, $height ) = wp_get_attachment_image_src( $thumbnail_id, $size ); 
  594. } else { 
  595. $src = $thumbnail_id; 
  596.  
  597. $src = apply_filters( 'rtmedia_media_thumb', $src, $media_object->id, $media_object->media_type ); 
  598.  
  599. if ( true === $recho ) { 
  600. echo esc_url( $src ); 
  601. } else { 
  602. return $src; 
  603.  
  604.  
  605. /** 
  606. * Get media alt 
  607. * 
  608. * @global object $rtmedia_media 
  609. * 
  610. * @param bool|int $id 
  611. * @param bool $echo 
  612. * 
  613. * @return string 
  614. */ 
  615. function rtmedia_image_alt( $id = false, $echo = true ) { 
  616.  
  617. if ( $id ) { 
  618. $model = new RTMediaModel(); 
  619. $media = $model->get_media( array( 
  620. 'id' => $id,  
  621. ), false, false ); 
  622.  
  623. if ( isset( $media[0] ) ) { 
  624. $media_object = $media[0]; 
  625. } else { 
  626. return false; 
  627.  
  628. $post_object = get_post( $media_object->media_id ); 
  629.  
  630. if ( isset( $post_object->post_name ) ) { 
  631. $img_alt = $post_object->post_name; 
  632. } else { 
  633. $img_alt = ' '; 
  634. } else { 
  635. global $rtmedia_media; 
  636.  
  637. if ( isset( $rtmedia_media->post_name ) ) { 
  638. $img_alt = $rtmedia_media->post_name; 
  639. } else { 
  640. $img_alt = ' '; 
  641.  
  642. if ( $echo ) { 
  643. echo esc_attr( $img_alt ); 
  644. } else { 
  645. return $img_alt; 
  646.  
  647.  
  648. /** 
  649. * Get album image 
  650. * 
  651. * @global object $rtmedia_media 
  652. * @global RTMediaQuery $rtmedia_query 
  653. * @global RTMedia $rtmedia 
  654. * 
  655. * @param string $size 
  656. * @param bool|int $id 
  657. * 
  658. * @return string 
  659. */ 
  660. function rtmedia_album_image( $size = 'thumbnail', $id = false ) { 
  661.  
  662. global $rtmedia_media, $rtmedia_query; 
  663.  
  664. if ( false === $id ) { 
  665. $id = $rtmedia_media->id; 
  666.  
  667. $model = new RTMediaModel(); 
  668.  
  669. if ( isset( $rtmedia_query->query['context_id'] ) && isset( $rtmedia_query->query['context'] ) && 'group' !== $rtmedia_query->query['context'] ) { 
  670. if ( 'profile' === $rtmedia_query->query['context'] ) { 
  671. $media = $model->get_media( array( 
  672. 'album_id' => $id,  
  673. 'media_type' => 'photo',  
  674. 'media_author' => $rtmedia_query->query['context_id'],  
  675. 'context' => 'profile',  
  676. 'context_id' => $rtmedia_query->query['context_id'],  
  677. ), 0, 1 ); 
  678. } else { 
  679. $media = $model->get_media( array( 
  680. 'album_id' => $id,  
  681. 'media_type' => 'photo',  
  682. 'media_author' => $rtmedia_query->query['context_id'],  
  683. ), 0, 1 ); 
  684. } else { 
  685. if ( isset( $rtmedia_query->query['context_id'] ) && isset( $rtmedia_query->query['context'] ) && 'group' === $rtmedia_query->query['context'] ) { 
  686. $media = $model->get_media( array( 
  687. 'album_id' => $id,  
  688. 'media_type' => 'photo',  
  689. 'context_id' => $rtmedia_query->query['context_id'],  
  690. ), 0, 1 ); 
  691. } else { 
  692. $media = $model->get_media( array( 
  693. 'album_id' => $id,  
  694. 'media_type' => 'photo',  
  695. ), 0, 1 ); 
  696.  
  697. if ( $media ) { 
  698. $src = rtmedia_image( $size, $media[0]->id, false ); 
  699. } else { 
  700. global $rtmedia; 
  701.  
  702. $src = $rtmedia->allowed_types['photo']['thumbnail']; 
  703.  
  704. return $src; 
  705.  
  706.  
  707. /** 
  708. * Get duration for media 
  709. * 
  710. * @global array $rtmedia_backbone 
  711. * @global object $rtmedia_media 
  712. * 
  713. * @param bool|int $id 
  714. * 
  715. * @return array|bool|mixed|null|string|void 
  716. */ 
  717. function rtmedia_duration( $id = false ) { 
  718.  
  719. global $rtmedia_backbone; 
  720.  
  721. if ( $rtmedia_backbone['backbone'] ) { 
  722. echo '<%= duration %>'; 
  723.  
  724. return; 
  725.  
  726. if ( $id ) { 
  727. $model = new RTMediaModel(); 
  728. $media = $model->get_media( array( 
  729. 'id' => $id,  
  730. ), false, false ); 
  731.  
  732. if ( isset( $media[0] ) ) { 
  733. $media_object = $media[0]; 
  734. } else { 
  735. return false; 
  736. } else { 
  737. global $rtmedia_media; 
  738.  
  739. $media_object = $rtmedia_media; 
  740.  
  741. $duration = ''; 
  742.  
  743. if ( ( 'video' === $media_object->media_type ) || ( 'music' === $media_object->media_type ) ) { 
  744. $media_time = get_rtmedia_meta( $media_object->id, 'duration_time' ); 
  745.  
  746. if ( false === $media_time || empty( $media_time ) ) { 
  747. $filepath = get_attached_file( $media_object->media_id ); 
  748. $media_tags = new RTMediaTags( $filepath ); 
  749. $duration = $media_tags->duration; 
  750.  
  751. add_rtmedia_meta( $media_object->id, 'duration_time', $duration ); 
  752. } else { 
  753. $duration = $media_time; 
  754.  
  755. $duration = str_replace( '-:--', '', $duration ); 
  756. $duration = '<span class="rtmedia_time" >' . esc_attr( $duration ) . '</span>'; 
  757.  
  758. return $duration; 
  759.  
  760.  
  761. /** 
  762. * Sanitizing object 
  763. * 
  764. * @param array $data 
  765. * @param array $exceptions 
  766. * 
  767. * @return array 
  768. */ 
  769. function rtmedia_sanitize_object( $data, $exceptions = array() ) { 
  770.  
  771. foreach ( $data as $key => $value ) { 
  772. if ( ! in_array( $key, array_merge( RTMediaMedia::$default_object, $exceptions ), true ) ) { 
  773. unset( $data[ $key ] ); 
  774.  
  775. return $data; 
  776.  
  777.  
  778. /** 
  779. * Checking if delete media is allowed 
  780. * 
  781. * @global object $rtmedia_media 
  782. * 
  783. * @return bool 
  784. */ 
  785. function rtmedia_delete_allowed() { 
  786.  
  787. global $rtmedia_media; 
  788.  
  789. $flag = intval( $rtmedia_media->media_author ) === get_current_user_id(); 
  790.  
  791. if ( ! $flag && isset( $rtmedia_media->context ) && 'group' === $rtmedia_media->context && function_exists( 'bp_group_is_admin' ) ) { 
  792. $flag = ( bp_group_is_admin() || bp_group_is_mod() ); 
  793.  
  794. if ( ! $flag ) { 
  795. $flag = is_super_admin(); 
  796.  
  797. $flag = apply_filters( 'rtmedia_media_delete_priv', $flag ); 
  798.  
  799. return $flag; 
  800.  
  801.  
  802. /** 
  803. * Checking if edit media is allowed 
  804. * 
  805. * @global object $rtmedia_media 
  806. * 
  807. * @return bool 
  808. */ 
  809. function rtmedia_edit_allowed() { 
  810.  
  811. global $rtmedia_media; 
  812.  
  813. $flag = intval( $rtmedia_media->media_author ) === get_current_user_id(); 
  814.  
  815. if ( ! $flag ) { 
  816. $flag = is_super_admin(); 
  817.  
  818. $flag = apply_filters( 'rtmedia_media_edit_priv', $flag ); 
  819.  
  820. return $flag; 
  821.  
  822.  
  823. /** 
  824. * Get media action like edit, delete 
  825. * 
  826. * @global RTMediaQuery $rtmedia_query 
  827. * 
  828. * @return string 
  829. */ 
  830. function rtmedia_request_action() { 
  831.  
  832. global $rtmedia_query; 
  833.  
  834. return $rtmedia_query->action_query->action; 
  835.  
  836.  
  837. /** 
  838. * Get text-box for editing media title 
  839. * 
  840. * @global object $rtmedia_media 
  841. */ 
  842. function rtmedia_title_input() { 
  843.  
  844. global $rtmedia_media; 
  845.  
  846. $name = 'media_title'; 
  847. $value = stripslashes( esc_html( $rtmedia_media->media_title ) ); 
  848. $html = ''; 
  849.  
  850. if ( 'edit' === rtmedia_request_action() ) { 
  851. $html .= '<input type="text" class="rtmedia-title-editor" name="' . esc_attr( $name ) . '" id="' . esc_attr( $name ) . '" value="' . esc_attr( $value ) . '">'; 
  852. } else { 
  853. $html .= '<h2 name="' . esc_attr( $name ) . '" id="' . esc_attr( $name ) . '">' . esc_html( $value ) . '</h2>'; 
  854.  
  855. $html .= ''; 
  856.  
  857. echo $html; // @codingStandardsIgnoreLine 
  858.  
  859.  
  860. /** 
  861. * Get text-area when editing media 
  862. * 
  863. * @global object $rtmedia_media 
  864. * 
  865. * @param bool $editor 
  866. * @param bool $echo 
  867. * 
  868. * @return string 
  869. */ 
  870. function rtmedia_description_input( $editor = true, $echo = false ) { 
  871.  
  872. global $rtmedia_media; 
  873.  
  874. $name = 'description'; 
  875.  
  876. if ( isset( $rtmedia_media->post_content ) ) { 
  877. $value = $rtmedia_media->post_content; 
  878. } else { 
  879. $post_details = get_post( $rtmedia_media->media_id ); 
  880. $value = $post_details->post_content; 
  881.  
  882. $html = ''; 
  883.  
  884. if ( $editor ) { 
  885. if ( 'edit' === rtmedia_request_action() ) { 
  886. ob_start(); 
  887. wp_editor( $value, $name, array( 
  888. 'media_buttons' => false,  
  889. 'textarea_rows' => 2,  
  890. 'quicktags' => false,  
  891. ) ); 
  892.  
  893. $html .= ob_get_clean(); 
  894. } else { 
  895. $html .= '<div name="' . esc_attr( $name ) . '" id="' . esc_attr( $name ) . '">' . wp_kses_post( $value ) . '</div>'; 
  896. } else { 
  897. $html .= "<textarea name='" . esc_attr( $name ) . "' id='" . esc_attr( $name ) . "' class='rtmedia-desc-textarea'>" . esc_textarea( $value ) . '</textarea>'; 
  898.  
  899. $html .= ''; 
  900.  
  901. if ( $echo ) { 
  902. echo $html; // @codingStandardsIgnoreLine 
  903. } else { 
  904. return $html; 
  905.  
  906.  
  907. /** 
  908. * echo media description 
  909. * 
  910. * @param bool $echo 
  911. * 
  912. * @return string 
  913. */ 
  914. function rtmedia_description( $echo = true ) { 
  915.  
  916. if ( $echo ) { 
  917. // escape description for any html tags and reformat using `wpautop` 
  918. echo rtmedia_get_media_description(); 
  919. } else { 
  920. return rtmedia_get_media_description(); 
  921.  
  922.  
  923. /** 
  924. * Get media description 
  925. * 
  926. * @global object $rtmedia_media 
  927. * 
  928. * @param bool $id 
  929. * 
  930. * @return string 
  931. */ 
  932. function rtmedia_get_media_description( $id = false ) { 
  933.  
  934. if ( $id ) { 
  935. $media_post_id = rtmedia_media_id( $id ); 
  936. } else { 
  937. global $rtmedia_media; 
  938.  
  939. $media_post_id = $rtmedia_media->media_id; 
  940.  
  941. /** 
  942. * This function will mostly be used in single media page. 
  943. * We are showing single media page using `the_content` filter and uses dummy post. 
  944. * If we use `the_content` filter again than media description won't work as 
  945. * this is already singe media request and hence using `wpautop` instead. 
  946. */ 
  947. return wpautop( get_post_field( 'post_content', $media_post_id ) ); 
  948.  
  949.  
  950. /** 
  951. * Get total media count in the album 
  952. * 
  953. * @global RTMediaQuery $rtmedia_query 
  954. * 
  955. * @return int 
  956. */ 
  957. function rtmedia_count() { 
  958.  
  959. global $rtmedia_query; 
  960.  
  961. return $rtmedia_query->media_count; 
  962.  
  963.  
  964. /** 
  965. * Get the page offset for the media pool 
  966. * 
  967. * @global RTMediaQuery $rtmedia_query 
  968. * 
  969. * @return int 
  970. */ 
  971. function rtmedia_offset() { 
  972.  
  973. global $rtmedia_query; 
  974.  
  975. return ( $rtmedia_query->action_query->page - 1 ) * $rtmedia_query->action_query->per_page_media; 
  976.  
  977.  
  978. /** 
  979. * Get number of media per page to be displayed 
  980. * 
  981. * @global RTMediaQuery $rtmedia_query 
  982. * 
  983. * @return int 
  984. */ 
  985. function rtmedia_per_page_media() { 
  986.  
  987. global $rtmedia_query; 
  988.  
  989. return $rtmedia_query->action_query->per_page_media; 
  990.  
  991.  
  992. /** 
  993. * Get the page number of media album in the pagination 
  994. * 
  995. * @global RTMediaQuery $rtmedia_query 
  996. * 
  997. * @return int 
  998. */ 
  999. function rtmedia_page() { 
  1000.  
  1001. global $rtmedia_query; 
  1002.  
  1003. return $rtmedia_query->action_query->page; 
  1004.  
  1005.  
  1006. /** 
  1007. * Get the current media number in the album pool 
  1008. * 
  1009. * @global RTMediaQuery $rtmedia_query 
  1010. * 
  1011. * @return string 
  1012. */ 
  1013. function rtmedia_current_media() { 
  1014.  
  1015. global $rtmedia_query; 
  1016.  
  1017. return $rtmedia_query->current_media; 
  1018.  
  1019.  
  1020. /** 
  1021. * rtMedia edit form 
  1022. * 
  1023. * @return bool|string 
  1024. */ 
  1025. function rtmedia_edit_form() { 
  1026.  
  1027. if ( is_user_logged_in() && rtmedia_edit_allowed() ) { 
  1028. $edit_button = '<button type="submit" class="rtmedia-edit rtmedia-action-buttons" >' . esc_html__( 'Edit', 'buddypress-media' ) . '</button>'; 
  1029. $edit_button = apply_filters( 'rtmedia_edit_button_filter', $edit_button ); 
  1030. $button = '<form action="' . esc_url( get_rtmedia_permalink( rtmedia_id() ) ) . 'edit/">' . $edit_button . '</form>'; 
  1031.  
  1032. return $button; 
  1033.  
  1034. return false; 
  1035.  
  1036.  
  1037. /** 
  1038. * list of actions might be performed on media 
  1039. */ 
  1040. function rtmedia_actions() { 
  1041.  
  1042. $actions = array(); 
  1043.  
  1044. if ( is_user_logged_in() && rtmedia_edit_allowed() ) { 
  1045. $edit_button = '<button type="submit" class="rtmedia-edit rtmedia-action-buttons button" >' . esc_html__( 'Edit', 'buddypress-media' ) . '</button>'; 
  1046. $edit_button = apply_filters( 'rtmedia_edit_button_filter', $edit_button ); 
  1047. $actions[] = '<form action="' . esc_url( get_rtmedia_permalink( rtmedia_id() ) ) . 'edit/">' . $edit_button . '</form>'; 
  1048.  
  1049. $actions = apply_filters( 'rtmedia_action_buttons_before_delete', $actions ); 
  1050.  
  1051. foreach ( $actions as $action ) { 
  1052. echo $action; // @codingStandardsIgnoreLine 
  1053.  
  1054. $actions = array(); 
  1055.  
  1056. if ( rtmedia_delete_allowed() ) { 
  1057. $actions[] = rtmedia_delete_form( $echo = false ); 
  1058.  
  1059. $actions = apply_filters( 'rtmedia_action_buttons_after_delete', $actions ); 
  1060.  
  1061. foreach ( $actions as $action ) { 
  1062. echo $action; // @codingStandardsIgnoreLine 
  1063.  
  1064. do_action( 'after_rtmedia_action_buttons' ); 
  1065.  
  1066.  
  1067. /** 
  1068. * Rendering comments section 
  1069. * 
  1070. * @global object $rtmedia_media 
  1071. * 
  1072. * @param bool $echo 
  1073. * 
  1074. * @return string 
  1075. */ 
  1076. function rtmedia_comments( $echo = true ) { 
  1077.  
  1078. global $rtmedia_media; 
  1079.  
  1080. /** check is comment media */ 
  1081. $comment_media = rtmedia_is_comment_media_single_page( rtmedia_id() ); 
  1082.  
  1083. $html = ""; 
  1084.  
  1085. if( empty( $comment_media ) ) { 
  1086. $html = '<ul id="rtmedia_comment_ul" class="rtm-comment-list" data-action="' . esc_url( get_rtmedia_permalink( rtmedia_id() ) ) . 'delete-comment/">'; 
  1087. $comments = get_comments( array( 
  1088. 'post_id' => $rtmedia_media->media_id,  
  1089. 'order' => 'ASC',  
  1090. ) ); 
  1091. $comment_list = ''; 
  1092. $count = count( $comments ); 
  1093. $i = 0; 
  1094.  
  1095. foreach ( $comments as $comment ) { 
  1096. $comment_list .= rmedia_single_comment( (array) $comment, $count, $i ); 
  1097. $i++; 
  1098.  
  1099. if ( ! empty( $comment_list ) ) { 
  1100. $html .= $comment_list; 
  1101. } else { 
  1102. $html .= "<li id='rtmedia-no-comments' class='rtmedia-no-comments'>" . apply_filters( 'rtmedia_single_media_no_comment_messege', esc_html__( 'There are no comments on this media yet.', 'buddypress-media' ) ) . '</li>'; 
  1103.  
  1104. $html .= '</ul>'; 
  1105.  
  1106.  
  1107. if ( $html ) { 
  1108. echo $html; // @codingStandardsIgnoreLine 
  1109. } else { 
  1110. return $html; 
  1111.  
  1112.  
  1113. /** 
  1114. * Render single comment,  
  1115. * And display show all comment link to display all comment 
  1116. * @param [array] $comment [comment] 
  1117. * @param [int] $count [default false other ways comment count] 
  1118. * @param [int] $i [default false other ways increment with loop] 
  1119. * By: Yahil 
  1120. */ 
  1121. function rmedia_single_comment( $comment, $count = false, $i = false ) { 
  1122.  
  1123. $html = ''; 
  1124. $class = ''; 
  1125. if ( isset( $count ) && $count ) { 
  1126. $hide = $count - 5; 
  1127. if ( $i < $hide ) { 
  1128. $class = 'hide'; 
  1129. if ( 0 == $i ) { 
  1130. echo '<div class="rtmedia-like-info"><span id="rtmedia_show_all_comment"> ' . sprintf( esc_html__( 'Show all %s comments', 'buddypress-media' ), esc_html( $count ) ) . ' </span></div>'; 
  1131. global $allowedtags, $rtmedia_media; 
  1132.  
  1133. $html .= '<li class="rtmedia-comment ' . $class . ' ">'; 
  1134.  
  1135. if ( $comment['user_id'] ) { 
  1136. $user_link = "<a href='" . esc_url( get_rtmedia_user_link( $comment['user_id'] ) ) . "' title='" . esc_attr( rtmedia_get_author_name( $comment['user_id'] ) ) . "'>" . esc_html( rtmedia_get_author_name( $comment['user_id'] ) ) . '</a>'; 
  1137. $user_name = apply_filters( 'rtmedia_comment_author_name', $user_link, $comment ); 
  1138. $profile_pic = rtmedia_author_profile_pic( $show_link = true, $echo = false, $comment['user_id'] ); 
  1139. } else { 
  1140. $user_name = 'Annonymous'; 
  1141. $profile_pic = ''; 
  1142.  
  1143. if ( ! empty( $profile_pic ) ) { 
  1144. $html .= "<div class='rtmedia-comment-user-pic cleafix'>" . $profile_pic . '</div>'; 
  1145.  
  1146. $html .= "<div class='rtm-comment-wrap'><div class='rtmedia-comment-details'>"; 
  1147. $html .= '<span class ="rtmedia-comment-author">' . $user_name . '</span>'; 
  1148. $html .= '<span class ="rtmedia-comment-date"> ' . apply_filters( 'rtmedia_comment_date_format', rtmedia_convert_date( $comment['comment_date_gmt'] ), $comment ) . '</span>'; 
  1149.  
  1150. $comment_content = $comment['comment_content']; 
  1151.  
  1152. $comment_string = rtmedia_wp_kses_of_buddypress( $comment_content, $allowedtags ); 
  1153.  
  1154. $html .= '<div class="rtmedia-comment-content">' . wpautop( make_clickable( apply_filters( 'bp_get_activity_content', $comment_string ) ) ) . '</div>'; 
  1155. $html .= '<div class="rtmedia-comment-extra">' . apply_filters( 'rtmedia_comment_extra', '', $comment ) . '</div>'; 
  1156.  
  1157. if ( is_rt_admin() || ( isset( $comment['user_id'] ) && ( get_current_user_id() === intval( $comment['user_id'] ) || intval( $rtmedia_media->media_author ) === get_current_user_id() ) ) || apply_filters( 'rtmedia_allow_comment_delete', false ) ) { // show delete button for comment author and admins 
  1158. $html .= '<i data-id="' . esc_attr( $comment['comment_ID'] ) . '" class = "rtmedia-delete-comment dashicons dashicons-no-alt rtmicon" title="' . esc_attr__( 'Delete Comment', 'buddypress-media' ) . '"></i>'; 
  1159.  
  1160. $html .= '<div class="clear"></div></div></div></li>'; 
  1161.  
  1162. return apply_filters( 'rtmedia_single_comment', $html, $comment ); 
  1163.  
  1164.  
  1165.  
  1166.  
  1167. /** 
  1168. * Get media comment count using media ID 
  1169. * 
  1170. * @global wpdb $wpdb 
  1171. * @global object $rtmedia_media 
  1172. * 
  1173. * @param bool|int $media_id 
  1174. * 
  1175. * @return int 
  1176. */ 
  1177. function rtmedia_get_media_comment_count( $media_id = false ) { 
  1178.  
  1179. global $wpdb, $rtmedia_media; 
  1180.  
  1181. if ( ! $media_id ) { 
  1182. $post_id = $rtmedia_media->media_id; 
  1183. } else { 
  1184. $post_id = rtmedia_media_id( $media_id ); 
  1185.  
  1186. $query = $wpdb->prepare( "SELECT count(*) FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ); 
  1187. $comment_count = $wpdb->get_results( $query, ARRAY_N ); // @codingStandardsIgnoreLine 
  1188.  
  1189. if ( is_array( $comment_count ) && is_array( $comment_count[0] ) && isset( $comment_count[0][0] ) ) { 
  1190. return $comment_count[0][0]; 
  1191. } else { 
  1192. return 0; 
  1193.  
  1194.  
  1195. /** 
  1196. * Get previous media link 
  1197. * 
  1198. * @global object $rtmedia_interaction 
  1199. * @global RTMediaQuery $rtmedia_query 
  1200. * 
  1201. * @return string 
  1202. */ 
  1203. function rtmedia_pagination_prev_link() { 
  1204.  
  1205. global $rtmedia_interaction, $rtmedia_query; 
  1206.  
  1207. $page_url = ( ( rtmedia_page() - 1 ) === 1 ) ? '' : 'pg/' . ( rtmedia_page() - 1 ); 
  1208. $site_url = ( is_multisite() ) ? trailingslashit( get_site_url( get_current_blog_id() ) ) : trailingslashit( get_site_url() ); 
  1209. $author_name = get_query_var( 'author_name' ); 
  1210. $link = ''; 
  1211.  
  1212. if ( $rtmedia_interaction && isset( $rtmedia_interaction->context ) && 'profile' === $rtmedia_interaction->context->type ) { 
  1213. if ( function_exists( 'bp_core_get_user_domain' ) ) { 
  1214. $link .= trailingslashit( bp_core_get_user_domain( $rtmedia_query->media_query['media_author'] ) ); 
  1215. } else { 
  1216. $link = $site_url . 'author/' . $author_name . '/'; 
  1217. } else { 
  1218. if ( $rtmedia_interaction && isset( $rtmedia_interaction->context ) && 'group' === $rtmedia_interaction->context->type ) { 
  1219. if ( function_exists( 'bp_get_current_group_slug' ) ) { 
  1220. $link .= $site_url . bp_get_groups_root_slug() . '/' . bp_get_current_group_slug() . '/'; 
  1221. } else { 
  1222. $post = get_post( get_post_field( 'post_parent', $rtmedia_query->media->media_id ) ); 
  1223. $link .= $site_url . $post->post_name . '/'; 
  1224.  
  1225. $link .= RTMEDIA_MEDIA_SLUG . '/'; 
  1226.  
  1227. if ( isset( $rtmedia_query->action_query->media_type ) ) { 
  1228. $media_type_array = apply_filters( 'rtmedia_media_type_support', array( 'photo', 'music', 'video', 'album' ) ); 
  1229.  
  1230. if ( in_array( $rtmedia_query->action_query->media_type, $media_type_array, true ) ) { 
  1231. $link .= $rtmedia_query->action_query->media_type . '/'; 
  1232.  
  1233. return apply_filters( 'rtmedia_pagination_prev_link', $link . $page_url, $link, $page_url ); 
  1234.  
  1235.  
  1236. /** 
  1237. * Get next media link 
  1238. * 
  1239. * @global object $rtmedia_interaction 
  1240. * @global RTMediaQuery $rtmedia_query 
  1241. * 
  1242. * @return string 
  1243. */ 
  1244. function rtmedia_pagination_next_link() { 
  1245.  
  1246. global $rtmedia_interaction, $rtmedia_query; 
  1247.  
  1248. $page_url = 'pg/' . ( rtmedia_page() + 1 ); 
  1249. $site_url = ( is_multisite() ) ? trailingslashit( get_site_url( get_current_blog_id() ) ) : trailingslashit( get_site_url() ); 
  1250. $author_name = get_query_var( 'author_name' ); 
  1251. $link = ''; 
  1252.  
  1253. if ( $rtmedia_interaction && isset( $rtmedia_interaction->context ) && 'profile' === $rtmedia_interaction->context->type ) { 
  1254. if ( function_exists( 'bp_core_get_user_domain' ) ) { 
  1255. if ( isset( $rtmedia_query->media_query['context'] ) && 'profile' === $rtmedia_query->media_query['context'] && isset( $rtmedia_query->media_query['context_id'] ) ) { 
  1256. $user_id = $rtmedia_query->media_query['context_id']; 
  1257. } else if ( isset( $rtmedia_query->media_query['media_author'] ) ) { 
  1258. $user_id = $rtmedia_query->media_query['media_author']; 
  1259. } else { 
  1260. $user_id = bp_displayed_user_id(); 
  1261.  
  1262. $link .= trailingslashit( bp_core_get_user_domain( $user_id ) ); 
  1263. } else { 
  1264. $link .= $site_url . 'author/' . $author_name . '/'; 
  1265. } else { 
  1266. if ( $rtmedia_interaction && isset( $rtmedia_interaction->context ) && 'group' === $rtmedia_interaction->context->type ) { 
  1267. if ( function_exists( 'bp_get_current_group_slug' ) ) { 
  1268. $link .= $site_url . bp_get_groups_root_slug() . '/' . bp_get_current_group_slug() . '/'; 
  1269. } else { 
  1270. // if there are more media than number of media per page to show than $rtmedia_query->media->media_id will be set other wise take media_id of very first media 
  1271. // For more understanding why array became object check rewind_media() in RTMediaQuery.php file and check it's call 
  1272. $post_id = ( isset( $rtmedia_query->media->media_id ) ? $rtmedia_query->media->media_id : $rtmedia_query->media[0]->media_id ); 
  1273. $post = get_post( get_post_field( 'post_parent', $post_id ) ); 
  1274.  
  1275. if ( isset( $post->post_name ) ) { 
  1276. $link .= $site_url . $post->post_name . '/'; 
  1277. } else { 
  1278. $link .= $site_url; 
  1279.  
  1280. $link .= RTMEDIA_MEDIA_SLUG . '/'; 
  1281.  
  1282. if ( isset( $rtmedia_query->media_query['album_id'] ) && intval( $rtmedia_query->media_query['album_id'] ) > 0 ) { 
  1283. $link .= $rtmedia_query->media_query['album_id'] . '/'; 
  1284.  
  1285. if ( isset( $rtmedia_query->action_query->media_type ) ) { 
  1286. $media_type_array = apply_filters( 'rtmedia_media_type_support', array( 'photo', 'music', 'video', 'album' ) ); 
  1287.  
  1288. if ( in_array( $rtmedia_query->action_query->media_type, $media_type_array, true ) ) { 
  1289. $link .= $rtmedia_query->action_query->media_type . '/'; 
  1290.  
  1291. return apply_filters( 'rtmedia_pagination_next_link', $link . $page_url, $link, $page_url ); 
  1292.  
  1293.  
  1294. /** 
  1295. * get media page link 
  1296. * 
  1297. * @global object $rtmedia_interaction 
  1298. * @global RTMediaQuery $rtmedia_query 
  1299. * 
  1300. * @param string $page_no 
  1301. * 
  1302. * @return string 
  1303. */ 
  1304. function rtmedia_pagination_page_link( $page_no = '' ) { 
  1305.  
  1306. global $rtmedia_interaction, $rtmedia_query, $post, $rtmedia; 
  1307.  
  1308. $wp_default_context = array( 'page', 'post' ); 
  1309.  
  1310. if ( isset( $_GET['context'] ) && in_array( $_GET['context'], $wp_default_context ) && isset( $_GET['rtmedia_shortcode'] ) && 'true' === $_GET['rtmedia_shortcode'] ) { 
  1311. $post = get_post( intval( $_GET['context_id'] ) ); 
  1312.  
  1313. $page_url = 'pg/' . $page_no; 
  1314. $site_url = ( is_multisite() ) ? trailingslashit( get_site_url( get_current_blog_id() ) ) : trailingslashit( get_site_url() ); 
  1315. $author_name = get_query_var( 'author_name' ); 
  1316. $link = ''; 
  1317.  
  1318. $is_shortcode_on_home = ( isset( $_GET['is_on_home'] ) && '1' === $_GET['is_on_home'] && isset( $_GET['rtmedia_shortcode'] ) && 'true' === $_GET['rtmedia_shortcode'] && isset( $_GET['context_id'] ) && $_GET['context_id'] === get_option( 'page_on_front' ) ) ? true : false; 
  1319.  
  1320. if ( $rtmedia_interaction && isset( $rtmedia_interaction->context ) && 'profile' === $rtmedia_interaction->context->type ) { 
  1321. if ( function_exists( 'bp_core_get_user_domain' ) && ! empty( $rtmedia_query->query['context_id'] ) ) { 
  1322. $link .= trailingslashit( bp_core_get_user_domain( $rtmedia_query->query['context_id'] ) ); 
  1323. } else { 
  1324. if ( $is_shortcode_on_home ) { 
  1325. $link .= $site_url; 
  1326. } else { 
  1327. $link .= $site_url . 'author/' . $author_name . '/'; 
  1328. } else { 
  1329. if ( $rtmedia_interaction && isset( $rtmedia_interaction->context ) && 'group' === $rtmedia_interaction->context->type ) { 
  1330. if ( function_exists( 'bp_get_current_group_slug' ) ) { 
  1331. $link .= $site_url . bp_get_groups_root_slug() . '/' . bp_get_current_group_slug() . '/'; 
  1332. } elseif ( $rtmedia_interaction && isset( $rtmedia_interaction->context ) && in_array( $rtmedia_interaction->context->type, $wp_default_context ) ) { 
  1333. // Make sure that only one slash is at the end of url 
  1334. $link .= rtrim( get_permalink( $post ), '/' ) . '/'; 
  1335. } elseif ( $rtmedia_interaction && isset( $rtmedia_interaction->context ) && 'rtmedia_album' === $rtmedia_interaction->context->type ) { // url for rtmedia album 
  1336. global $rtmedia; 
  1337. $options = $rtmedia->options; 
  1338. // Get album slug 
  1339. $album_slug = $options['rtmedia_wp_album_slug']; 
  1340.  
  1341. if ( empty( $album_slug ) ) { 
  1342. $album_slug = 'rtmedia-album'; 
  1343. $post = get_post( get_post_field( 'post_parent', $rtmedia_query->media->media_id ) ); 
  1344. $link .= $site_url . $album_slug . '/' . $post->post_name . '/'; 
  1345. } elseif ( isset( $rtmedia_query->media->media_id ) ) { 
  1346. $post = get_post( get_post_field( 'post_parent', $rtmedia_query->media->media_id ) ); 
  1347.  
  1348. $link .= $site_url . $post->post_name . '/'; 
  1349.  
  1350. // Do not add media slug for gallery shortcode and sitewide gallery 
  1351. if ( $rtmedia_interaction && isset( $rtmedia_interaction->context ) && ! in_array( $rtmedia_interaction->context->type, array( 'page', 'rtmedia_album', 'post' ) ) && ! $is_shortcode_on_home ) { 
  1352. $link .= RTMEDIA_MEDIA_SLUG . '/'; 
  1353.  
  1354. // For albums tab 
  1355. if ( isset( $rtmedia_query->media_query['album_id'] ) && intval( $rtmedia_query->media_query['album_id'] ) > 0 ) { 
  1356. $link .= $rtmedia_query->media_query['album_id'] . '/'; 
  1357.  
  1358. // For those pages of which es id is set into action query 
  1359. if ( isset( $rtmedia_query->action_query->id ) && intval( $rtmedia_query->action_query->id ) > 0 ) { 
  1360. $link .= $rtmedia_query->action_query->id . '/'; 
  1361.  
  1362. $allowed_types = array( 'album' ); 
  1363.  
  1364. // get all allowed media type 
  1365. foreach ( $rtmedia->allowed_types as $type ) { 
  1366. $name = strtoupper( $type['name'] ); 
  1367. $allowed_types[] = constant( 'RTMEDIA_' . $name . '_SLUG' ); 
  1368.  
  1369. if ( isset( $rtmedia_query->action_query->media_type ) ) { 
  1370.  
  1371. /** 
  1372. * Filters media types. 
  1373. * 
  1374. * @param array Array of all media types. 
  1375. */ 
  1376. $media_type = apply_filters( 'rtmedia_media_type', $rtmedia_query->action_query->media_type ); 
  1377.  
  1378. if ( isset( $media_type ) ) { 
  1379.  
  1380. /** 
  1381. * Filters allowed media types. 
  1382. * 
  1383. * @param array Array of all allowed media types. 
  1384. */ 
  1385. $media_type_array = apply_filters( 'rtmedia_media_type_support', $allowed_types ); 
  1386. if ( in_array( $media_type, $media_type_array, true ) ) { 
  1387. $link .= $media_type . '/'; 
  1388.  
  1389.  
  1390. return apply_filters( 'rtmedia_pagination_page_link', $link . $page_url, $link, $page_url ); 
  1391.  
  1392.  
  1393. /** 
  1394. * Media pagination 
  1395. * 
  1396. * @global array $rtmedia_backbone 
  1397. */ 
  1398. function rtmedia_media_pagination() { 
  1399.  
  1400. global $rtmedia_backbone; 
  1401.  
  1402. if ( $rtmedia_backbone['backbone'] ) { 
  1403. echo '<%= pagination %>'; 
  1404. } else { 
  1405. echo rtmedia_get_pagination_values(); // @codingStandardsIgnoreLine 
  1406.  
  1407.  
  1408. /** 
  1409. * Render pagination UI 
  1410. * 
  1411. * @global RTMedia $rtmedia 
  1412. * @global RTMediaQuery $rtmedia_query 
  1413. * @global int $paged 
  1414. * 
  1415. * @return string 
  1416. */ 
  1417. function rtmedia_get_pagination_values() { 
  1418.  
  1419. global $rtmedia, $rtmedia_query, $paged; 
  1420.  
  1421. $general_options = $rtmedia->options; 
  1422. $per_page = $general_options['general_perPageMedia']; 
  1423.  
  1424. if ( isset( $rtmedia_query->query['per_page'] ) ) { 
  1425. $per_page = $rtmedia_query->query['per_page']; 
  1426.  
  1427. $per_page = intval( $per_page ); 
  1428. $range = 1; 
  1429. $showitems = ( $range * 2 ) + 1; 
  1430. $rtmedia_media_pages = ''; 
  1431.  
  1432. if ( 0 === intval( rtmedia_offset() ) ) { 
  1433. $paged = 1; // @codingStandardsIgnoreLine 
  1434. } else if ( intval( rtmedia_offset() ) === $per_page ) { 
  1435. $paged = 2; // @codingStandardsIgnoreLine 
  1436. } else { 
  1437. $paged = ceil( rtmedia_offset() / $per_page ) + 1; // @codingStandardsIgnoreLine 
  1438.  
  1439. $pages = ceil( rtmedia_count() / $per_page ); 
  1440.  
  1441. if ( ! $pages ) { 
  1442. $pages = 1; 
  1443.  
  1444. $page_base_url = rtmedia_pagination_page_link(); 
  1445.  
  1446. if ( 1 !== intval( $pages ) ) { 
  1447. $rtmedia_media_pages .= "<div class='rtm-pagination clearfix'>"; 
  1448. $rtmedia_media_pages .= "<div class='rtmedia-page-no rtm-page-number'>"; 
  1449. $rtmedia_media_pages .= "<span class='rtm-label'>"; 
  1450. $rtmedia_media_pages .= esc_html( apply_filters( 'rtmedia_goto_page_label', esc_html__( 'Go to page no : ', 'buddypress-media' ) ) ); 
  1451. $rtmedia_media_pages .= '</span>'; 
  1452. $rtmedia_media_pages .= "<input type='hidden' id='rtmedia_first_page' value='1' />"; 
  1453. $rtmedia_media_pages .= "<input type='hidden' id='rtmedia_last_page' value='" . esc_attr( $pages ) . "' />"; 
  1454. $rtmedia_media_pages .= "<input type='number' value='" . esc_attr( $paged ) . "' min='1' max='" . esc_attr( $pages ) . "' class='rtm-go-to-num' id='rtmedia_go_to_num' />"; 
  1455. $rtmedia_media_pages .= "<a class='rtmedia-page-link button' data-page-type='num' data-page-base-url='" . $page_base_url . "' href='#'>" . esc_html__( 'Go', 'buddypress-media' ) . '</a>'; 
  1456. $rtmedia_media_pages .= "</div><div class='rtm-paginate'>"; 
  1457.  
  1458. if ( $paged > 1 && $showitems < $pages ) { 
  1459. $page_url = ( ( rtmedia_page() - 1 ) == 1 ) ? '' : $page_base_url . ( rtmedia_page() - 1 ); 
  1460.  
  1461. $rtmedia_media_pages .= "<a class='rtmedia-page-link' data-page-type='prev' href='" . esc_url( $page_url ) . "'><i class='dashicons dashicons-arrow-left-alt2'></i></a>"; 
  1462.  
  1463. if ( $paged > 2 && $paged > $range + 1 && $showitems < $pages ) { 
  1464. $page_url = $page_base_url . '1'; 
  1465.  
  1466. $rtmedia_media_pages .= "<a class='rtmedia-page-link' data-page-type='page' data-page='1' href='" . esc_url( $page_url ) . "'>1</a>"; 
  1467. if ( $paged > 3 ) { 
  1468. $rtmedia_media_pages .= '<span>...</span>'; 
  1469.  
  1470. for ( $i = 1; $i <= $pages; $i ++ ) { 
  1471. if ( 1 != $pages && ( ! ( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems ) ) { 
  1472. $page_url = $page_base_url . $i; 
  1473.  
  1474. $rtmedia_media_pages .= ( $paged == $i ) ? "<span class='current'>" . esc_html( $i ) . '</span>' : "<a class='rtmedia-page-link' data-page-type='page' data-page='" . esc_attr( $i ) . "' href='" . esc_url( $page_url ) . "' class='inactive' >" . esc_html( $i ) . '</a>'; 
  1475.  
  1476. if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages ) { 
  1477. $page_url = $page_base_url . $pages; 
  1478.  
  1479. if ( $paged + 2 < $pages ) { 
  1480. $rtmedia_media_pages .= '<span>...</span>'; 
  1481.  
  1482. $rtmedia_media_pages .= "<a class='rtmedia-page-link' data-page-type='page' data-page='" . esc_attr( $pages ) . "' href='" . esc_url( $page_url ) . "'>" . esc_html( $pages ) . '</a>'; 
  1483.  
  1484. if ( $paged < $pages && $showitems < $pages ) { 
  1485. $page_url = $page_base_url . ( rtmedia_page() + 1 ); 
  1486.  
  1487. $rtmedia_media_pages .= "<a class='rtmedia-page-link' data-page-type='next' href='" . esc_url( $page_url ) . "'><i class='dashicons dashicons-arrow-right-alt2'></i></a>"; 
  1488.  
  1489. $rtmedia_media_pages .= "</div></div>"; 
  1490. }// End if(). 
  1491.  
  1492. return $rtmedia_media_pages; 
  1493.  
  1494.  
  1495. /** 
  1496. * Checking if comments are enabled 
  1497. * 
  1498. * @global RTMedia $rtmedia 
  1499. * 
  1500. * @return bool 
  1501. */ 
  1502. function rtmedia_comments_enabled() { 
  1503.  
  1504. global $rtmedia; 
  1505.  
  1506. return $rtmedia->options['general_enableComments']; 
  1507.  
  1508.  
  1509. /** 
  1510. * Checking if it's a rtmedia gallery 
  1511. * 
  1512. * @global RTMediaQuery $rtmedia_query 
  1513. * 
  1514. * @return bool 
  1515. */ 
  1516. function is_rtmedia_gallery() { 
  1517.  
  1518. global $rtmedia_query; 
  1519.  
  1520. if ( $rtmedia_query ) { 
  1521. return $rtmedia_query->is_gallery(); 
  1522. } else { 
  1523. return false; 
  1524.  
  1525.  
  1526. /** 
  1527. * Checking if it's a album gallery 
  1528. * 
  1529. * @global RTMediaQuery $rtmedia_query 
  1530. * 
  1531. * @return bool 
  1532. */ 
  1533. function is_rtmedia_album_gallery() { 
  1534.  
  1535. global $rtmedia_query; 
  1536.  
  1537. if ( $rtmedia_query ) { 
  1538. return $rtmedia_query->is_album_gallery(); 
  1539. } else { 
  1540. return false; 
  1541.  
  1542.  
  1543. /** 
  1544. * Checking if it's a single media 
  1545. * 
  1546. * @global RTMediaQuery $rtmedia_query 
  1547. * 
  1548. * @return bool 
  1549. */ 
  1550. function is_rtmedia_single() { 
  1551.  
  1552. global $rtmedia_query; 
  1553.  
  1554. if ( $rtmedia_query ) { 
  1555. return $rtmedia_query->is_single(); 
  1556. } else { 
  1557. return false; 
  1558.  
  1559.  
  1560. /** 
  1561. * Checking if it's an album 
  1562. * 
  1563. * @global RTMediaQuery $rtmedia_query 
  1564. * 
  1565. * @param bool|int $album_id 
  1566. * 
  1567. * @return bool 
  1568. */ 
  1569. function is_rtmedia_album( $album_id = false ) { 
  1570.  
  1571. if ( $album_id ) { 
  1572. $rtmedia_model = new RTMediaModel(); 
  1573. $media = $rtmedia_model->get( array( 
  1574. 'id' => $album_id,  
  1575. ) ); 
  1576.  
  1577. if ( is_array( $media ) && isset( $media[0] ) && isset( $media[0]->media_type ) && 'album' === $media[0]->media_type ) { 
  1578. return true; 
  1579.  
  1580. return false; 
  1581.  
  1582. global $rtmedia_query; 
  1583.  
  1584. if ( $rtmedia_query ) { 
  1585. return $rtmedia_query->is_album(); 
  1586. } else { 
  1587. return false; 
  1588.  
  1589.  
  1590. /** 
  1591. * Checking if it's a group album 
  1592. * 
  1593. * @global RTMediaQuery $rtmedia_query 
  1594. * 
  1595. * @return bool 
  1596. */ 
  1597. function is_rtmedia_group_album() { 
  1598.  
  1599. global $rtmedia_query; 
  1600.  
  1601. if ( $rtmedia_query ) { 
  1602. return $rtmedia_query->is_group_album(); 
  1603. } else { 
  1604. return false; 
  1605.  
  1606.  
  1607. /** 
  1608. * Checking if edit is allowed 
  1609. * 
  1610. * @global RTMediaQuery $rtmedia_query 
  1611. * 
  1612. * @return bool 
  1613. */ 
  1614. function is_rtmedia_edit_allowed() { 
  1615.  
  1616. global $rtmedia_query; 
  1617.  
  1618. if ( $rtmedia_query ) { 
  1619. if ( isset( $rtmedia_query->media_query['media_author'] ) && get_current_user_id() === intval( $rtmedia_query->media_query['media_author'] ) && 'edit' === $rtmedia_query->action_query->action ) { 
  1620. return true; 
  1621. } else { 
  1622. return false; 
  1623. } else { 
  1624. return false; 
  1625.  
  1626.  
  1627. /** 
  1628. * Updating activity after thumbnail set 
  1629. * 
  1630. * @global wpdb $wpdb 
  1631. * @global BuddyPress $bp 
  1632. * 
  1633. * @param int $id 
  1634. */ 
  1635. function update_activity_after_thumb_set( $id ) { 
  1636. $model = new RTMediaModel(); 
  1637. $media_obj = new RTMediaMedia(); 
  1638. $media = $model->get( array( 
  1639. 'id' => $id,  
  1640. ) ); 
  1641. $privacy = $media[0]->privacy; 
  1642. $activity_id = rtmedia_activity_id( $id ); 
  1643.  
  1644. if ( ! empty( $activity_id ) ) { 
  1645. $same_medias = $media_obj->model->get( array( 
  1646. 'activity_id' => $activity_id,  
  1647. ) ); 
  1648. $update_activity_media = array(); 
  1649.  
  1650. foreach ( $same_medias as $a_media ) { 
  1651. $update_activity_media[] = $a_media->id; 
  1652.  
  1653. $obj_activity = new RTMediaActivity( $update_activity_media, $privacy, false ); 
  1654.  
  1655. global $wpdb, $bp; 
  1656.  
  1657. $activity_old_content = bp_activity_get_meta( $activity_id, 'bp_old_activity_content' ); 
  1658.  
  1659. if ( ! empty( $activity_old_content ) ) { 
  1660. // get old activity content and save in activity meta 
  1661. $activity_get = bp_activity_get_specific( array( 
  1662. 'activity_ids' => $activity_id,  
  1663. ) ); 
  1664. $activity = $activity_get['activities'][0]; 
  1665. $activity_body = $activity->content; 
  1666.  
  1667. bp_activity_update_meta( $activity_id, 'bp_old_activity_content', $activity_body ); 
  1668.  
  1669. //extract activity text from old content 
  1670. $activity_text = strip_tags( $activity_body, '<span>' ); 
  1671. $activity_text = explode( '</span>', $activity_text ); 
  1672. $activity_text = strip_tags( $activity_text[0] ); 
  1673.  
  1674. bp_activity_update_meta( $activity_id, 'bp_activity_text', $activity_text ); 
  1675.  
  1676. $activity_text = bp_activity_get_meta( $activity_id, 'bp_activity_text' ); 
  1677. $obj_activity->activity_text = $activity_text; 
  1678. $activity_content = $obj_activity->create_activity_html(); 
  1679.  
  1680. $wpdb->update( $bp->activity->table_name, array( 
  1681. 'content' => $activity_content,  
  1682. ), array( 
  1683. 'id' => $activity_id,  
  1684. ) ); 
  1685.  
  1686. if( function_exists( 'rtmedia_update_content_of_comment_media' ) ) { 
  1687. rtmedia_update_content_of_comment_media( $id, $activity_content ); 
  1688. }// End if(). 
  1689.  
  1690.  
  1691.  
  1692.  
  1693. /** 
  1694. * Updating profile and comment activity after thumbnail set 
  1695. * 
  1696. * @global wpdb $wpdb 
  1697. * 
  1698. * @param int $media_id 
  1699. * @param string $activity_content 
  1700. */ 
  1701. function rtmedia_update_content_of_comment_media( $media_id, $activity_content ) { 
  1702. /** update activity profile and comment content of the media */ 
  1703. if( isset( $media_id ) && ! empty( $media_id ) && function_exists( 'rtmedia_is_comment_media' ) ) { 
  1704. global $wpdb; 
  1705. /** check if it's an comment media */ 
  1706. if( rtmedia_is_comment_media( $media_id ) ) { 
  1707.  
  1708. // update profile content 
  1709. /** get the profile activity id from the rtmedia meta table */ 
  1710. $activity_id = get_rtmedia_meta( $media_id, 'rtmedia_comment_media_profile_id' ); 
  1711. /** check is activity id is empty or not */ 
  1712. if( isset( $activity_id ) && ! empty( $activity_id ) ) { 
  1713. $update = $wpdb->update( $wpdb->base_prefix . 'bp_activity', array( 'content' => $activity_content ), array( 'id' => $activity_id ) ); 
  1714.  
  1715. // update comment content 
  1716. // get the comment id from the rtmedia meta table 
  1717. $comment_id = get_rtmedia_meta( $media_id, 'rtmedia_comment_media_comment_id' ); 
  1718. if( isset( $comment_id ) && ! empty( $comment_id ) ) { 
  1719. $activity_content = str_replace( 'rtmedia-activity-container', 'rtmedia-comment-media-container', $activity_content ); 
  1720. $activity_content = str_replace( 'rtmedia-activity-text', 'rtmedia-comment-media-text', $activity_content ); 
  1721. $activity_content = str_replace( 'rtmedia-list-item', 'rtmedia-comment-media-list-item', $activity_content ); 
  1722. $activity_content = str_replace( 'rtmedia-list', 'rtmedia-comment-media-list', $activity_content ); 
  1723. $activity_content = str_replace( 'rtmedia-comment-media-list-item', 'rtmedia-list-item', $activity_content ); 
  1724. $update = $wpdb->update( $wpdb->base_prefix . 'comments', array( 'comment_content' => $activity_content ), array( 'comment_ID' => $comment_id ) ); 
  1725.  
  1726.  
  1727. /** 
  1728. * Updating video poster 
  1729. * 
  1730. * @param string $html 
  1731. * @param object $media 
  1732. * @param bool $activity 
  1733. * 
  1734. * @return string 
  1735. */ 
  1736. function update_video_poster( $html, $media, $activity = false ) { 
  1737.  
  1738. if ( 'video' === $media->media_type ) { 
  1739. $thumbnail_id = $media->cover_art; 
  1740.  
  1741. if ( $thumbnail_id ) { 
  1742. $thumbnail_info = wp_get_attachment_image_src( $thumbnail_id, 'full' ); 
  1743. $html = str_replace( '<video ', '<video poster="' . esc_url( $thumbnail_info[0] ) . '" ', $html ); 
  1744.  
  1745. return $html; 
  1746.  
  1747.  
  1748. /** 
  1749. * Get video without thumbnail 
  1750. * 
  1751. * @global wpdb $wpdb 
  1752. * 
  1753. * @return string 
  1754. */ 
  1755. function get_video_without_thumbs() { 
  1756.  
  1757. global $wpdb; 
  1758.  
  1759. $rtmedia_model = new RTMediaModel(); 
  1760.  
  1761. $sql = $wpdb->prepare( "select media_id from {$rtmedia_model->table_name} where media_type = %s and blog_id = %d and cover_art is null", 'video', get_current_blog_id() ); // @codingStandardsIgnoreLine 
  1762. $results = $wpdb->get_col( $sql ); // @codingStandardsIgnoreLine 
  1763.  
  1764. return $results; 
  1765.  
  1766.  
  1767. /** 
  1768. * Rendering single media comment form 
  1769. */ 
  1770. function rtmedia_comment_form() { 
  1771.  
  1772. /** check is comment media */ 
  1773. $comment_media = rtmedia_is_comment_media_single_page( rtmedia_id() ); 
  1774.  
  1775. if ( is_user_logged_in() && empty( $comment_media ) ) { 
  1776. ?> 
  1777. <form method="post" id="rt_media_comment_form" class="rt_media_comment_form" action="<?php echo esc_url( get_rtmedia_permalink( rtmedia_id() ) ); ?>comment/"> 
  1778. <textarea style="width:100%" placeholder="<?php esc_attr_e( 'Type Comment...', 'buddypress-media' ); ?>" name="comment_content" id="comment_content" class="bp-suggestions ac-input"></textarea> 
  1779.  
  1780. <input type="submit" id="rt_media_comment_submit" class="rt_media_comment_submit" value="<?php esc_attr_e( 'Comment', 'buddypress-media' ); ?>"> 
  1781.  
  1782. <?php do_action( 'rtmedia_add_comments_extra' ); ?> 
  1783.  
  1784. <?php RTMediaComment::comment_nonce_generator(); ?> 
  1785. </form> 
  1786. <?php 
  1787.  
  1788.  
  1789. /** 
  1790. * Get cover srt using media ID 
  1791. * 
  1792. * @param int $id 
  1793. * 
  1794. * @return bool|string 
  1795. */ 
  1796. function rtmedia_get_cover_art_src( $id ) { 
  1797.  
  1798. $model = new RTMediaModel(); 
  1799. $media = $model->get( array( 
  1800. 'id' => $id,  
  1801. ) ); 
  1802. $cover_art = $media[0]->cover_art; 
  1803.  
  1804. if ( ! empty( $cover_art ) ) { 
  1805. if ( is_numeric( $cover_art ) ) { 
  1806. $thumbnail_info = wp_get_attachment_image_src( $cover_art, 'full' ); 
  1807.  
  1808. return $thumbnail_info[0]; 
  1809. } else { 
  1810. return $cover_art; 
  1811. } else { 
  1812. return false; 
  1813.  
  1814.  
  1815. /** 
  1816. * Rendering media delete form 
  1817. * 
  1818. * @param bool $echo 
  1819. * 
  1820. * @return bool|string 
  1821. */ 
  1822. function rtmedia_delete_form( $echo = true ) { 
  1823.  
  1824. if ( rtmedia_delete_allowed() ) { 
  1825. $html = '<form method="post" action="' . esc_url( get_rtmedia_permalink( rtmedia_id() ) ) . 'delete/">'; 
  1826. $html .= '<input type="hidden" name="id" id="id" value="' . esc_attr( rtmedia_id() ) . '">'; 
  1827. $html .= '<input type="hidden" name="request_action" id="request_action" value="delete">'; 
  1828.  
  1829. if ( $echo ) { 
  1830. echo $html; // @codingStandardsIgnoreLine 
  1831.  
  1832. RTMediaMedia::media_nonce_generator( rtmedia_id(), true ); 
  1833.  
  1834. do_action( 'rtmedia_media_single_delete_form' ); 
  1835.  
  1836. echo '<button type="submit" title="' . esc_attr__( 'Delete Media', 'buddypress-media' ) . '" class="rtmedia-delete-media rtmedia-action-buttons button">' . esc_html__( 'Delete', 'buddypress-media' ) . '</button></form>'; 
  1837. } else { 
  1838. $output = $html; 
  1839. $rtm_nonce = RTMediaMedia::media_nonce_generator( rtmedia_id(), false ); 
  1840. $rtm_nonce = json_decode( $rtm_nonce ); 
  1841. $rtm_nonce_field = wp_nonce_field( 'rtmedia_' . rtmedia_id(), $rtm_nonce->action, true, false ); 
  1842.  
  1843. do_action( 'rtmedia_media_single_delete_form' ); 
  1844.  
  1845. $output .= $rtm_nonce_field . '<button type="submit" title="' . esc_attr__( 'Delete Media', 'buddypress-media' ) . '" class="rtmedia-delete-media rtmedia-action-buttons button">' . esc_html__( 'Delete', 'buddypress-media' ) . '</button></form>'; 
  1846.  
  1847. return $output; 
  1848.  
  1849. return false; 
  1850.  
  1851.  
  1852. /** 
  1853. * Rendering RTMedia Uploader 
  1854. * 
  1855. * @param array|string $attr 
  1856. */ 
  1857. function rtmedia_uploader( $attr = '' ) { 
  1858.  
  1859. if ( rtmedia_is_uploader_view_allowed( true, 'media_gallery' ) ) { 
  1860. if ( function_exists( 'bp_is_blog_page' ) && ! bp_is_blog_page() ) { 
  1861. if ( function_exists( 'bp_is_user' ) && bp_is_user() && function_exists( 'bp_displayed_user_id' ) && bp_displayed_user_id() === get_current_user_id() ) { 
  1862. echo RTMediaUploadShortcode::pre_render( $attr ); // @codingStandardsIgnoreLine 
  1863. } else { 
  1864. if ( function_exists( 'bp_is_group' ) && bp_is_group() ) { 
  1865. if ( can_user_upload_in_group() ) { 
  1866. echo RTMediaUploadShortcode::pre_render( $attr ); // @codingStandardsIgnoreLine 
  1867. } else { 
  1868. echo "<div class='rtmedia-upload-not-allowed'>" . wp_kses( apply_filters( 'rtmedia_upload_not_allowed_message', esc_html__( 'You are not allowed to upload/attach media.', 'buddypress-media' ), 'media_gallery' ), RTMediaUpload::$wp_kses_allowed_tags ) . '</div>'; 
  1869.  
  1870.  
  1871. /** 
  1872. * Rendering RTMedia Gallery 
  1873. * 
  1874. * @param array|string $attr 
  1875. */ 
  1876. function rtmedia_gallery( $attr = '' ) { 
  1877.  
  1878. echo RTMediaGalleryShortcode::render( $attr ); // @codingStandardsIgnoreLine 
  1879.  
  1880.  
  1881. /** 
  1882. * Get meta data of media 
  1883. * 
  1884. * @param bool|int $id 
  1885. * @param bool|string $key 
  1886. * 
  1887. * @return bool 
  1888. */ 
  1889. function get_rtmedia_meta( $id = false, $key = false ) { 
  1890.  
  1891. if ( apply_filters( 'rtmedia_use_legacy_meta_function', false ) ) { 
  1892. $rtmediameta = new RTMediaMeta(); 
  1893.  
  1894. return $rtmediameta->get_meta( $id, $key ); 
  1895. } else { 
  1896. // check whether to get single value or multiple 
  1897. $single = ( false === $key ) ? false : true; 
  1898.  
  1899. // use WP's default get_metadata function replace column name from "media_id" to "id" in query 
  1900. add_filter( 'query', 'rtm_filter_metaid_column_name' ); 
  1901.  
  1902. $meta = get_metadata( 'media', $id, $key, $single ); 
  1903.  
  1904. remove_filter( 'query', 'rtm_filter_metaid_column_name' ); 
  1905.  
  1906. return $meta; 
  1907.  
  1908.  
  1909. /** 
  1910. * Add media meta 
  1911. * 
  1912. * @param bool|int $id 
  1913. * @param bool|string $key 
  1914. * @param bool|string $value 
  1915. * @param bool $duplicate 
  1916. * 
  1917. * @return bool|string 
  1918. */ 
  1919. function add_rtmedia_meta( $id = false, $key = false, $value = false, $duplicate = false ) { 
  1920.  
  1921. if ( apply_filters( 'rtmedia_use_legacy_meta_function', false ) ) { 
  1922. $rtmediameta = new RTMediaMeta( $id, $key, $value, $duplicate ); 
  1923.  
  1924. return $rtmediameta->add_meta( $id, $key, $value, $duplicate ); 
  1925. } else { 
  1926. // use WP's default get_metadata function replace column name from "media_id" to "id" in query 
  1927. add_filter( 'query', 'rtm_filter_metaid_column_name' ); 
  1928.  
  1929. $meta = add_metadata( 'media', $id, $key, $value, ! $duplicate ); 
  1930.  
  1931. remove_filter( 'query', 'rtm_filter_metaid_column_name' ); 
  1932.  
  1933. return $meta; 
  1934.  
  1935.  
  1936. /** 
  1937. * Update media meta 
  1938. * 
  1939. * @param bool|int $id 
  1940. * @param bool|string $key 
  1941. * @param bool|string $value 
  1942. * @param bool $duplicate 
  1943. * 
  1944. * @return bool|string 
  1945. */ 
  1946. function update_rtmedia_meta( $id = false, $key = false, $value = false, $duplicate = false ) { 
  1947.  
  1948. if ( apply_filters( 'rtmedia_use_legacy_meta_function', false ) ) { 
  1949. $rtmediameta = new RTMediaMeta(); 
  1950.  
  1951. return $rtmediameta->update_meta( $id, $key, $value, $duplicate ); 
  1952. } else { 
  1953. // use WP's default get_metadata function replace column name from "media_id" to "id" in query 
  1954. add_filter( 'query', 'rtm_filter_metaid_column_name' ); 
  1955.  
  1956. $meta = update_metadata( 'media', $id, $key, $value, $duplicate ); 
  1957.  
  1958. remove_filter( 'query', 'rtm_filter_metaid_column_name' ); 
  1959.  
  1960. return $meta; 
  1961.  
  1962.  
  1963. /** 
  1964. * Delete media meta 
  1965. * 
  1966. * @param bool|int $id 
  1967. * @param bool|string $key 
  1968. * 
  1969. * @return array|bool 
  1970. */ 
  1971. function delete_rtmedia_meta( $id = false, $key = false ) { 
  1972.  
  1973. if ( apply_filters( 'rtmedia_use_legacy_meta_function', false ) ) { 
  1974. $rtmediameta = new RTMediaMeta(); 
  1975.  
  1976. return $rtmediameta->delete_meta( $id, $key ); 
  1977. } else { 
  1978. // use WP's default get_metadata function replace column name from "media_id" to "id" in query 
  1979. add_filter( 'query', 'rtm_filter_metaid_column_name' ); 
  1980.  
  1981. $meta = delete_metadata( 'media', $id, $key ); 
  1982.  
  1983. remove_filter( 'query', 'rtm_filter_metaid_column_name' ); 
  1984.  
  1985. return $meta; 
  1986.  
  1987. /** 
  1988. * Get global albums 
  1989. * 
  1990. * @return array 
  1991. */ 
  1992. function rtmedia_global_albums() { 
  1993.  
  1994. return RTMediaAlbum::get_globals(); 
  1995.  
  1996.  
  1997. /** 
  1998. * Get global album list 
  1999. * 
  2000. * @param bool|int $selected_album_id 
  2001. * 
  2002. * @return null|string 
  2003. */ 
  2004. function rtmedia_global_album_list( $selected_album_id = false ) { 
  2005.  
  2006. $model = new RTMediaModel(); 
  2007. $global_albums = rtmedia_global_albums(); 
  2008.  
  2009. if ( false === $selected_album_id && ! empty( $global_albums ) && is_array( $global_albums ) ) { 
  2010. $selected_album_id = $global_albums[0]; 
  2011.  
  2012. $option = null; 
  2013. $album_objects = $model->get_media( array( 
  2014. 'id' => $global_albums,  
  2015. ), false, false ); 
  2016.  
  2017. if ( $album_objects ) { 
  2018. foreach ( $album_objects as $album ) { 
  2019. //if selected_album_id is provided, keep that album_id selected by default 
  2020. $selected = ''; 
  2021.  
  2022. if ( ! empty( $selected_album_id ) && $selected_album_id === $album->id ) { 
  2023. $selected = 'selected="selected"'; 
  2024.  
  2025. $option .= '<option value="' . esc_attr( $album->id ) . '" ' . $selected . '>' . esc_html( $album->media_title ) . '</option>'; 
  2026.  
  2027. return $option; 
  2028.  
  2029.  
  2030. /** 
  2031. * Get user's album list 
  2032. * 
  2033. * @global RTMediaQuery $rtmedia_query 
  2034. * 
  2035. * @param bool $get_all 
  2036. * @param bool|int $selected_album_id 
  2037. * 
  2038. * @return bool|string 
  2039. */ 
  2040. function rtmedia_user_album_list( $get_all = false, $selected_album_id = false ) { 
  2041.  
  2042. global $rtmedia_query; 
  2043.  
  2044. $model = new RTMediaModel(); 
  2045. $global_option = rtmedia_global_album_list( $selected_album_id ); 
  2046. $global_albums = rtmedia_global_albums(); 
  2047.  
  2048. $user_id = apply_filters( 'rtmedia_album_by_user', get_current_user_id() ); 
  2049. $album_objects = $model->get_media( array( 
  2050. 'media_author' => $user_id,  
  2051. 'media_type' => 'album',  
  2052. ), false, 'context' ); 
  2053. $option_group = ''; 
  2054. $profile_option = ''; 
  2055.  
  2056. if ( $album_objects ) { 
  2057. foreach ( $album_objects as $album ) { 
  2058. if ( ! in_array( $album->id, array_map( 'intval', $global_albums ), true ) && ( ( isset( $rtmedia_query->media_query['album_id'] ) && ( $album->id !== $rtmedia_query->media_query['album_id'] || $get_all ) ) || ! isset( $rtmedia_query->media_query['album_id'] ) ) ) { 
  2059. if ( 'profile' === $album->context ) { 
  2060. $profile_option .= '<option value="' . esc_attr( $album->id ) . '" ' . selected( $selected_album_id, $album->id, false ) . '>' . esc_html( $album->media_title ) . '</option>'; 
  2061.  
  2062. $option = apply_filters( 'rtmedia_global_albums_in_uploader', "$global_option" ); 
  2063.  
  2064. if ( '' != $profile_option ) { 
  2065. $option .= "<optgroup label='" . esc_attr__( 'Profile Albums', 'buddypress-media' ) . " ' value = 'profile'>$profile_option</optgroup>"; 
  2066.  
  2067. if ( '' != $option_group && class_exists( 'BuddyPress' ) ) { 
  2068. $option .= "<optgroup label='" . esc_attr__( 'Group Albums', 'buddypress-media' ) . "' value = 'group'>$option_group</optgroup>"; 
  2069.  
  2070. if ( $option ) { 
  2071. return $option; 
  2072. } else { 
  2073. return false; 
  2074.  
  2075.  
  2076. /** 
  2077. * Get group's album list 
  2078. * 
  2079. * @global RTMediaQuery $rtmedia_query 
  2080. * 
  2081. * @param bool|int $selected_album_id 
  2082. * 
  2083. * @return bool|null|string 
  2084. */ 
  2085. function rtmedia_group_album_list( $selected_album_id = false ) { 
  2086. //by default, first album in list will be selected 
  2087. global $rtmedia_query; 
  2088.  
  2089. $model = new RTMediaModel(); 
  2090. $global_option = rtmedia_global_album_list( $selected_album_id ); 
  2091. $global_albums = rtmedia_global_albums(); 
  2092. $album_objects = $model->get_media( array( 
  2093. 'context' => $rtmedia_query->media_query['context'],  
  2094. 'context_id' => $rtmedia_query->media_query['context_id'],  
  2095. 'media_type' => 'album',  
  2096. ), false, false ); 
  2097. $option_group = ''; 
  2098.  
  2099. if ( $album_objects ) { 
  2100. foreach ( $album_objects as $album ) { 
  2101. if ( ! in_array( $album->id, $global_albums ) && ( ( isset( $rtmedia_query->media_query['album_id'] ) && ( $album->id != $rtmedia_query->media_query['album_id'] ) ) || ! isset( $rtmedia_query->media_query['album_id'] ) ) ) { 
  2102. $option_group .= '<option value="' . esc_attr( $album->id ) . '" ' . selected( $selected_album_id, $album->id ) . '>' . esc_html( $album->media_title ) . '</option>'; 
  2103.  
  2104. $option = $global_option; 
  2105.  
  2106. if ( ! empty( $option_group ) ) { 
  2107. $option .= "<optgroup label='" . esc_attr__( 'Group Albums', 'buddypress-media' ) . "' value = 'group'>$option_group</optgroup>"; 
  2108.  
  2109. if ( $option ) { 
  2110. return $option; 
  2111. } else { 
  2112. return false; 
  2113.  
  2114.  
  2115. /** 
  2116. * Checking if album creation is allowed 
  2117. * 
  2118. * @return bool 
  2119. */ 
  2120. function rtm_is_album_create_allowed() { 
  2121.  
  2122. return apply_filters( 'rtm_is_album_create_enable', true ); 
  2123.  
  2124.  
  2125. /** 
  2126. * Checking if user has an access to create an album 
  2127. * 
  2128. * @param bool|int $user_id 
  2129. * 
  2130. * @return bool 
  2131. */ 
  2132. function rtm_is_user_allowed_to_create_album( $user_id = false ) { 
  2133.  
  2134. if ( ! $user_id ) { 
  2135. $user_id = get_current_user_id(); 
  2136.  
  2137. return apply_filters( 'rtm_display_create_album_button', true, $user_id ); 
  2138.  
  2139.  
  2140. /** 
  2141. * Checking if album is editable 
  2142. * 
  2143. * @global RTMediaQuery $rtmedia_query 
  2144. * 
  2145. * @return bool 
  2146. */ 
  2147. function rtmedia_is_album_editable() { 
  2148.  
  2149. global $rtmedia_query; 
  2150.  
  2151. if ( isset( $rtmedia_query->query['context'] ) && 'profile' === $rtmedia_query->query['context'] ) { 
  2152. if ( isset( $rtmedia_query->media_query['media_author'] ) && get_current_user_id() === intval( $rtmedia_query->media_query['media_author'] ) ) { 
  2153. return true; 
  2154.  
  2155. if ( isset( $rtmedia_query->query['context'] ) && 'group' === $rtmedia_query->query['context'] ) { 
  2156. if ( isset( $rtmedia_query->album[0]->media_author ) && get_current_user_id() === intval( $rtmedia_query->album[0]->media_author ) ) { 
  2157. return true; 
  2158.  
  2159. return false; 
  2160.  
  2161.  
  2162. /** 
  2163. * Rendering sub nav 
  2164. * 
  2165. * @global RTMediaNav $rtMediaNav 
  2166. */ 
  2167. function rtmedia_sub_nav() { 
  2168.  
  2169. global $rtMediaNav; 
  2170.  
  2171. $rtMediaNav = new RTMediaNav(); 
  2172.  
  2173. $rtMediaNav->sub_nav(); 
  2174.  
  2175.  
  2176. /** 
  2177. * Checking if album is enable 
  2178. * 
  2179. * @global RTMedia $rtmedia 
  2180. * 
  2181. * @return bool 
  2182. */ 
  2183. function is_rtmedia_album_enable() { 
  2184.  
  2185. global $rtmedia; 
  2186.  
  2187. if ( isset( $rtmedia->options['general_enableAlbums'] ) && 0 !== intval( $rtmedia->options['general_enableAlbums'] ) ) { 
  2188. return true; 
  2189.  
  2190. return false; 
  2191.  
  2192.  
  2193. /** 
  2194. * Loading right media template 
  2195. */ 
  2196. function rtmedia_load_template() { 
  2197.  
  2198. do_action( 'rtmedia_before_template_load' ); 
  2199.  
  2200. include( RTMediaTemplate::locate_template() ); 
  2201.  
  2202. do_action( 'rtmedia_after_template_load' ); 
  2203.  
  2204.  
  2205. /** 
  2206. * Checking if privacy is enabled 
  2207. * 
  2208. * @global RTMedia $rtmedia 
  2209. * 
  2210. * @return bool 
  2211. */ 
  2212. function is_rtmedia_privacy_enable() { 
  2213.  
  2214. global $rtmedia; 
  2215.  
  2216. if ( isset( $rtmedia->options['privacy_enabled'] ) && 0 !== intval( $rtmedia->options['privacy_enabled'] ) ) { 
  2217. return true; 
  2218.  
  2219. return false; 
  2220.  
  2221.  
  2222. /** 
  2223. * Checking if user can override the existing privacy 
  2224. * 
  2225. * @global RTMedia $rtmedia 
  2226. * 
  2227. * @return bool 
  2228. */ 
  2229. function is_rtmedia_privacy_user_overide() { 
  2230.  
  2231. global $rtmedia; 
  2232.  
  2233. if ( isset( $rtmedia->options['privacy_userOverride'] ) && 0 !== intval( $rtmedia->options['privacy_userOverride'] ) ) { 
  2234. return true; 
  2235.  
  2236. return false; 
  2237.  
  2238.  
  2239. /** 
  2240. * Rendering privacy UI 
  2241. * 
  2242. * @global RTMediaQuery $rtmedia_query 
  2243. * 
  2244. * @return bool|string 
  2245. */ 
  2246. function rtmedia_edit_media_privacy_ui() { 
  2247.  
  2248. global $rtmedia_query; 
  2249.  
  2250. /** check is comment media */ 
  2251. $comment_media = rtmedia_is_comment_media( rtmedia_id() ); 
  2252.  
  2253. if ( isset( $rtmedia_query->query['context'] ) && 'group' === $rtmedia_query->query['context'] ) { 
  2254. //if context is group i.e editing a group media, dont show the privacy dropdown 
  2255. return false; 
  2256.  
  2257. $privacymodel = new RTMediaPrivacy( false ); 
  2258. $privacy = $privacymodel->select_privacy_ui( $echo = false ); 
  2259.  
  2260. if ( isset( $rtmedia_query->media ) && is_array( $rtmedia_query->media ) && isset( $rtmedia_query->media['0'] ) ) { 
  2261. if ( isset( $rtmedia_query->media['0']->privacy ) && $rtmedia_query->media['0']->privacy != '80' ) { 
  2262. if ( $privacy && empty( $comment_media ) ) { 
  2263. return "<div class='rtmedia-edit-privacy rtm-field-wrap'><label for='privacy'>" . esc_html__( 'Privacy : ', 'buddypress-media' ) . '</label>' . $privacy . '</div>'; 
  2264.  
  2265. /** 
  2266. * Get default privacy 
  2267. * 
  2268. * @global RTMedia $rtmedia 
  2269. * 
  2270. * @return int 
  2271. */ 
  2272. function get_rtmedia_default_privacy() { 
  2273.  
  2274. global $rtmedia; 
  2275.  
  2276. if ( isset( $rtmedia->options['privacy_default'] ) ) { 
  2277. return $rtmedia->options['privacy_default']; 
  2278.  
  2279. return 0; 
  2280.  
  2281.  
  2282. /** 
  2283. * Checking if media is enabled in BuddyPress group 
  2284. * 
  2285. * @global RTMedia $rtmedia 
  2286. * 
  2287. * @return bool 
  2288. */ 
  2289. function is_rtmedia_group_media_enable() { 
  2290.  
  2291. global $rtmedia; 
  2292.  
  2293. if ( isset( $rtmedia->options['buddypress_enableOnGroup'] ) && 0 !== intval( $rtmedia->options['buddypress_enableOnGroup'] ) ) { 
  2294. return true; 
  2295.  
  2296. return false; 
  2297.  
  2298. /** 
  2299. * Checking if media is enabled in BuddyPress Member's profile 
  2300. * 
  2301. * @global RTMedia $rtmedia 
  2302. * 
  2303. * @return bool 
  2304. */ 
  2305. function is_rtmedia_profile_media_enable() { 
  2306.  
  2307. global $rtmedia; 
  2308.  
  2309. if ( isset( $rtmedia->options['buddypress_enableOnProfile'] ) && 0 !== intval( $rtmedia->options['buddypress_enableOnProfile'] ) ) { 
  2310. return true; 
  2311.  
  2312. return false; 
  2313.  
  2314.  
  2315. /** 
  2316. * Checking if user in group component 
  2317. * 
  2318. * @global RTMediaQuery $rtmedia_query 
  2319. * 
  2320. * @return bool 
  2321. */ 
  2322. function is_rtmedia_bp_group() { 
  2323.  
  2324. global $rtmedia_query; 
  2325.  
  2326. if ( isset( $rtmedia_query->query['context'] ) && 'group' === $rtmedia_query->query['context'] ) { 
  2327. return true; 
  2328.  
  2329. return false; 
  2330.  
  2331.  
  2332. /** 
  2333. * Checking if user in profile component 
  2334. * 
  2335. * @global RTMediaQuery $rtmedia_query 
  2336. * 
  2337. * @return bool 
  2338. */ 
  2339. function is_rtmedia_bp_profile() { 
  2340.  
  2341. global $rtmedia_query; 
  2342.  
  2343. if ( isset( $rtmedia_query->query['context'] ) && 'profile' == $rtmedia_query->query['context'] ) { 
  2344. return true; 
  2345.  
  2346. return false; 
  2347.  
  2348.  
  2349. /** 
  2350. * Checking if user can upload in BuddyPress group 
  2351. * 
  2352. * @return bool 
  2353. */ 
  2354. function can_user_upload_in_group() { 
  2355.  
  2356. $group = groups_get_current_group(); 
  2357. $user_id = get_current_user_id(); 
  2358. $display_flag = false; 
  2359.  
  2360. if ( groups_is_user_member( $user_id, $group->id ) ) { 
  2361. $display_flag = true; 
  2362.  
  2363. $display_flag = apply_filters( 'rtm_can_user_upload_in_group', $display_flag ); 
  2364.  
  2365. return $display_flag; 
  2366.  
  2367.  
  2368. /** 
  2369. * Checking if user can create an album in BuddyPress group 
  2370. * 
  2371. * @param bool|int $group_id 
  2372. * @param bool|int $user_id 
  2373. * 
  2374. * @return bool 
  2375. */ 
  2376. function can_user_create_album_in_group( $group_id = false, $user_id = false ) { 
  2377.  
  2378. if ( false == $group_id ) { 
  2379. $group = groups_get_current_group(); 
  2380. $group_id = $group->id; 
  2381.  
  2382. $upload_level = groups_get_groupmeta( $group_id, 'rt_media_group_control_level' ); 
  2383.  
  2384. if ( empty( $upload_level ) ) { 
  2385. $upload_level = groups_get_groupmeta( $group_id, 'bp_media_group_control_level' ); 
  2386.  
  2387. if ( empty( $upload_level ) ) { 
  2388. $upload_level = 'all'; 
  2389.  
  2390. $user_id = get_current_user_id(); 
  2391. $display_flag = false; 
  2392.  
  2393. if ( groups_is_user_member( $user_id, $group_id ) ) { 
  2394. if ( 'admin' === $upload_level ) { 
  2395. if ( groups_is_user_admin( $user_id, $group_id ) > 0 ) { 
  2396. $display_flag = true; 
  2397. } else { 
  2398. if ( 'moderators' === $upload_level ) { 
  2399. if ( groups_is_user_mod( $user_id, $group_id ) || groups_is_user_admin( $user_id, $group_id ) ) { 
  2400. $display_flag = true; 
  2401. } else { 
  2402. $display_flag = true; 
  2403.  
  2404. $display_flag = apply_filters( 'can_user_create_album_in_group', $display_flag ); 
  2405.  
  2406. return $display_flag; 
  2407.  
  2408.  
  2409. /** 
  2410. * Checking if video upload is allowed 
  2411. * 
  2412. * @global RTMedia $rtmedia 
  2413. * 
  2414. * @return bool 
  2415. */ 
  2416. function is_rtmedia_upload_video_enabled() { 
  2417.  
  2418. global $rtmedia; 
  2419.  
  2420. if ( isset( $rtmedia->options['allowedTypes_video_enabled'] ) && 0 !== intval( $rtmedia->options['allowedTypes_video_enabled'] ) ) { 
  2421. return true; 
  2422.  
  2423. return false; 
  2424.  
  2425. /** 
  2426. * Checking if photo upload is allowed 
  2427. * 
  2428. * @global RTMedia $rtmedia 
  2429. * 
  2430. * @return bool 
  2431. */ 
  2432. function is_rtmedia_upload_photo_enabled() { 
  2433.  
  2434. global $rtmedia; 
  2435.  
  2436. if ( isset( $rtmedia->options['allowedTypes_photo_enabled'] ) && 0 !== intval( $rtmedia->options['allowedTypes_photo_enabled'] ) ) { 
  2437. return true; 
  2438.  
  2439. return false; 
  2440.  
  2441.  
  2442. /** 
  2443. * Checking if music upload is allowed 
  2444. * 
  2445. * @global RTMedia $rtmedia 
  2446. * 
  2447. * @return bool 
  2448. */ 
  2449. function is_rtmedia_upload_music_enabled() { 
  2450.  
  2451. global $rtmedia; 
  2452.  
  2453. if ( isset( $rtmedia->options['allowedTypes_music_enabled'] ) && 0 !== intval( $rtmedia->options['allowedTypes_music_enabled'] ) ) { 
  2454. return true; 
  2455.  
  2456. return false; 
  2457.  
  2458.  
  2459. /** 
  2460. * Get allowed media upload type 
  2461. * 
  2462. * @global RTMedia $rtmedia 
  2463. * 
  2464. * @return string 
  2465. */ 
  2466. function get_rtmedia_allowed_upload_type() { 
  2467.  
  2468. global $rtmedia; 
  2469.  
  2470. $allow_type_str = ''; 
  2471. $sep = ''; 
  2472.  
  2473. foreach ( $rtmedia->allowed_types as $type ) { 
  2474. if ( function_exists( 'is_rtmedia_upload_' . $type['name'] . '_enabled' ) && call_user_func( 'is_rtmedia_upload_' . $type['name'] . '_enabled' ) ) { 
  2475. foreach ( $type['extn'] as $extn ) { 
  2476. $allow_type_str .= $sep . $extn; 
  2477.  
  2478. $sep = ', '; 
  2479.  
  2480. return $allow_type_str; 
  2481.  
  2482.  
  2483. /** 
  2484. * Checking if is admin 
  2485. * 
  2486. * @return bool 
  2487. */ 
  2488. function is_rt_admin() { 
  2489.  
  2490. return current_user_can( 'list_users' ); 
  2491.  
  2492.  
  2493. /** 
  2494. * Get media like count 
  2495. * 
  2496. * @param bool|int $media_id 
  2497. * 
  2498. * @return array|int 
  2499. */ 
  2500. function get_rtmedia_like( $media_id = false ) { 
  2501.  
  2502. $mediamodel = new RTMediaModel(); 
  2503. $actions = $mediamodel->get( array( 
  2504. 'id' => rtmedia_id( $media_id ),  
  2505. ) ); 
  2506.  
  2507. if ( isset( $actions[0]->likes ) ) { 
  2508. $actions = intval( $actions[0]->likes ); 
  2509. } else { 
  2510. $actions = 0; 
  2511.  
  2512. return $actions; 
  2513.  
  2514.  
  2515. /** 
  2516. * Show media like count 
  2517. * 
  2518. * @global RTMedia $rtmedia 
  2519. */ 
  2520. function show_rtmedia_like_counts() { 
  2521.  
  2522. global $rtmedia; 
  2523.  
  2524. $options = $rtmedia->options; 
  2525. $count = get_rtmedia_like(); 
  2526.  
  2527. if ( ! ( isset( $options['general_enableLikes'] ) && 0 === intval( $options['general_enableLikes'] ) ) ) { 
  2528. $class = ''; 
  2529.  
  2530. if ( ! intval( $count ) ) { 
  2531. $class = 'hide'; 
  2532. ?> 
  2533. <div class='rtmedia-like-info <?php echo $class; ?>'> 
  2534. <i class="rtmicon-thumbs-up rtmicon-fw"></i> 
  2535. <span class="rtmedia-like-counter-wrap"> 
  2536. <?php 
  2537. if ( class_exists( 'RTMediaLike' ) && function_exists( 'rtmedia_who_like_html' ) ) { 
  2538. $rtmedialike = new RTMediaLike(); 
  2539. echo rtmedia_who_like_html( $count, $rtmedialike->is_liked( rtmedia_id() ) ); 
  2540. ?> 
  2541. </span> 
  2542. <?php 
  2543. ?> 
  2544. </div> 
  2545. <?php 
  2546.  
  2547.  
  2548.  
  2549.  
  2550. /** 
  2551. * Print rtmedia who like html 
  2552. * 
  2553. * @param int $like_count ( Total like Count ) 
  2554. * @param bool|string $user_like_it ( login user like it or not ) 
  2555. * 
  2556. * @return string HTML 
  2557. */ 
  2558. if ( ! function_exists( 'rtmedia_who_like_html' ) ) { 
  2559. function rtmedia_who_like_html( $like_count, $user_like_it ) { 
  2560. $like_count = ( $like_count ) ? $like_count : false; 
  2561. $user_like_it = ( $user_like_it ) ? true : false; 
  2562. $like_count_new = $like_count; 
  2563. $html = ''; 
  2564. if ( $like_count == 1 && $user_like_it ) { 
  2565. /** 
  2566. * rtmedia you like text 
  2567. * @param $html TEXT 
  2568. * @param int $like_count Total Like 
  2569. * @param int $user_like_it User Like it or Not 
  2570. * @return html TEXT to display 
  2571. */ 
  2572. $html = apply_filters( 'rtmedia_like_html_you_only_like', esc_html__( 'You like this', 'buddypress-media' ), $like_count, $user_like_it ); 
  2573. } elseif ( $like_count ) { 
  2574. if ( $like_count > 1 && $user_like_it ) { 
  2575. /** 
  2576. * rtmedia you and 
  2577. * @param $html TEXT 
  2578. * @param int $like_count Total Like 
  2579. * @param int $user_like_it User Like it or Not 
  2580. * @return html TEXT to display 
  2581. */ 
  2582. $html .= apply_filters( 'rtmedia_like_html_you_and_more_like', esc_html__( 'You and ', 'buddypress-media' ), $like_count, $user_like_it ); 
  2583. $like_count_new--; 
  2584.  
  2585. /** 
  2586. * rtmedia Disaply count 
  2587. * @param int $like_count Total Like 
  2588. * @param int $user_like_it User Like it or Not 
  2589. * @return INT Count to display 
  2590. */ 
  2591. $html .= apply_filters( 'rtmedia_like_html_you_and_more_like', $like_count, $user_like_it ); 
  2592.  
  2593. /** 
  2594. * rtmedia person or people likes it 
  2595. * @param $html TEXT 
  2596. * @param int $like_count Total Like 
  2597. * @param int $user_like_it User Like it or Not 
  2598. * @return html TEXT to display 
  2599. */ 
  2600. $html .= apply_filters( 'rtmedia_like_html_othe_likes_this', _n( ' person likes this', ' people like this', $like_count_new, 'buddypress-media' ) , $like_count, $user_like_it ); 
  2601.  
  2602. /** 
  2603. * rtmedia return whole HTML 
  2604. * @param $html TEXT 
  2605. * @param int $like_count Total Like 
  2606. * @param int $user_like_it User Like it or Not 
  2607. * @return html TEXT to display 
  2608. */ 
  2609. $html = apply_filters( 'rtmedia_who_like_html', $html , $like_count, $user_like_it ); 
  2610. return $html; 
  2611.  
  2612. /** 
  2613. * Get music cover art 
  2614. * 
  2615. * @param object $media_object 
  2616. * 
  2617. * @return bool|string 
  2618. */ 
  2619. function rtm_get_music_cover_art( $media_object ) { 
  2620.  
  2621. // return URL if cover_art already set. 
  2622. $url = $media_object->cover_art; 
  2623.  
  2624. if ( ! empty( $url ) && ! is_numeric( $url ) ) { 
  2625. return $url; 
  2626.  
  2627. // return false if covert_art is already analyzed earlier 
  2628. if ( -1 === intval( $url ) ) { 
  2629. return false; 
  2630.  
  2631. // Analyze media for the first time and set cover_art into database. 
  2632. $file = get_attached_file( $media_object->media_id ); 
  2633. $media_obj = new RTMediaMedia(); 
  2634. $media_tags = new RTMediaTags( $file ); 
  2635. $title_info = $media_tags->title; 
  2636. $image_info = $media_tags->image; 
  2637. $image_mime = $image_info['mime']; 
  2638. $mime = explode( '/', $image_mime ); 
  2639. $id = $media_object->id; 
  2640.  
  2641. if ( ! empty( $image_info['data'] ) ) { 
  2642. $thumb_upload_info = wp_upload_bits( $title_info . '.' . $mime[ count( $mime ) - 1 ], null, $image_info['data'] ); 
  2643.  
  2644. if ( is_array( $thumb_upload_info ) && ! empty( $thumb_upload_info['url'] ) ) { 
  2645. $media_obj->model->update( array( 
  2646. 'cover_art' => $thumb_upload_info['url'],  
  2647. ), array( 
  2648. 'id' => $id,  
  2649. ) ); 
  2650.  
  2651. return $thumb_upload_info['url']; 
  2652.  
  2653. $media_obj->model->update( array( 
  2654. 'cover_art' => '-1',  
  2655. ), array( 
  2656. 'id' => $id,  
  2657. ) ); 
  2658.  
  2659. return false; 
  2660.  
  2661.  
  2662. /** 
  2663. * "get_music_cover_art" is too generic function name. It shouldn't added in very first place. 
  2664. * It is renamed as "rtm_get_music_cover_art" 
  2665. * 
  2666. * @return bool 
  2667. */ 
  2668. if ( ! function_exists( 'get_music_cover_art' ) ) { 
  2669.  
  2670. function get_music_cover_art( $file, $id ) { 
  2671.  
  2672. return false; 
  2673.  
  2674.  
  2675. /** 
  2676. * Get the media privacy symbol 
  2677. * 
  2678. * @param bool|int $rtmedia_id 
  2679. * 
  2680. * @return string 
  2681. */ 
  2682. function get_rtmedia_privacy_symbol( $rtmedia_id = false ) { 
  2683.  
  2684. $mediamodel = new RTMediaModel(); 
  2685. $actions = $mediamodel->get( array( 
  2686. 'id' => rtmedia_id( $rtmedia_id ),  
  2687. ) ); 
  2688. $privacy = ''; 
  2689.  
  2690. if ( intval( $actions[0]->privacy ) >= 0 ) { 
  2691. $title = $icon = ''; 
  2692.  
  2693. switch ( $actions[0]->privacy ) { 
  2694. case 0: // public 
  2695. $title = esc_html__( 'Public', 'buddypress-media' ); 
  2696. $icon = 'dashicons dashicons-admin-site rtmicon'; 
  2697.  
  2698. break; 
  2699. case 20: // users 
  2700. $title = esc_html__( 'All members', 'buddypress-media' ); 
  2701. $icon = 'dashicons dashicons-groups rtmicon'; 
  2702.  
  2703. break; 
  2704. case 40: // friends 
  2705. $title = esc_html__( 'Your friends', 'buddypress-media' ); 
  2706. $icon = 'dashicons dashicons-networking rtmicon'; 
  2707.  
  2708. break; 
  2709. case 60: // private 
  2710. $title = esc_html__( 'Only you', 'buddypress-media' ); 
  2711. $icon = 'dashicons dashicons-lock rtmicon'; 
  2712.  
  2713. break; 
  2714. case 80: // private 
  2715. $title = esc_html__( 'Blocked temporarily', 'buddypress-media' ); 
  2716. $icon = 'dashicons dashicons-dismiss rtmicon'; 
  2717.  
  2718. break; 
  2719.  
  2720. if ( ! empty( $title ) && ! empty( $icon ) ) { 
  2721. $privacy = "<i class='" . esc_attr( $icon ) . "' title='" . esc_attr( $title ) . "'></i>"; 
  2722.  
  2723. return $privacy; 
  2724.  
  2725.  
  2726. /** 
  2727. * Get media uploaded gmt date 
  2728. * 
  2729. * @param bool|int $rtmedia_id 
  2730. * 
  2731. * @return string 
  2732. */ 
  2733. function get_rtmedia_date_gmt( $rtmedia_id = false ) { 
  2734.  
  2735. $media = get_post( rtmedia_media_id( rtmedia_id( $rtmedia_id ) ) ); 
  2736. $date_time = ''; 
  2737.  
  2738. if ( ! empty( $media->post_date_gmt ) ) { 
  2739. $date_time = rtmedia_convert_date( $media->post_date_gmt ); 
  2740.  
  2741. $date_time = apply_filters( 'rtmedia_comment_date_format', $date_time, null ); 
  2742.  
  2743. return '<span>' . $date_time . '</span>'; 
  2744.  
  2745.  
  2746. /** 
  2747. * Convert comment datetime to "time ago" format 
  2748. * 
  2749. * @param string $_date 
  2750. * 
  2751. * @return string 
  2752. */ 
  2753. function rtmedia_convert_date( $_date ) { 
  2754.  
  2755. $stf = 0; 
  2756. $date = new DateTime( $_date ); 
  2757. $date = $date->format( 'U' ); 
  2758. $cur_time = time(); 
  2759. $diff = $cur_time - $date; 
  2760. $time_unit = array( 'second', 'minute', 'hour' ); 
  2761. $length = array( 1, 60, 3600, 86400 ); 
  2762. $ago_text = esc_html__( '%s ago ', 'buddypress-media' ); 
  2763.  
  2764. for ( $i = sizeof( $length ) - 1; ( $i >= 0 ) && ( ( $no = $diff / $length[ $i ] ) <= 1 ); $i -- ) {} 
  2765.  
  2766. if ( $i < 0 ) { 
  2767. $i = 0; 
  2768.  
  2769. if ( $i <= 2 ) { //if posted in last 24 hours 
  2770. $_time = $cur_time - ( $diff % $length[ $i ] ); 
  2771. $no = floor( $no ); 
  2772.  
  2773. switch ( $time_unit[ $i ] ) { 
  2774. case 'second': 
  2775. $time_unit_phrase = _n( '1 second', '%s seconds', $no, 'buddypress-media' ); 
  2776.  
  2777. break; 
  2778. case 'minute': 
  2779. $time_unit_phrase = _n( '1 minute', '%s minutes', $no, 'buddypress-media' ); 
  2780.  
  2781. break; 
  2782. case 'hour': 
  2783. $time_unit_phrase = _n( '1 hour', '%s hours', $no, 'buddypress-media' ); 
  2784.  
  2785. break; 
  2786. default: 
  2787. // should not happen 
  2788. $time_unit_phrase = '%s unknown'; 
  2789.  
  2790. $value = sprintf( $time_unit_phrase . ' ', $no ); 
  2791.  
  2792. if ( ( 1 === $stf ) && ( $i >= 1 ) && ( ( $cur_time - $_time ) > 0 ) ) { 
  2793. $value .= rtmedia_convert_date( $_time ); 
  2794.  
  2795. return sprintf( $ago_text, $value ); 
  2796. } else { 
  2797. /** translators: date format, see http://php.net/date */ 
  2798. return date_i18n( 'd F Y ', strtotime( $_date ), true ); 
  2799.  
  2800.  
  2801. /** 
  2802. * Get media counts 
  2803. * 
  2804. * @global RTMediaQuery $rtmedia_query 
  2805. * 
  2806. * @return array|void 
  2807. */ 
  2808. function get_media_counts() { 
  2809.  
  2810. global $rtmedia_query; 
  2811.  
  2812. $user_id = false; 
  2813.  
  2814. if ( function_exists( 'bp_displayed_user_id' ) ) { 
  2815. $user_id = bp_displayed_user_id(); 
  2816. } else { 
  2817. if ( isset( $rtmedia_query ) && isset( $rtmedia_query->query['context_id'] ) && 'profile' === $rtmedia_query->query['context'] ) { 
  2818. $user_id = $rtmedia_query->query['context_id']; 
  2819.  
  2820. $media_nav = new RTMediaNav( false ); 
  2821. $temp = $media_nav->actual_counts( $user_id ); 
  2822.  
  2823. return $temp; 
  2824.  
  2825.  
  2826. /** 
  2827. * Checking if it is rtmedia's edit page 
  2828. * 
  2829. * @global string $pagenow 
  2830. * 
  2831. * @param null $new_edit 
  2832. * 
  2833. * @return bool 
  2834. */ 
  2835. function rtmedia_is_edit_page( $new_edit = null ) { 
  2836.  
  2837. global $pagenow; 
  2838.  
  2839. //make sure we are on the backend 
  2840. if ( ! is_admin() ) { 
  2841. return false; 
  2842.  
  2843. if ( 'edit' === $new_edit ) { 
  2844. return in_array( $pagenow, array( 'post.php' ), true ); 
  2845. } elseif ( 'new' === $new_edit ) { //check for new post page 
  2846. return in_array( $pagenow, array( 'post-new.php' ), true ); 
  2847. } else { //check for either new or edit 
  2848. return in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ); 
  2849.  
  2850.  
  2851. /** 
  2852. * Checking if it's a rtmedia page 
  2853. * 
  2854. * @global object $rtmedia_interaction 
  2855. * 
  2856. * @return bool 
  2857. */ 
  2858. function is_rtmedia_page() { 
  2859.  
  2860. if ( ! defined( 'RTMEDIA_MEDIA_SLUG' ) ) { 
  2861. return false; 
  2862.  
  2863. global $rtmedia_interaction; 
  2864.  
  2865. if ( ! isset( $rtmedia_interaction ) ) { 
  2866. return false; 
  2867.  
  2868. if ( ! isset( $rtmedia_interaction->routes ) ) { 
  2869. return false; 
  2870.  
  2871. return $rtmedia_interaction->routes[ RTMEDIA_MEDIA_SLUG ]->is_template(); 
  2872.  
  2873.  
  2874. /** 
  2875. * To be used in migration in importing 
  2876. * 
  2877. * @param int $seconds_left 
  2878. * 
  2879. * @return string 
  2880. */ 
  2881. function rtmedia_migrate_formatseconds( $seconds_left ) { 
  2882.  
  2883. $minute_in_seconds = 60; 
  2884. $hour_in_seconds = $minute_in_seconds * 60; 
  2885. $day_in_seconds = $hour_in_seconds * 24; 
  2886.  
  2887. $days = floor( $seconds_left / $day_in_seconds ); 
  2888. $seconds_left = $seconds_left % $day_in_seconds; 
  2889.  
  2890. $hours = floor( $seconds_left / $hour_in_seconds ); 
  2891. $seconds_left = $seconds_left % $hour_in_seconds; 
  2892.  
  2893. $minutes = floor( $seconds_left / $minute_in_seconds ); 
  2894. $seconds = $seconds_left % $minute_in_seconds; 
  2895.  
  2896. $time_components = array(); 
  2897.  
  2898. if ( $days > 0 ) { 
  2899. $time_components[] = $days . ' day' . ( $days > 1 ? 's' : '' ); 
  2900.  
  2901. if ( $hours > 0 ) { 
  2902. $time_components[] = $hours . ' hour' . ( $hours > 1 ? 's' : '' ); 
  2903.  
  2904. if ( $minutes > 0 ) { 
  2905. $time_components[] = $minutes . ' minute' . ( $minutes > 1 ? 's' : '' ); 
  2906.  
  2907. if ( $seconds > 0 ) { 
  2908. $time_components[] = $seconds . ' second' . ( $seconds > 1 ? 's' : '' ); 
  2909.  
  2910. if ( count( $time_components ) > 0 ) { 
  2911. $formatted_time_remaining = implode( ', ', $time_components ); 
  2912. $formatted_time_remaining = trim( $formatted_time_remaining ); 
  2913. } else { 
  2914. $formatted_time_remaining = 'No time remaining.'; 
  2915.  
  2916. return $formatted_time_remaining; 
  2917.  
  2918.  
  2919. /** 
  2920. * echo the size of the media file 
  2921. * 
  2922. * @global array $rtmedia_backbone 
  2923. * @global object $rtmedia_media 
  2924. * 
  2925. * @return int 
  2926. */ 
  2927. function rtmedia_file_size() { 
  2928.  
  2929. global $rtmedia_backbone; 
  2930.  
  2931. if ( $rtmedia_backbone['backbone'] ) { 
  2932. echo '<%= file_size %>'; 
  2933. } else { 
  2934. global $rtmedia_media; 
  2935.  
  2936. if ( isset( $rtmedia_media->file_size ) ) { 
  2937. return $rtmedia_media->file_size; 
  2938. } else { 
  2939. return filesize( get_attached_file( $rtmedia_media->media_id ) ); 
  2940.  
  2941.  
  2942. /** 
  2943. * Get rtmedia media type from file extension 
  2944. * 
  2945. * @global RTMedia $rtmedia 
  2946. * 
  2947. * @param string $extn 
  2948. * 
  2949. * @return bool|int|string 
  2950. */ 
  2951. function rtmedia_get_media_type_from_extn( $extn ) { 
  2952.  
  2953. global $rtmedia; 
  2954.  
  2955. $allowed_type = $rtmedia->allowed_types; 
  2956.  
  2957. foreach ( $allowed_type as $type => $param ) { 
  2958. if ( isset( $param['extn'] ) && is_array( $param['extn'] ) && in_array( $extn, $param['extn'], true ) ) { 
  2959. return $type; 
  2960.  
  2961. return false; 
  2962.  
  2963.  
  2964. /** 
  2965. * Get extension from media id 
  2966. * 
  2967. * @global object $rtmedia_media 
  2968. * 
  2969. * @param bool|int $media_id 
  2970. * 
  2971. * @return bool 
  2972. */ 
  2973. function rtmedia_get_extension( $media_id = false ) { 
  2974. // If media_id is false then use global media_id 
  2975. if ( ! $media_id ) { 
  2976. global $rtmedia_media; 
  2977.  
  2978. if ( isset( $rtmedia_media->media_id ) ) { 
  2979. $media_id = $rtmedia_media->media_id; 
  2980. } else { 
  2981. return false; 
  2982.  
  2983. // Getting filename from media id 
  2984. $filename = basename( wp_get_attachment_url( $media_id ) ); 
  2985.  
  2986. // Checking file type of uploaded document 
  2987. $file_type = wp_check_filetype( $filename ); 
  2988.  
  2989. // return the extension of the filename 
  2990. return $file_type['ext']; 
  2991.  
  2992.  
  2993. /** 
  2994. * Function to get permalink for current blog 
  2995. * 
  2996. * @param string $domain 
  2997. * 
  2998. * @return string 
  2999. */ 
  3000. function rtmedia_get_current_blog_url( $domain ) { 
  3001.  
  3002. $domain = get_home_url( get_current_blog_id() ); 
  3003.  
  3004. return $domain; 
  3005.  
  3006.  
  3007. /** 
  3008. * Checking if album is global 
  3009. * 
  3010. * @param int $album_id 
  3011. * 
  3012. * @return bool 
  3013. */ 
  3014. function rtmedia_is_global_album( $album_id ) { 
  3015.  
  3016. $rtmedia_global_albums = rtmedia_global_albums(); 
  3017.  
  3018. if ( ! in_array( intval( $album_id ), $rtmedia_global_albums, true ) ) { 
  3019. return true; 
  3020. } else { 
  3021. return false; 
  3022.  
  3023.  
  3024. /** 
  3025. * Checking if uploader view is allowed 
  3026. * 
  3027. * @param bool $allow 
  3028. * @param string $section 
  3029. * 
  3030. * @return bool 
  3031. */ 
  3032. function rtmedia_is_uploader_view_allowed( $allow, $section = 'media_gallery' ) { 
  3033.  
  3034. return apply_filters( 'rtmedia_allow_uploader_view', $allow, $section ); 
  3035.  
  3036.  
  3037. /** 
  3038. * Get rtMedia Encoding API Key 
  3039. * 
  3040. * @return string 
  3041. */ 
  3042. function get_rtmedia_encoding_api_key() { 
  3043.  
  3044. return get_site_option( 'rtmedia-encoding-api-key' ); 
  3045.  
  3046.  
  3047. /** 
  3048. * Filter SQL query strings to swap out the 'meta_id' column. 
  3049. * 
  3050. * WordPress uses the meta_id column for commentmeta and postmeta, and so 
  3051. * hardcodes the column name into its *_metadata() functions. rtMedia 
  3052. * uses 'id' for the primary column. To make WP's functions usable for rtMedia,  
  3053. * we use this filter on 'query' to swap all 'meta_id' with 'id. 
  3054. * 
  3055. * @param string $q 
  3056. * 
  3057. * @return string 
  3058. */ 
  3059. function rtm_filter_metaid_column_name( $q ) { 
  3060.  
  3061. /** 
  3062. * Replace quoted content with __QUOTE__ to avoid false positives. 
  3063. * This regular expression will match nested quotes. 
  3064. */ 
  3065. $quoted_regex = "/'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'/s"; 
  3066.  
  3067. preg_match_all( $quoted_regex, $q, $quoted_matches ); 
  3068.  
  3069. $q = preg_replace( $quoted_regex, '__QUOTE__', $q ); 
  3070. $q = str_replace( 'meta_id', 'id', $q ); 
  3071.  
  3072. // Put quoted content back into the string. 
  3073. if ( ! empty( $quoted_matches[0] ) ) { 
  3074. for ( $i = 0; $i < count( $quoted_matches[0] ); $i ++ ) { 
  3075. $quote_pos = strpos( $q, '__QUOTE__' ); 
  3076. $q = substr_replace( $q, $quoted_matches[0][ $i ], $quote_pos, 9 ); 
  3077.  
  3078. return $q; 
  3079.  
  3080.  
  3081. /** 
  3082. * Checking if SCRIPT_DEBUG constant is defined or not 
  3083. * 
  3084. * @return string 
  3085. */ 
  3086. function rtm_get_script_style_suffix() { 
  3087.  
  3088. $suffix = ( defined( 'SCRIPT_DEBUG' ) && constant( 'SCRIPT_DEBUG' ) === true ) ? '' : '.min'; 
  3089.  
  3090. return $suffix; 
  3091.  
  3092.  
  3093. /** 
  3094. * To get list of allowed types in rtMedia 
  3095. * 
  3096. * @since 3.8.16 
  3097. * 
  3098. * @global RTMedia $rtmedia 
  3099. * 
  3100. * @return array 
  3101. */ 
  3102. function rtmedia_get_allowed_types() { 
  3103.  
  3104. global $rtmedia; 
  3105.  
  3106. $allowed_media_type = $rtmedia->allowed_types; 
  3107. $allowed_media_type = apply_filters( 'rtmedia_allowed_types', $allowed_media_type ); 
  3108.  
  3109. return $allowed_media_type; 
  3110.  
  3111.  
  3112. /** 
  3113. * To get list of allowed upload types in rtMedia 
  3114. * 
  3115. * @since 3.8.16 
  3116. * 
  3117. * @return array 
  3118. */ 
  3119. function rtmedia_get_allowed_upload_types() { 
  3120.  
  3121. $allowed_types = rtmedia_get_allowed_types(); 
  3122.  
  3123. foreach ( $allowed_types as $type => $type_detail ) { 
  3124. if ( ! ( function_exists( 'is_rtmedia_upload_' . $type . '_enabled' ) && call_user_func( 'is_rtmedia_upload_' . $type . '_enabled' ) ) ) { 
  3125. unset( $allowed_types[ $type ] ); 
  3126.  
  3127. return $allowed_types; 
  3128.  
  3129.  
  3130. /** 
  3131. * To get list of allowed upload type name in rtMedia 
  3132. * 
  3133. * @since 3.8.16 
  3134. * 
  3135. * @return array 
  3136. */ 
  3137. function rtmedia_get_allowed_upload_types_array() { 
  3138.  
  3139. $allowed_types = rtmedia_get_allowed_upload_types(); 
  3140. $types = array_keys( $allowed_types ); 
  3141.  
  3142. return $types; 
  3143.  
  3144.  
  3145. /** 
  3146. * Upload and add media 
  3147. * 
  3148. * @param array $upload_params 
  3149. * 
  3150. * @return bool|int 
  3151. */ 
  3152. function rtmedia_add_media( $upload_params = array() ) { 
  3153.  
  3154. if ( empty( $upload_params ) ) { 
  3155. $upload_params = $_POST; // @codingStandardsIgnoreLine 
  3156.  
  3157. $upload_model = new RTMediaUploadModel(); 
  3158. $upload_array = $upload_model->set_post_object( $upload_params ); 
  3159.  
  3160. $rtupload = new RTMediaUpload( $upload_array ); 
  3161. $media_id = isset( $rtupload->media_ids[0] ) ? $rtupload->media_ids[0] : false; 
  3162.  
  3163. return $media_id; 
  3164.  
  3165.  
  3166. /** 
  3167. * Add multiple meta key and value for media. 
  3168. * 
  3169. * @param int $media_id 
  3170. * @param string $meta_key_val 
  3171. * 
  3172. * @return array 
  3173. */ 
  3174. function rtmedia_add_multiple_meta( $media_id, $meta_key_val ) { 
  3175.  
  3176. $meta_ids = array(); 
  3177.  
  3178. if ( ! empty( $media_id ) && ! empty( $meta_key_val ) ) { 
  3179. $media_meta = new RTMediaMeta(); 
  3180.  
  3181. foreach ( $meta_key_val as $meta_key => $meta_val ) { 
  3182. $meta_ids[] = $media_meta->add_meta( $media_id, $meta_key, $meta_val ); 
  3183.  
  3184. return $meta_ids; 
  3185.  
  3186.  
  3187. /** 
  3188. * To get server variable 
  3189. * 
  3190. * @param string $server_key 
  3191. * @param string $filter_type 
  3192. * 
  3193. * @return string 
  3194. */ 
  3195. function rtm_get_server_var( $server_key, $filter_type = 'FILTER_SANITIZE_STRING' ) { 
  3196.  
  3197. $server_val = ''; 
  3198.  
  3199. if ( function_exists( 'filter_input' ) && filter_has_var( INPUT_SERVER, $server_key ) ) { 
  3200. $server_val = filter_input( INPUT_SERVER, $server_key, constant( $filter_type ) ); 
  3201. } elseif ( isset( $_SERVER[ $server_key ] ) ) { 
  3202. $server_val = $_SERVER[ $server_key ]; 
  3203.  
  3204. return $server_val; 
  3205.  
  3206.  
  3207. /** 
  3208. * Check if URL exists of a given media type (i.e mp4, ogg, wmv) 
  3209. * 
  3210. * @param array $medias 
  3211. * @param string $media_type 
  3212. * 
  3213. * @return bool 
  3214. */ 
  3215. function rtt_is_video_exists( $medias, $media_type = 'mp4' ) { 
  3216.  
  3217. if ( empty( $medias ) || empty( $media_type ) ) { 
  3218. return false; 
  3219.  
  3220. if ( isset( $medias[ $media_type ] ) && is_array( $medias[ $media_type ] ) && ! empty( $medias[ $media_type ][0] ) ) { 
  3221. return $medias[ $media_type ][0]; 
  3222.  
  3223.  
  3224. /** 
  3225. * Send the request to the rtmedia server for addon license validation 
  3226. * and activation 
  3227. * 
  3228. * @since 4.2 
  3229. * 
  3230. * @param array $addon Array containing the license_key, addon_id 
  3231. * and addon name 
  3232. * 
  3233. * @return obejct|boolean Addon license data/status from server or the false on error 
  3234. */ 
  3235. function rtmedia_activate_addon_license( $addon = array() ) { 
  3236.  
  3237. if ( empty( $addon ) || ! is_array( $addon ) || count( $addon ) < 1 ) { 
  3238. return false; 
  3239.  
  3240. if ( ! isset( $addon['args'] ) ) { 
  3241. return false; 
  3242.  
  3243. if ( empty( $addon['args']['license_key'] ) || empty( $addon['name'] ) || empty( $addon['args']['addon_id'] ) ) { 
  3244. return false; 
  3245.  
  3246. $license = $addon['args']['license_key']; 
  3247.  
  3248. $addon_name = $addon['name']; 
  3249.  
  3250. $addon_id = $addon['args']['addon_id']; 
  3251.  
  3252. $store_url = ''; 
  3253. if ( defined( 'EDD_' . strtoupper( $addon_id ) . '_STORE_URL' ) ) { 
  3254. // Get the store URL from the constant defined in the addon 
  3255. $store_url = constant( 'EDD_' . strtoupper( $addon_id ) . '_STORE_URL' ); 
  3256.  
  3257. // If store URL not found in the addon, use the default store URL 
  3258. if ( empty( $store_url ) ) { 
  3259. $store_url = 'https://rtmedia.io/'; 
  3260.  
  3261. // data to send in our API request 
  3262. $api_params = array( 
  3263. 'edd_action' => 'activate_license',  
  3264. 'license' => $license,  
  3265. 'item_name' => urlencode( $addon_name ), // the name of our product in EDD 
  3266. 'url' => home_url(),  
  3267. ); 
  3268.  
  3269. // Call the custom API. 
  3270. $response = wp_remote_get( esc_url_raw( add_query_arg( $api_params, $store_url ) ), array( 'timeout' => 15, 'sslverify' => false ) ); 
  3271.  
  3272. // make sure the response came back okay 
  3273. if ( is_wp_error( $response ) ) { 
  3274. return false; 
  3275.  
  3276. // decode the license data 
  3277. $license_data = json_decode( wp_remote_retrieve_body( $response ) ); 
  3278.  
  3279. return $license_data; 
  3280.  
  3281.  
  3282.  
  3283.  
  3284.  
  3285. function rtmedia_wp_kses_of_buddypress( $comment_content, $allowedtags ) { 
  3286. if( function_exists( 'bp_activity_filter_kses' ) ) { 
  3287. $comment_string = bp_activity_filter_kses( $comment_content, $allowedtags ); 
  3288. }else{ 
  3289. $comment_string = wp_kses( $comment_content, $allowedtags ); 
  3290. return $comment_string; 
  3291.  
  3292.  
  3293. /** 
  3294. * is media is uploaded in the comment 
  3295. * parameter media_id int 
  3296. * return true/false value 
  3297. */ 
  3298. function rtmedia_is_comment_media( $rtmedia_id ) { 
  3299. return get_rtmedia_meta( $rtmedia_id, 'rtmedia_comment_media' ); 
  3300.  
  3301.  
  3302.  
  3303. function rtmedia_is_comment_media_single_page( $rtmedia_id ) { 
  3304. $comment_media = false; 
  3305. global $rtmedia; 
  3306. /** check if the reply in comment media is not allow */ 
  3307. if( $rtmedia_id && ! rtmedia_check_comment_in_commented_media_allow() ) { 
  3308. $comment_media = rtmedia_is_comment_media( $rtmedia_id ); 
  3309. return $comment_media; 
  3310.  
  3311.  
  3312. function rtmedia_view_conversation_of_media( $activity_id ) { 
  3313. if ( function_exists( 'bp_activity_get_permalink' ) ) { 
  3314. ?> 
  3315. <span> 
  3316. <a href="<?php echo bp_activity_get_permalink( $activity_id ); ?>" 
  3317. class="rtmedia-view-conversation" > 
  3318. <?php _e( 'View Conversation', 'buddypress-media' ); ?> 
  3319. </a> 
  3320. </span> 
  3321. <?php 
  3322.  
  3323.  
  3324.  
  3325.  
  3326. function rtmedia_get_comments_details_for_media_id( $media_id ) { 
  3327. $args = array( 
  3328. 'post_id' => $media_id,  
  3329. ); 
  3330. return get_comments( $args ); 
  3331.  
  3332.  
  3333. /** 
  3334. * Is comment allow in Commented Media. 
  3335. **/ 
  3336. function rtmedia_check_comment_in_commented_media_allow() { 
  3337. $value = false; 
  3338. global $rtmedia; 
  3339. /** variable */ 
  3340. if( isset( $rtmedia->options ) && isset( $rtmedia->options['rtmedia_disable_media_in_commented_media'] ) && 0 == $rtmedia->options['rtmedia_disable_media_in_commented_media'] ) { 
  3341. $value = true; 
  3342. return $value; 
  3343.  
  3344.  
  3345.  
  3346.  
  3347. /** 
  3348. * Is comment allow in Commented Media. 
  3349. **/ 
  3350. function rtmedia_check_comment_media_allow() { 
  3351. $value = false; 
  3352. global $rtmedia; 
  3353. /** variable */ 
  3354. if ( ( isset( $rtmedia->options ) && isset( $rtmedia->options['buddypress_enableOnComment'] ) && 1 == $rtmedia->options['buddypress_enableOnComment'] ) || ! isset( $rtmedia->options['buddypress_enableOnComment'] ) ) { 
  3355. $value = true; 
  3356. return $value; 
  3357.  
  3358.  
  3359. /** 
  3360. * Get the Original Content from the $_REQUEST 
  3361. * 
  3362. * @return string 
  3363. */ 
  3364. function rtmedia_get_original_comment_media_content() { 
  3365. $old_content = ' '; 
  3366.  
  3367. /** get the original contant from the $REQUEST */ 
  3368. if ( isset( $_REQUEST['content'] ) ) { 
  3369. $old_content = $_REQUEST['content']; 
  3370.  
  3371. if ( isset( $_REQUEST['comment_content'] ) ) { 
  3372. $old_content = $_REQUEST['comment_content']; 
  3373.  
  3374.  
  3375. /** is comment is empty then add content content space */ 
  3376. if ( strstr( $old_content, 'nbsp' ) ) { 
  3377. $old_content = ' '; 
  3378.  
  3379. return sanitize_text_field( $old_content ); 
  3380.  
  3381.  
  3382.  
  3383. /** 
  3384. * Will alter the rtMedia query and remove the comment media from it 
  3385. * 
  3386. * parameter $where string rtMedia query where conditions 
  3387. * parameter $table_name string rtMedia query table name 
  3388. * parameter $join string 
  3389. * 
  3390. * return string of rtMedia query where conditions 
  3391. */ 
  3392. function rtmedia_query_where_filter_remove_comment_media( $where, $table_name, $join ) { 
  3393. $where .= ' AND ' . $table_name . '.context NOT LIKE ( "comment-media" ) '; 
  3394. return $where; 
  3395.  
  3396.  
  3397.  
  3398.  
  3399.  
  3400. function rtmedia_bp_activity_entry_comments_callback() { 
  3401. global $activities_template; 
  3402.  
  3403. /** comment media activity is created so media is not allow */ 
  3404. $allow_media_activity_type = array( 'rtmedia_comment_activity', 'rtmedia_like_activity' ); 
  3405. $allow_media_activity_type = apply_filters( 'rtmedia_not_allow_comment_media_in_activity_type' , $allow_media_activity_type ); 
  3406.  
  3407. /** parent activity id */ 
  3408. $activity_id = bp_get_activity_id(); 
  3409.  
  3410. /** if activity id is not empty and the type is not as $allow_media_activity_type */ 
  3411. if( $activity_id && isset( $activities_template->activity ) && isset( $activities_template->activity->type ) && ! in_array( $activities_template->activity->type , $allow_media_activity_type ) ) { 
  3412. add_action( 'before_rtmedia_comment_uploader_display', 'rtmedia_before_rtmedia_comment_uploader_display_callback', 10 ); 
  3413. echo rtmedia_bp_activity_entry_comments_id_callback( $activity_id, 'activity', $activities_template->activity->component ); 
  3414. remove_action( 'before_rtmedia_comment_uploader_display', 'rtmedia_before_rtmedia_comment_uploader_display_callback', 10 ); 
  3415.  
  3416.  
  3417. function rtmedia_before_rtmedia_comment_uploader_display_callback( $flag ) { 
  3418. return true; 
  3419.  
  3420. function rtmedia_enable_comment_media_uplaod() { 
  3421. global $rtmedia; 
  3422. $comment_media = false; 
  3423.  
  3424. if ( isset( $rtmedia->options['buddypress_enableOnComment'] ) ) { 
  3425. if ( 0 !== intval( $rtmedia->options['buddypress_enableOnComment'] ) ) { 
  3426. $comment_media = true; 
  3427. } elseif ( function_exists( 'rtmedia_add_comments_extra_callback' ) && function_exists( 'rtmedia_bp_activity_entry_comments_callback' ) ) { 
  3428. $comment_media = true; 
  3429.  
  3430. if ( $comment_media ) { 
  3431. /** 
  3432. * Add Comment Media in rtMedia Popup 
  3433. */ 
  3434. add_action( 'rtmedia_add_comments_extra', 'rtmedia_add_comments_extra_callback', 10 ); 
  3435.  
  3436. /** 
  3437. * Add Media Upload in Activity 
  3438. */ 
  3439. add_action( 'bp_activity_entry_comments', 'rtmedia_bp_activity_entry_comments_callback', 10 ); 
  3440.  
  3441. function rtmedia_bp_activity_entry_comments_id_callback( $id, $type, $context = "activity" ) { 
  3442. if( class_exists( 'RTMediaComment' ) ) { 
  3443. /**add media in comment*/ 
  3444. return RTMediaComment::add_uplaod_media_button( $id, $type, $context ); 
  3445.  
  3446. function rtmedia_add_comments_extra_callback() { 
  3447. global $rtmedia_media; 
  3448. $context = 'activity'; 
  3449.  
  3450. if ( is_array( $rtmedia_media->context ) ) { 
  3451. $context = $rtmedia_media->context; 
  3452. $rtmedia_id = rtmedia_id(); 
  3453. if ( $rtmedia_id ) { 
  3454. echo rtmedia_bp_activity_entry_comments_id_callback( $rtmedia_id, 'rtmedia', $context ); 
  3455.  
  3456. /** 
  3457. * check if the show desc in album gallery setting is set or not 
  3458. * @return boolean if the general is enable then return true or else false 
  3459. */ 
  3460. if ( ! function_exists( 'rtmedia_get_album_description_setting' ) ) { 
  3461. function rtmedia_get_album_description_setting() { 
  3462. $return = false; 
  3463. global $rtmedia; 
  3464. if ( isset( $rtmedia->options ) && isset( $rtmedia->options['general_enableAlbums_description'] ) && 1 == intval( $rtmedia->options['general_enableAlbums_description'] ) ) { 
  3465. $return = true; 
  3466. return $return; 
  3467.  
  3468.  
  3469. if ( ! function_exists( 'rtmedia_hide_title_media_gallery' ) ) { 
  3470. function rtmedia_hide_title_media_gallery( $media_type = false ) { 
  3471. $return = 'hide'; 
  3472. $media_type_allow = array(); 
  3473. $media_type_allow = apply_filters( 'rtmedia_show_title_media_gallery', $media_type_allow ); 
  3474. if ( ! is_array( $media_type_allow ) ) { 
  3475. $media_type_allow = array(); 
  3476.  
  3477. if ( is_array( $media_type_allow ) && ! empty( $media_type ) && in_array( $media_type, $media_type_allow ) ) { 
  3478. $return = 'show'; 
  3479. return $return; 
  3480.  
  3481.  
  3482. /** 
  3483. * echo the title of the media 
  3484. * 
  3485. * @global array $rtmedia_backbone 
  3486. * 
  3487. * @return string 
  3488. */ 
  3489. if ( ! function_exists( 'rtmedia_show_title' ) ) { 
  3490. function rtmedia_show_title() { 
  3491.  
  3492. global $rtmedia_backbone; 
  3493.  
  3494. if ( $rtmedia_backbone['backbone'] ) { 
  3495. echo '<%= media_class %>'; 
  3496. } else { 
  3497. global $rtmedia_media; 
  3498. $media_class = 'hide'; 
  3499. if ( isset( $rtmedia_media->media_type ) && function_exists( 'rtmedia_hide_title_media_gallery' ) ) { 
  3500. $media_class = rtmedia_hide_title_media_gallery( $rtmedia_media->media_type ); 
  3501. return $media_class; 
.