BPMediaAlbumimporter

Description of BPMediaBPAlbumImporter.

Defined (1)

The class is defined in the following location(s).

/app/importers/BPMediaAlbumimporter.php  
  1. class BPMediaAlbumimporter extends BPMediaImporter { 
  2.  
  3. function __construct() { 
  4. global $wpdb; 
  5. parent::__construct(); 
  6. $table = "{$wpdb->base_prefix}bp_album"; 
  7. if ( BPMediaImporter::table_exists( $table ) && BPMediaAlbumimporter::_active( 'bp-album/loader.php' ) !== - 1 && ! $this->column_exists( 'import_status' ) ) { 
  8. $this->update_table(); 
  9.  
  10. function update_table() { 
  11. if ( $this->column_exists( 'import_status' ) ) { 
  12. return; 
  13. global $wpdb; 
  14.  
  15. return $wpdb->query( "ALTER TABLE {$wpdb->base_prefix}bp_album 
  16. ADD COLUMN import_status BIGINT (20) NOT NULL DEFAULT 0,  
  17. ADD COLUMN old_activity_id BIGINT (20) NOT NULL DEFAULT 0,  
  18. ADD COLUMN new_activity_id BIGINT (20) NOT NULL DEFAULT 0,  
  19. ADD COLUMN favorites TINYINT (1) NOT NULL DEFAULT 0" ); 
  20.  
  21. function column_exists( $column ) { 
  22. global $wpdb; 
  23.  
  24. return $wpdb->query( $wpdb->prepare( "SHOW COLUMNS FROM {$wpdb->base_prefix}bp_album LIKE %s limit 1", $column ) ); 
  25.  
  26. function ui() { 
  27. global $wpdb; 
  28. $bp_album_active = BPMediaImporter::_active( 'bp-album/loader.php' ); 
  29. $table = "{$wpdb->base_prefix}bp_album"; 
  30. if ( BPMediaImporter::table_exists( $table ) ) { 
  31.  
  32. $this->progress = new rtProgress(); 
  33. $total = BPMediaAlbumimporter::get_total_count(); 
  34. $remaining_comments = $this->get_remaining_comments(); 
  35. $finished = BPMediaAlbumimporter::get_completed_media( $total ); 
  36. $finished_users = BPMediaAlbumimporter::get_completed_users(); 
  37. $finished_comments = $this->get_finished_comments(); 
  38. $total_comments = (int) $finished_comments + (int) $remaining_comments; 
  39. $completed_users_favorites = (int) get_site_option( 'bp_media_bp_album_favorite_import_status', 0 ); 
  40. $users = count_users(); 
  41.  
  42. echo '<div id="bpmedia-bpalbumimporter">'; 
  43. wp_nonce_field( 'bpmedia-bpalbumimporter', 'bpaimporter_wpnonce' ); 
  44. if ( ( $finished[0]->media !== $total[0]->media ) || ( $users['total_users'] > $completed_users_favorites ) ) { 
  45. if ( 1 !== $bp_album_active ) { 
  46. echo '<div id="setting-error-bp-album-importer" class="error settings-error below-h2"> 
  47. <p><strong>' . esc_html__( 'Warning!', 'buddypress-media' ) . '</strong> ' . 
  48. esc_html__( 'This import process is irreversible. Although everything is tested, please take a ', 'buddypress-media' ) . 
  49. '<a target="_blank" href="http://codex.wordpress.org/WordPress_Backups">' . esc_html__( 'backup of your database and files', 'buddypress-media' ) . '</a>' . 
  50. esc_html__( ', before proceeding. If you don\'t know your way around databases and files, consider ', 'buddypress-media' ) . 
  51. '<a target="_blank" href="http://rtmedia.io/contact/?purpose=buddypress&utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media">' . esc_html__( 'hiring us', 'buddypress-media' ) . '</a>' . 
  52. esc_html__( ', or another professional.', 'buddypress-media' ) . 
  53. '</p>'; 
  54. echo '<p>' . esc_html__( 'If you have set "WP_DEBUG" in you wp-config.php file, please make sure it is set to "false", so that it doesn\'t conflict with the import process.', 'buddypress-media' ) . '</p></div>'; 
  55. echo '<div class="bp-album-import-accept"><p><strong><label for="bp-album-import-accept"><input type="checkbox" value="accept" name="bp-album-import-accept" id="bp-album-import-accept" /> ' . esc_html__( 'I have taken a backup of the database and files of this site.', 'buddypress-media' ) . '</label></strong></p></div>'; 
  56. echo '<button id="bpmedia-bpalbumimport" class="button button-primary">'; 
  57. esc_html__( 'Start Import', 'buddypress-media' ); 
  58. echo '</button>'; 
  59. echo '<div class="bp-album-importer-wizard">'; 
  60. echo '<div class="bp-album-users">'; 
  61. echo '<strong>'; 
  62. echo esc_html__( 'Users', 'buddypress-media' ) . ': <span class="finished">' . esc_html( $finished_users[0]->users ) . '</span> / <span class="total">' . esc_html( $total[0]->users ) . '</span>'; 
  63. echo '</strong>'; 
  64. if ( 0 !== $total[0]->users ) { 
  65. $users_progress = $this->progress->progress( $finished_users[0]->users, $total[0]->users ); 
  66. $this->progress->progress_ui( $users_progress ); 
  67. echo '</div>'; 
  68. echo '<br />'; 
  69. echo '<div class="bp-album-media">'; 
  70. echo '<strong>'; 
  71. echo esc_html__( 'Media', 'buddypress-media' ) . ': <span class="finished">' . esc_html( $finished[0]->media ) . '</span> / <span class="total">' . esc_html( $total[0]->media ) . '</span>'; 
  72. echo '</strong>'; 
  73. $progress = 100; 
  74. if ( 0 !== $total[0]->media ) { 
  75. $todo = $total[0]->media - $finished[0]->media; 
  76. $steps = ceil( $todo / 5 ); 
  77. $laststep = $todo % 5; 
  78. $progress = $this->progress->progress( $finished[0]->media, $total[0]->media ); 
  79. echo '<input type="hidden" value="' . esc_attr( $finished[0]->media ) . '" name="finished"/>'; 
  80. echo '<input type="hidden" value="' . esc_attr( $total[0]->media ) . '" name="total"/>'; 
  81. echo '<input type="hidden" value="' . esc_attr( $todo ) . '" name="todo"/>'; 
  82. echo '<input type="hidden" value="' . esc_attr( $steps ) . '" name="steps"/>'; 
  83. echo '<input type="hidden" value="' . esc_attr( $laststep ) . '" name="laststep"/>'; 
  84. $this->progress->progress_ui( $progress ); 
  85. echo '</div>'; 
  86. echo '<br>'; 
  87. echo '<div class="bp-album-comments">'; 
  88. if ( 0 !== $total_comments ) { 
  89. echo '<strong>'; 
  90. echo esc_html__( 'Comments', 'buddypress-media' ) . ': <span class="finished">' . esc_html( $finished_comments ) . '</span> / <span class="total">' . esc_html( $total_comments ) . '</span>'; 
  91. echo '</strong>'; 
  92. $comments_progress = $this->progress->progress( $finished_comments, $total_comments ); 
  93. $this->progress->progress_ui( $comments_progress ); 
  94. echo '<br />'; 
  95. } else { 
  96. echo '<p><strong>' . esc_html__( 'Comments: 0/0 (No comments to import)', 'buddypress-media' ) . '</strong></p>'; 
  97. echo '</div>'; 
  98. if ( 0 !== $completed_users_favorites ) { 
  99. echo '<br />'; 
  100. echo '<div class="bp-album-favorites">'; 
  101. echo '<strong>'; 
  102. echo esc_html__( 'User\'s Favorites', 'buddypress-media' ) . ': <span class="finished">' . esc_html( $completed_users_favorites ) . '</span> / <span class="total">' . esc_html( $users['total_users'] ) . '</span>'; 
  103. echo '</strong>'; 
  104. $favorites_progress = $this->progress->progress( $completed_users_favorites, $users['total_users'] ); 
  105. $this->progress->progress_ui( $favorites_progress ); 
  106. echo '</div>'; 
  107. echo '</div>'; 
  108. } else { 
  109. $deactivate_link = wp_nonce_url( admin_url( 'plugins.php?action=deactivate&plugin=' . urlencode( $this->path ) ), 'deactivate-plugin_' . $this->path ); 
  110. echo '<p>' . esc_html__( 'BP-Album is active on your site and will cause problems with the import.', 'buddypress-media' ) . '</p>'; 
  111. echo '<p><a class="button button-primary deactivate-bp-album" href="' . esc_url( $deactivate_link ) . '">' . esc_html__( 'Click here to deactivate BP-Album and continue importing', 'buddypress-media' ) . '</a></p>'; 
  112. } else { 
  113. $corrupt_media = BPMediaAlbumimporter::get_corrupt_media(); 
  114. if ( $corrupt_media ) { 
  115. echo '<div class="error below-h2">'; 
  116. echo '<p><strong>' . esc_html__( 'Some of the media failed to import. The file might be corrupt or deleted.', 'buddypress-media' ) . '</strong></p>'; 
  117. echo '<p>' . sprintf( esc_html__( 'The following %d BP Album Media id\'s could not be imported', 'buddypress-media' ), count( $corrupt_media ) ) . ': </p>'; 
  118. $corrupt_prefix_path = str_replace( '/wp-content', '', WP_CONTENT_URL ); 
  119. foreach ( $corrupt_media as $corrupt ) { 
  120. echo '<p>' . esc_html( $corrupt->id ) . ' => <a href="' . esc_url( $corrupt_prefix_path . $corrupt->pic_org_url ) . '">' . esc_html( $corrupt->title ) . '</a></p>'; 
  121. echo '</div>'; 
  122. } else { 
  123. echo '<div class="bp-album-import-accept i-accept">'; 
  124. echo '<p class="info">'; 
  125. $message = sprintf( esc_html__( 'I just imported bp-album to @rtMediaWP http://rt.cx/rtmedia on %s', 'buddypress-media' ), home_url() ); 
  126. echo '<strong>' . esc_html__( 'Congratulations!', 'buddypress-media' ) . '</strong> ' . esc_html__( 'All media from BP Album has been imported.', 'buddypress-media' ); 
  127. echo ' <a href="http://twitter.com/home/?status=' . esc_url( $message ) . '" class="button button-import-tweet" target= "_blank">' . esc_html__( 'Tweet this', 'buddypress-media' ) . '</a>'; 
  128. echo '</p>'; 
  129. echo '</div>'; 
  130. echo '<p>' . esc_html__( 'However, a lot of unnecessary files and a database table are still eating up your resources. If everything seems fine, you can clean this data up.', 'buddypress-media' ) . '</p>'; 
  131. echo '<br />'; 
  132. echo '<button id="bpmedia-bpalbumimport-cleanup" class="button btn-warning">'; 
  133. esc_html_e( 'Clean up Now', 'buddypress-media' ); 
  134. echo '</button>'; 
  135. echo ' <a href="' . esc_url( add_query_arg( array( 'page' => 'bp-media-settings' ), ( is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) ) ) ) . '" id="bpmedia-bpalbumimport-cleanup-later" class="button">'; 
  136. esc_html_e( 'Clean up Later', 'buddypress-media' ); 
  137. echo '</a>'; 
  138. echo '<br />'; 
  139. echo '<br />'; 
  140. echo '<br />'; 
  141. echo '<strong>' . esc_html__( 'Why don\'t you try adding some instagram like effects to your images?', 'buddypress-media' ) . '</strong>'; 
  142. echo '<div class="bp-media-addon"> 
  143. <a href="https://rtmedia.io/products/rtmedia-photo-filters/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media&utm_content=bp-album-importer" title="rtMedia Photo Filters" target="_blank"> 
  144. <img width="240" height="184" title="rtMedia Photo Filters" alt="rtMedia Photo Filters" src="' . esc_url( $img_src ) . 'BuddyPressMedia-Instagram.png?ref=bp-album-importer"> 
  145. </a> 
  146. <h4><a href="https://rtmedia.io/products/rtmedia-photo-filters/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media&utm_content=bp-album-importer" title="rtMedia Photo Filters" target="_blank">rtMedia Photo Filters</a></h4> 
  147. <div class="product_desc"> 
  148. <p>' . esc_html__( 'rtMedia Photo Filters adds Instagram like filters to images uploaded with BuddyPress Media.', 'buddypress-media' ) . '</p> 
  149. <p><strong>' . esc_html__( 'Important', 'buddypress-media' ) . ':</strong> ' . esc_html__( 'You need to have ImageMagick installed on your server for this addon to work.', 'buddypress-media' ) . '</p> 
  150. </div> 
  151. <div class="product_footer"> 
  152. <span class="price alignleft"><span class="amount">$19</span></span> 
  153. <a class="add_to_cart_button alignright product_type_simple" href="https://rtmedia.io/products/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media&utm_content=bp-album-importer&add-to-cart=34379" target="_blank">' . esc_html__( 'Buy Now', 'buddypress-media' ) . '</a> 
  154. <a class="alignleft product_demo_link" href="http://demo.rtmedia.io/rtmedia/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media&utm_content=bp-album-importer" title="rtMedia Photo Filters" target="_blank">' . esc_html__( 'Live Demo', 'buddypress-media' ) . '</a> 
  155. </div></div>'; 
  156. echo '</div>'; 
  157. } else { 
  158. echo '<p>' . esc_html__( 'Looks like you don\'t use BP Album. Is there any other BuddyPress Plugin you want an importer for?', 'buddypress-media' ) . '</p>'; 
  159. echo '<p>' . '<a href="https://github.com/rtCamp/rtMedia/issues/new">' . esc_html__( 'Create an issue', 'buddypress-media' ) . '</a>'; 
  160. echo esc_html__( ' on GitHub requesting the same.', 'buddypress-media' ) . '</p>'; 
  161.  
  162. function create_album( $author_id, $album_name = 'Imported Media' ) { 
  163. global $bp_media, $wpdb; 
  164.  
  165. if ( array_key_exists( 'bp_album_import_name', $bp_media->options ) ) { 
  166. if ( '' !== $bp_media->options['bp_album_import_name'] ) { 
  167. $album_name = $bp_media->options['bp_album_import_name']; 
  168.  
  169. $result = $wpdb->get_results( $wpdb->prepare( "SELECT ID from $wpdb->posts WHERE post_type='bp_media_album' AND post_status = 'publish' AND post_author = %d AND post_title LIKE %s limit 1", $author_id, $album_name ) ); 
  170. if ( count( $result ) < 1 ) { 
  171. $album = new BPMediaAlbum(); 
  172. $album->add_album( $album_name, $author_id ); 
  173. $album_id = $album->get_id(); 
  174. } else { 
  175. $album_id = $result[0]->ID; 
  176. $wpdb->update( $wpdb->base_prefix . 'bp_activity', array( 'secondary_item_id' => - 999 ), array( 'id' => get_post_meta( $album_id, 'bp_media_child_activity', true ) ) ); 
  177.  
  178. return $album_id; 
  179.  
  180. static function get_total_count() { 
  181. global $wpdb; 
  182. $table = $wpdb->base_prefix . 'bp_album'; 
  183. if ( BPMediaAlbumimporter::table_exists( $table ) ) { 
  184. return $wpdb->get_results( "SELECT COUNT(DISTINCT owner_id) as users, COUNT(id) as media FROM {$table}" ); // @codingStandardsIgnoreLine 
  185.  
  186. return 0; 
  187.  
  188. function get_remaining_comments() { 
  189. global $wpdb; 
  190. $bp_album_table = $wpdb->base_prefix . 'bp_album'; 
  191. $activity_table = $wpdb->base_prefix . 'bp_activity'; 
  192. if ( $this->table_exists( $bp_album_table ) ) { 
  193. // @codingStandardsIgnoreStart 
  194. return $wpdb->get_var( "SELECT SUM( b.count ) AS total 
  195. FROM ( 
  196. SELECT ( 
  197. SELECT COUNT( a.id ) 
  198. FROM {$activity_table} a 
  199. WHERE a.item_id = activity.id 
  200. AND a.component = 'activity' 
  201. AND a.type = 'activity_comment' 
  202. ) AS count 
  203. FROM $activity_table AS activity 
  204. INNER JOIN $bp_album_table AS album ON ( album.id = activity.item_id ) 
  205. WHERE activity.component = 'album' 
  206. AND activity.type = 'bp_album_picture' 
  207. AND album.import_status =0 
  208. )b" ); // @codingStandardsIgnoreEnd 
  209.  
  210. return 0; 
  211.  
  212. function get_finished_comments() { 
  213. global $wpdb; 
  214. $bp_album_table = $wpdb->base_prefix . 'bp_album'; 
  215. $activity_table = $wpdb->base_prefix . 'bp_activity'; 
  216. if ( $this->table_exists( $bp_album_table ) ) { 
  217. // @codingStandardsIgnoreStart 
  218. return $wpdb->get_var( "SELECT COUNT( activity.id ) AS count 
  219. FROM $activity_table AS activity 
  220. INNER JOIN $bp_album_table AS album ON ( activity.item_id = album.import_status ) 
  221. WHERE activity.component = 'activity' 
  222. AND activity.type = 'activity_comment'" ); // @codingStandardsIgnoreEnd 
  223.  
  224. return 0; 
  225.  
  226. static function get_completed_users() { 
  227. global $wpdb; 
  228. $table = $wpdb->base_prefix . 'bp_album'; 
  229. if ( BPMediaAlbumimporter::table_exists( $table ) ) { 
  230. // @codingStandardsIgnoreStart 
  231. return $wpdb->get_results( "SELECT COUNT( DISTINCT owner_id ) AS users 
  232. FROM $table 
  233. WHERE owner_id NOT 
  234. IN ( 
  235. SELECT a.owner_id 
  236. FROM $table a 
  237. WHERE a.import_status =0 
  238. " ); 
  239. // @codingStandardsIgnoreEnd 
  240.  
  241. return 0; 
  242.  
  243. static function get_completed_media() { 
  244. global $wpdb; 
  245. $table = $wpdb->base_prefix . 'bp_album'; 
  246. if ( BPMediaAlbumimporter::table_exists( $table ) ) { 
  247. return $wpdb->get_results( "SELECT COUNT(id) as media FROM $table WHERE import_status!=0" ); // @codingStandardsIgnoreLine 
  248.  
  249. return 0; 
  250.  
  251. static function get_corrupt_media() { 
  252. global $wpdb; 
  253. $table = $wpdb->base_prefix . 'bp_album'; 
  254. if ( BPMediaAlbumimporter::table_exists( $table ) ) { 
  255. return $wpdb->get_results( "SELECT id, title, pic_org_url FROM $table WHERE import_status=-1" ); // @codingStandardsIgnoreLine 
  256.  
  257. return 0; 
  258.  
  259. static function batch_import( $count = 5 ) { 
  260. global $wpdb; 
  261. $table = $wpdb->base_prefix . 'bp_album'; 
  262. $bp_album_data = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table} WHERE import_status = 0 ORDER BY owner_id LIMIT %d", $count ) ); // @codingStandardsIgnoreLine 
  263.  
  264. return $bp_album_data; 
  265.  
  266. static function bpmedia_ajax_import_callback() { 
  267. if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) { 
  268. wp_send_json( false ); 
  269. $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_NUMBER_INT ); 
  270. $count = filter_input( INPUT_GET, 'count', FILTER_SANITIZE_NUMBER_INT ); 
  271. $page = isset( $page ) ? $page : 1; 
  272. $count = isset( $count ) ? $count : 5; 
  273. $bp_album_data = BPMediaAlbumimporter::batch_import( $count ); 
  274. global $wpdb; 
  275. $table = $wpdb->base_prefix . 'bp_album'; 
  276. $activity_table = $wpdb->base_prefix . 'bp_activity'; 
  277. $activity_meta_table = $wpdb->base_prefix . 'bp_activity_meta'; 
  278. $comments = 0; 
  279. foreach ( $bp_album_data as &$bp_album_item ) { 
  280.  
  281. if ( get_site_option( 'bp_media_bp_album_importer_base_path' ) === '' ) { 
  282. $base_path = pathinfo( $bp_album_item->pic_org_path ); 
  283. update_site_option( 'bp_media_bp_album_importer_base_path', $base_path['dirname'] ); 
  284. $bpm_host_wp = new BPMediaHostWordpress(); 
  285. $bpm_host_wp->check_and_create_album( 0, 0, $bp_album_item->owner_id ); 
  286. $album_id = BPMediaAlbumimporter::create_album( $bp_album_item->owner_id, 'Imported Media' ); 
  287. $imported_media_id = BPMediaImporter::add_media( $album_id, $bp_album_item->title, $bp_album_item->description, $bp_album_item->pic_org_path, $bp_album_item->privacy, $bp_album_item->owner_id, 'Imported Media' ); 
  288. $wpdb->update( $table, array( 'import_status' => ( $imported_media_id ) ? $imported_media_id : - 1 ), array( 'id' => $bp_album_item->id ), array( '%d' ), array( '%d' ) ); 
  289. if ( $imported_media_id ) { 
  290. $comments += (int) BPMediaAlbumimporter::update_recorded_time_and_comments( $imported_media_id, $bp_album_item->id, "{$wpdb->base_prefix}bp_album" ); 
  291.  
  292. $bp_album_media_id = $wpdb->get_var( "SELECT activity.id from $activity_table as activity INNER JOIN $table as album ON ( activity.item_id = album.id ) WHERE activity.item_id = $bp_album_item->id AND activity.component = 'album' AND activity.type='bp_album_picture'" ); // @codingStandardsIgnoreLine 
  293. $wpdb->update( $table, array( 'old_activity_id' => $bp_album_media_id ), array( 'id' => $bp_album_item->id ), array( '%d' ), array( '%d' ) ); 
  294. $bp_new_activity_id = $wpdb->get_var( "SELECT id from $activity_table WHERE item_id = $imported_media_id AND component = 'activity' AND type='activity_update' AND secondary_item_id=0" ); // @codingStandardsIgnoreLine 
  295. $wpdb->update( $table, array( 'new_activity_id' => $bp_new_activity_id ), array( 'id' => $bp_album_item->id ), array( '%d' ), array( '%d' ) ); 
  296. if ( $wpdb->update( $activity_meta_table, array( 'activity_id' => $bp_new_activity_id ), array( 
  297. 'activity_id' => $bp_album_media_id,  
  298. 'meta_key' => 'favorite_count',  
  299. ), array( '%d' ), array( '%d' ) ) 
  300. ) { 
  301. $wpdb->update( $table, array( 'favorites' => 1 ), array( 'id' => $bp_album_item->id ), array( '%d' ), array( '%d' ) ); 
  302.  
  303. $finished_users = BPMediaAlbumimporter::get_completed_users(); 
  304.  
  305. echo wp_json_encode( array( 'page' => $page, 'users' => $finished_users[0]->users, 'comments' => $comments ) ); 
  306. die(); 
  307.  
  308. static function bpmedia_ajax_import_favorites() { 
  309. if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) { 
  310. wp_send_json( array( 'status' => false ) ); 
  311. global $wpdb; 
  312. $table = $wpdb->base_prefix . 'bp_album'; 
  313. $users = count_users(); 
  314. echo wp_json_encode( array( 
  315. 'favorites' => $wpdb->get_var( "SELECT COUNT(id) from $table WHERE favorites != 0" ), // @codingStandardsIgnoreLine 
  316. 'users' => $users['total_users'],  
  317. 'offset' => (int) get_site_option( 'bp_media_bp_album_favorite_import_status', 0 ),  
  318. ) ); 
  319. die(); 
  320.  
  321. static function bpmedia_ajax_import_step_favorites() { 
  322. if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) { 
  323. wp_send_json( array( 'status' => false ) ); 
  324. $offset = filter_input( INPUT_GET, 'offset', FILTER_SANITIZE_NUMBER_INT ); 
  325. $redirect = filter_input( INPUT_GET, 'redirect', FILTER_SANITIZE_URL ); 
  326. $offset = isset( $offset ) ? $offset : 0; 
  327. $redirect = isset( $redirect ) ? $redirect : false; 
  328. global $wpdb; 
  329. $table = $wpdb->base_prefix . 'bp_album'; 
  330. $blogusers = get_users( array( 'meta_key' => 'bp_favorite_activities', 'offset' => $offset, 'number' => 1 ) ); 
  331. if ( $blogusers ) { 
  332. foreach ( $blogusers as $user ) { 
  333. $favorite_activities = get_user_meta( $user->ID, 'bp_favorite_activities', true ); 
  334. if ( $favorite_activities ) { 
  335. $new_favorite_activities = $favorite_activities; 
  336. foreach ( $favorite_activities as $key => $favorite ) { 
  337. if ( $new_act = $wpdb->get_var( $wpdb->prepare( "SELECT new_activity_id from $table WHERE old_activity_id = %d limit 1", $favorite ) ) ) { // @codingStandardsIgnoreLine 
  338. $new_favorite_activities[ $key ] = $new_act; 
  339. update_user_meta( $user->ID, 'bp_favorite_activities', $new_favorite_activities ); 
  340. $completed_users_favorites = (int) get_site_option( 'bp_media_bp_album_favorite_import_status', 0 ) + 1; 
  341. update_site_option( 'bp_media_bp_album_favorite_import_status', $completed_users_favorites ); 
  342. echo esc_url( $redirect ); 
  343. die(); 
  344.  
  345. static function cleanup_after_install() { 
  346. global $wpdb; 
  347. if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) { 
  348. wp_send_json( array( 'status' => false ) ); 
  349. $table = $wpdb->base_prefix . 'bp_album'; 
  350. $dir = get_site_option( 'bp_media_bp_album_importer_base_path' ); 
  351. BPMediaImporter::cleanup( $table, $dir ); 
  352. die(); 
  353.  
  354. static function update_recorded_time_and_comments( $media, $bp_album_id, $table ) { 
  355. global $wpdb; 
  356. if ( function_exists( 'bp_activity_add' ) ) { 
  357. if ( ! is_object( $media ) ) { 
  358. try { 
  359. $media = new BPMediaHostWordpress( $media ); 
  360. } catch ( exception $e ) { 
  361. return false; 
  362. $activity_id = get_post_meta( $media->get_id(), 'bp_media_child_activity', true ); 
  363. if ( $activity_id ) { 
  364. $date_uploaded = $wpdb->get_var( $wpdb->prepare( "SELECT date_uploaded from $table WHERE id = %d", $bp_album_id ) ); // @codingStandardsIgnoreLine 
  365. $old_activity_id = $wpdb->get_var( $wpdb->prepare( "SELECT id from {$wpdb->base_prefix}bp_activity WHERE component = 'album' AND type = 'bp_album_picture' AND item_id = %d", $bp_album_id ) ); 
  366. if ( $old_activity_id ) { 
  367. $comments = $wpdb->get_results( $wpdb->prepare( "SELECT id, secondary_item_id from {$wpdb->base_prefix}bp_activity WHERE component = 'activity' AND type = 'activity_comment' AND item_id = %d", $old_activity_id ) ); 
  368. foreach ( $comments as $comment ) { 
  369. $update = array( 'item_id' => $activity_id ); 
  370. if ( $comment->secondary_item_id === $old_activity_id ) { 
  371. $update['secondary_item_id'] = $activity_id; 
  372. $wpdb->update( $wpdb->base_prefix . 'bp_activity', $update, array( 'id' => $comment->id ) ); 
  373. BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id ); 
  374. $wpdb->update( $wpdb->base_prefix . 'bp_activity', array( 'date_recorded' => $date_uploaded ), array( 'id' => $activity_id ) ); 
  375.  
  376. return count( $comments ); 
  377.  
  378. return 0; 
  379.  
  380. static function bp_album_deactivate() { 
  381. if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) { 
  382. deactivate_plugins( 'bp-album/loader.php' ); 
  383. die( true );