rtMedia for WordPress, BuddyPress and bbPress - Version 2.5.2

Version Description

  • Fixes warning on admin side.
Download this release

Release Info

Developer saurabhshukla
Plugin Icon 128x128 rtMedia for WordPress, BuddyPress and bbPress
Version 2.5.2
Comparing to
See all releases

Code changes from version 2.5.1 to 2.5.2

Files changed (35) hide show
  1. app/admin/BPMediaAdmin.php +164 -136
  2. app/helper/BPMediaAddon.php +5 -0
  3. app/helper/BPMediaAdminWidget.php +7 -0
  4. app/helper/BPMediaFeed.php +5 -0
  5. app/helper/BPMediaLog.php +71 -50
  6. app/helper/BPMediaSettings.php +69 -15
  7. app/helper/BPMediaSupport.php +9 -0
  8. app/helper/BPMediaUpgrade.php +24 -8
  9. app/helper/rtPluginInfo.php +114 -106
  10. app/helper/rtPluginUpdate.php +121 -89
  11. app/helper/rtPluginUpdateChecker.php +655 -558
  12. app/main/BPMediaLoader.php +112 -96
  13. app/main/BuddyPressMedia.php +35 -7
  14. app/main/group/BPMediaGroup.php +52 -10
  15. app/main/group/BPMediaGroupAction.php +31 -3
  16. app/main/group/BPMediaGroupElementExtension.php +20 -4
  17. app/main/group/BPMediaGroupsExtension.php +35 -4
  18. app/main/group/dummy/BPMediaGroupAlbum.php +10 -7
  19. app/main/includes/BPMediaActions.php +93 -3
  20. app/main/includes/BPMediaComponent.php +353 -339
  21. app/main/includes/BPMediaFilters.php +75 -3
  22. app/main/includes/BPMediaFunction.php +54 -1
  23. app/main/includes/BPMediaHostWordpress.php +194 -28
  24. app/main/includes/BPMediaTemplateFunctions.php +36 -7
  25. app/main/includes/BPMediaUpgradeScript.php +10 -3
  26. app/main/profile/BPMediaAlbum.php +328 -259
  27. app/main/profile/BPMediaAlbumScreen.php +182 -136
  28. app/main/profile/BPMediaScreen.php +440 -398
  29. app/main/profile/BPMediaTemplate.php +241 -206
  30. app/main/profile/BPMediaUploadScreen.php +125 -115
  31. app/main/widgets/BPMediaPopularMedia.php +21 -6
  32. app/main/widgets/BPMediaRecentMedia.php +23 -8
  33. app/main/widgets/BPMediaWidget.php +41 -26
  34. index.php +1 -1
  35. readme.txt +6 -3
app/admin/BPMediaAdmin.php CHANGED
@@ -41,6 +41,11 @@ if (!class_exists('BPMediaAdmin')) {
41
  *
42
  * @param string $hook
43
  */
 
 
 
 
 
44
  public function ui($hook) {
45
  $admin_ajax = admin_url('admin-ajax.php');
46
  wp_enqueue_script('bp-media-admin', BP_MEDIA_URL . 'app/assets/js/admin.js');
@@ -81,6 +86,10 @@ if (!class_exists('BPMediaAdmin')) {
81
  $this->render_page('bp-media-support');
82
  }
83
 
 
 
 
 
84
  static function get_current_tab() {
85
  return isset($_GET['page']) ? $_GET['page'] : "bp-media-settings";
86
  }
@@ -90,6 +99,12 @@ if (!class_exists('BPMediaAdmin')) {
90
  *
91
  * @global string BP_MEDIA_TXT_DOMAIN
92
  */
 
 
 
 
 
 
93
  public function render_page($page, $option_group = NULL) {
94
  ?>
95
 
@@ -99,7 +114,7 @@ if (!class_exists('BPMediaAdmin')) {
99
  <?php settings_errors(); ?>
100
  <div class="columns-2">
101
  <h3 class="bp-media-settings-tabs"><?php
102
- $this->sub_tabs();
103
  ?>
104
  </h3>
105
 
@@ -126,85 +141,90 @@ if (!class_exists('BPMediaAdmin')) {
126
  </div>
127
  </div><!-- .metabox-holder -->
128
  </div><!-- .bp-media-admin --><?php
129
- }
130
-
131
- /**
132
- * Adds a tab for Media settings in the BuddyPress settings page
133
- *
134
- * @global type $bp_media
135
- */
136
- public function tab() {
137
-
138
- $tabs_html = '';
139
- $idle_class = 'nav-tab';
140
- $active_class = 'nav-tab nav-tab-active';
141
- $tabs = array();
142
-
143
- // Check to see which tab we are on
144
- $tab = $this->get_current_tab();
145
- /* BuddyPress Media */
146
- $tabs[] = array(
147
- 'href' => bp_get_admin_url(add_query_arg(array('page' => 'bp-media-settings'), 'admin.php')),
148
- 'title' => __('BuddyPress Media', BP_MEDIA_TXT_DOMAIN),
149
- 'name' => __('BuddyPress Media', BP_MEDIA_TXT_DOMAIN),
150
- 'class' => ($tab == 'bp-media-settings' || $tab == 'bp-media-addons' || $tab == 'bp-media-support') ? $active_class : $idle_class
151
- );
152
-
153
- foreach ($tabs as $tab) {
154
- $tabs_html.= '<a id="bp-media" title= "' . $tab['title'] . '" href="' . $tab['href'] . '" class="' . $tab['class'] . '">' . $tab['name'] . '</a>';
155
- }
156
- echo $tabs_html;
157
- }
158
-
159
- /**
160
- * Adds a sub tabs to the BuddyPress Media settings page
161
- *
162
- * @global type $bp_media
163
- */
164
- public function sub_tabs() {
165
- $tabs_html = '';
166
- $idle_class = 'nav-tab';
167
- $active_class = 'nav-tab nav-tab-active';
168
- $tabs = array();
169
-
170
- // Check to see which tab we are on
171
- $tab = $this->get_current_tab();
172
- /* BuddyPress Media */
173
- $tabs[] = array(
174
- 'href' => bp_get_admin_url(add_query_arg(array('page' => 'bp-media-settings'), 'admin.php')),
175
- 'title' => __('BuddyPress Media Settings', BP_MEDIA_TXT_DOMAIN),
176
- 'name' => __('Settings', BP_MEDIA_TXT_DOMAIN),
177
- 'class' => ($tab == 'bp-media-settings') ? $active_class : $idle_class . ' first_tab'
178
- );
179
-
180
- $tabs[] = array(
181
- 'href' => bp_get_admin_url(add_query_arg(array('page' => 'bp-media-addons'), 'admin.php')),
182
- 'title' => __('BuddyPress Media Addons', BP_MEDIA_TXT_DOMAIN),
183
- 'name' => __('Addons', BP_MEDIA_TXT_DOMAIN),
184
- 'class' => ($tab == 'bp-media-addons') ? $active_class : $idle_class
185
- );
186
-
187
- $tabs[] = array(
188
- 'href' => bp_get_admin_url(add_query_arg(array('page' => 'bp-media-support'), 'admin.php')),
189
- 'title' => __('BuddyPress Media Support', BP_MEDIA_TXT_DOMAIN),
190
- 'name' => __('Support', BP_MEDIA_TXT_DOMAIN),
191
- 'class' => ($tab == 'bp-media-support') ? $active_class : $idle_class . ' last_tab'
192
- );
193
- $tabs = apply_filters('bp_media_add_sub_tabs', $tabs, $tab);
194
- foreach ($tabs as $tab) {
195
- $tabs_html.= '<a title="' . $tab['title'] . '" href="' . $tab['href'] . '" class="' . $tab['class'] . '">' . $tab['name'] . '</a>';
196
- }
197
- echo $tabs_html;
198
- }
199
-
200
- /*
201
- * Updates the media count of all users.
202
- */
203
-
204
- public function update_count() {
205
- global $wpdb;
206
- $query =
207
- "SELECT
 
 
 
 
 
208
  post_author,
209
  SUM(CASE WHEN post_mime_type LIKE 'image%' THEN 1 ELSE 0 END) as Images,
210
  SUM(CASE WHEN post_mime_type LIKE 'audio%' THEN 1 ELSE 0 END) as Audio,
@@ -218,82 +238,90 @@ if (!class_exists('BPMediaAdmin')) {
218
  `meta_value` > 0 AND
219
  ( post_mime_type LIKE 'image%' OR post_mime_type LIKE 'audio%' OR post_mime_type LIKE 'video%' OR post_type LIKE 'bp_media_album')
220
  GROUP BY post_author";
221
- $result = $wpdb->get_results($query);
222
- if (!is_array($result))
223
- return false;
224
-
225
- foreach ($result as $obj) {
226
-
227
- $count = array(
228
- 'images' => isset($obj->Images) ? $obj->Images : 0,
229
- 'videos' => isset($obj->Videos) ? $obj->Videos : 0,
230
- 'audio' => isset($obj->Audio) ? $obj->Audio : 0,
231
- 'albums' => isset($obj->Albums) ? $obj->Albums : 0
232
- );
233
- bp_update_user_meta($obj->post_author, 'bp_media_count', $count);
234
- }
235
- return true;
236
- }
237
-
238
- /* Multisite Save Options - http://wordpress.stackexchange.com/questions/64968/settings-api-in-multisite-missing-update-message#answer-72503 */
239
-
240
- public function save_multisite_options() {
241
- global $bp_media_admin;
242
- if (isset($_POST['refresh-count'])) {
243
- $bp_media_admin->update_count();
244
- }
245
- do_action('bp_media_sanitize_settings', $_POST);
246
-
247
- if (isset($_POST['bp_media_options'])) {
248
- bp_update_option('bp_media_options', $_POST['bp_media_options']);
249
-
250
- // redirect to settings page in network
251
- wp_redirect(
252
- add_query_arg(
253
- array('page' => 'bp-media-settings', 'updated' => 'true'), (is_multisite() ? network_admin_url('admin.php') : admin_url('admin.php'))
254
- )
255
- );
256
- exit;
257
- }
258
- }
259
-
260
- /* Admin Sidebar */
261
-
262
- public function admin_sidebar() {
263
- global $bp_media;
264
- $branding = '<a href="http://rtcamp.com" title="' . __('Empowering The Web With WordPress', BP_MEDIA_TXT_DOMAIN) . '" id="logo"><img src="' . BP_MEDIA_URL . 'app/assets/img/rtcamp-logo.png" alt="' . __('rtCamp', BP_MEDIA_TXT_DOMAIN) . '" /></a>
 
 
 
 
 
 
 
 
265
  <ul id="social">
266
  <li><a href="' . sprintf('%s', 'http://www.facebook.com/rtCamp.solutions/') . '" title="' . __('Become a fan on Facebook', BP_MEDIA_TXT_DOMAIN) . '" class="bp-media-facebook bp-media-social">' . __('Facebook', BP_MEDIA_TXT_DOMAIN) . '</a></li>
267
  <li><a href="' . sprintf('%s', 'https://twitter.com/rtcamp/') . '" title="' . __('Follow us on Twitter', BP_MEDIA_TXT_DOMAIN) . '" class="bp-media-twitter bp-media-social">' . __('Twitter', BP_MEDIA_TXT_DOMAIN) . '</a></li>
268
  <li><a href="' . sprintf('%s', 'http://feeds.feedburner.com/rtcamp/') . '" title="' . __('Subscribe to our feeds', BP_MEDIA_TXT_DOMAIN) . '" class="bp-media-rss bp-media-social">' . __('RSS Feed', BP_MEDIA_TXT_DOMAIN) . '</a></li>
269
  </ul>';
270
- new BPMediaAdminWidget('branding', '', $branding);
271
 
272
- $support = '<p><ul>
273
  <li>' . sprintf('<a href="%s">' . __("Read FAQ", BP_MEDIA_TXT_DOMAIN) . '</a>', 'http://rtcamp.com/buddypress-media/faq/') . '</li>
274
  <li>' . sprintf('<a href="%s">' . __("Free Support Forum", BP_MEDIA_TXT_DOMAIN) . '</a>', $bp_media->support_url) . '</li>
275
  <li>' . sprintf('<a href="%s">' . __("Github Issue Tracker", BP_MEDIA_TXT_DOMAIN) . '</a>', 'https://github.com/rtCamp/buddypress-media/issues/') . '</li>
276
  <li>' . sprintf('<a href="%s">' . __("Hire Us!", BP_MEDIA_TXT_DOMAIN) . '</a> ' . __("To get professional customisation/setup service.", BP_MEDIA_TXT_DOMAIN), 'http://rtcamp.com/buddypress-media/hire/') . '</li>
277
  </ul></p>';
278
- new BPMediaAdminWidget('support', __('Need Help?', BP_MEDIA_TXT_DOMAIN), $support);
279
 
280
- $donate = '<span><a href="http://rtcamp.com/donate/" title="' . __('Help the development keep going.', BP_MEDIA_TXT_DOMAIN) . '"><img class="bp-media-donation-image" src ="' . BP_MEDIA_URL . 'app/assets/img/donate.gif" /></a></span>
281
  <p>' . sprintf(__('Help us release more amazing features faster. Consider making a donation to our consistent efforts.', BP_MEDIA_TXT_DOMAIN)) . '</p>';
282
- new BPMediaAdminWidget('donate', __('Donate', BP_MEDIA_TXT_DOMAIN), $donate);
283
 
284
- $addons = '<ul>
285
  <li><a href="http://rtcamp.com/store/buddypress-media-kaltura/" title="' . __('BuddyPress Media Kaltura', BP_MEDIA_TXT_DOMAIN) . '">' . __('BPM-Kaltura', BP_MEDIA_TXT_DOMAIN) . '</a> - ' . __('Add support for Kaltura.com/Kaltura-CE based video conversion support', BP_MEDIA_TXT_DOMAIN) . '</li>
286
  <li><a href="http://rtcamp.com/store/buddy-press-media-ffmpeg/" title="' . __('BuddyPress Media FFMPEG', BP_MEDIA_TXT_DOMAIN) . '">' . __('BPM-FFMPEG', BP_MEDIA_TXT_DOMAIN) . '</a> - ' . __('Add FFMEG-based audio/video conversion support', BP_MEDIA_TXT_DOMAIN) . '</li>
287
  </ul>
288
  <h4>' . sprintf(__('Are you a developer?', BP_MEDIA_TXT_DOMAIN)) . '</h4>
289
  <p>' . sprintf(__('If you are developing a BuddyPress Media addon we would like to include it in above list. We can also help you sell them. <a href="%s">More info!</a>', BP_MEDIA_TXT_DOMAIN), 'http://rtcamp.com/contact/') . '</p></h4>';
290
- new BPMediaAdminWidget('premium-addons', __('Premium Addons', BP_MEDIA_TXT_DOMAIN), $addons);
291
 
292
- $news = '<img src ="' . admin_url('/images/wpspin_light.gif') . '" /> Loading...';
293
- new BPMediaAdminWidget('latest-news', __('Latest News', BP_MEDIA_TXT_DOMAIN), $news);
294
- }
295
 
296
- }
297
 
298
- }
299
  ?>
41
  *
42
  * @param string $hook
43
  */
44
+
45
+ /**
46
+ *
47
+ * @param type $hook
48
+ */
49
  public function ui($hook) {
50
  $admin_ajax = admin_url('admin-ajax.php');
51
  wp_enqueue_script('bp-media-admin', BP_MEDIA_URL . 'app/assets/js/admin.js');
86
  $this->render_page('bp-media-support');
87
  }
88
 
89
+ /**
90
+ *
91
+ * @return type
92
+ */
93
  static function get_current_tab() {
94
  return isset($_GET['page']) ? $_GET['page'] : "bp-media-settings";
95
  }
99
  *
100
  * @global string BP_MEDIA_TXT_DOMAIN
101
  */
102
+
103
+ /**
104
+ *
105
+ * @param type $page
106
+ * @param type $option_group
107
+ */
108
  public function render_page($page, $option_group = NULL) {
109
  ?>
110
 
114
  <?php settings_errors(); ?>
115
  <div class="columns-2">
116
  <h3 class="bp-media-settings-tabs"><?php
117
+ $this->sub_tabs();
118
  ?>
119
  </h3>
120
 
141
  </div>
142
  </div><!-- .metabox-holder -->
143
  </div><!-- .bp-media-admin --><?php
144
+ }
145
+
146
+ /**
147
+ * Adds a tab for Media settings in the BuddyPress settings page
148
+ *
149
+ * @global type $bp_media
150
+ */
151
+ public function tab() {
152
+
153
+ $tabs_html = '';
154
+ $idle_class = 'nav-tab';
155
+ $active_class = 'nav-tab nav-tab-active';
156
+ $tabs = array();
157
+
158
+ // Check to see which tab we are on
159
+ $tab = $this->get_current_tab();
160
+ /* BuddyPress Media */
161
+ $tabs[] = array(
162
+ 'href' => bp_get_admin_url(add_query_arg(array('page' => 'bp-media-settings'), 'admin.php')),
163
+ 'title' => __('BuddyPress Media', BP_MEDIA_TXT_DOMAIN),
164
+ 'name' => __('BuddyPress Media', BP_MEDIA_TXT_DOMAIN),
165
+ 'class' => ($tab == 'bp-media-settings' || $tab == 'bp-media-addons' || $tab == 'bp-media-support') ? $active_class : $idle_class
166
+ );
167
+
168
+ foreach ($tabs as $tab) {
169
+ $tabs_html.= '<a id="bp-media" title= "' . $tab['title'] . '" href="' . $tab['href'] . '" class="' . $tab['class'] . '">' . $tab['name'] . '</a>';
170
+ }
171
+ echo $tabs_html;
172
+ }
173
+
174
+ /**
175
+ * Adds a sub tabs to the BuddyPress Media settings page
176
+ *
177
+ * @global type $bp_media
178
+ */
179
+ public function sub_tabs() {
180
+ $tabs_html = '';
181
+ $idle_class = 'nav-tab';
182
+ $active_class = 'nav-tab nav-tab-active';
183
+ $tabs = array();
184
+
185
+ // Check to see which tab we are on
186
+ $tab = $this->get_current_tab();
187
+ /* BuddyPress Media */
188
+ $tabs[] = array(
189
+ 'href' => bp_get_admin_url(add_query_arg(array('page' => 'bp-media-settings'), 'admin.php')),
190
+ 'title' => __('BuddyPress Media Settings', BP_MEDIA_TXT_DOMAIN),
191
+ 'name' => __('Settings', BP_MEDIA_TXT_DOMAIN),
192
+ 'class' => ($tab == 'bp-media-settings') ? $active_class : $idle_class . ' first_tab'
193
+ );
194
+
195
+ $tabs[] = array(
196
+ 'href' => bp_get_admin_url(add_query_arg(array('page' => 'bp-media-addons'), 'admin.php')),
197
+ 'title' => __('BuddyPress Media Addons', BP_MEDIA_TXT_DOMAIN),
198
+ 'name' => __('Addons', BP_MEDIA_TXT_DOMAIN),
199
+ 'class' => ($tab == 'bp-media-addons') ? $active_class : $idle_class
200
+ );
201
+
202
+ $tabs[] = array(
203
+ 'href' => bp_get_admin_url(add_query_arg(array('page' => 'bp-media-support'), 'admin.php')),
204
+ 'title' => __('BuddyPress Media Support', BP_MEDIA_TXT_DOMAIN),
205
+ 'name' => __('Support', BP_MEDIA_TXT_DOMAIN),
206
+ 'class' => ($tab == 'bp-media-support') ? $active_class : $idle_class . ' last_tab'
207
+ );
208
+ $tabs = apply_filters('bp_media_add_sub_tabs', $tabs, $tab);
209
+ foreach ($tabs as $tab) {
210
+ $tabs_html.= '<a title="' . $tab['title'] . '" href="' . $tab['href'] . '" class="' . $tab['class'] . '">' . $tab['name'] . '</a>';
211
+ }
212
+ echo $tabs_html;
213
+ }
214
+
215
+ /*
216
+ * Updates the media count of all users.
217
+ */
218
+
219
+ /**
220
+ *
221
+ * @global type $wpdb
222
+ * @return boolean
223
+ */
224
+ public function update_count() {
225
+ global $wpdb;
226
+ $query =
227
+ "SELECT
228
  post_author,
229
  SUM(CASE WHEN post_mime_type LIKE 'image%' THEN 1 ELSE 0 END) as Images,
230
  SUM(CASE WHEN post_mime_type LIKE 'audio%' THEN 1 ELSE 0 END) as Audio,
238
  `meta_value` > 0 AND
239
  ( post_mime_type LIKE 'image%' OR post_mime_type LIKE 'audio%' OR post_mime_type LIKE 'video%' OR post_type LIKE 'bp_media_album')
240
  GROUP BY post_author";
241
+ $result = $wpdb->get_results($query);
242
+ if (!is_array($result))
243
+ return false;
244
+
245
+ foreach ($result as $obj) {
246
+
247
+ $count = array(
248
+ 'images' => isset($obj->Images) ? $obj->Images : 0,
249
+ 'videos' => isset($obj->Videos) ? $obj->Videos : 0,
250
+ 'audio' => isset($obj->Audio) ? $obj->Audio : 0,
251
+ 'albums' => isset($obj->Albums) ? $obj->Albums : 0
252
+ );
253
+ bp_update_user_meta($obj->post_author, 'bp_media_count', $count);
254
+ }
255
+ return true;
256
+ }
257
+
258
+ /* Multisite Save Options - http://wordpress.stackexchange.com/questions/64968/settings-api-in-multisite-missing-update-message#answer-72503 */
259
+
260
+ /**
261
+ *
262
+ * @global type $bp_media_admin
263
+ */
264
+ public function save_multisite_options() {
265
+ global $bp_media_admin;
266
+ if (isset($_POST['refresh-count'])) {
267
+ $bp_media_admin->update_count();
268
+ }
269
+ do_action('bp_media_sanitize_settings', $_POST);
270
+
271
+ if (isset($_POST['bp_media_options'])) {
272
+ bp_update_option('bp_media_options', $_POST['bp_media_options']);
273
+
274
+ // redirect to settings page in network
275
+ wp_redirect(
276
+ add_query_arg(
277
+ array('page' => 'bp-media-settings', 'updated' => 'true'), (is_multisite() ? network_admin_url('admin.php') : admin_url('admin.php'))
278
+ )
279
+ );
280
+ exit;
281
+ }
282
+ }
283
+
284
+ /* Admin Sidebar */
285
+
286
+ /**
287
+ *
288
+ * @global type $bp_media
289
+ */
290
+ public function admin_sidebar() {
291
+ global $bp_media;
292
+ $branding = '<a href="http://rtcamp.com" title="' . __('Empowering The Web With WordPress', BP_MEDIA_TXT_DOMAIN) . '" id="logo"><img src="' . BP_MEDIA_URL . 'app/assets/img/rtcamp-logo.png" alt="' . __('rtCamp', BP_MEDIA_TXT_DOMAIN) . '" /></a>
293
  <ul id="social">
294
  <li><a href="' . sprintf('%s', 'http://www.facebook.com/rtCamp.solutions/') . '" title="' . __('Become a fan on Facebook', BP_MEDIA_TXT_DOMAIN) . '" class="bp-media-facebook bp-media-social">' . __('Facebook', BP_MEDIA_TXT_DOMAIN) . '</a></li>
295
  <li><a href="' . sprintf('%s', 'https://twitter.com/rtcamp/') . '" title="' . __('Follow us on Twitter', BP_MEDIA_TXT_DOMAIN) . '" class="bp-media-twitter bp-media-social">' . __('Twitter', BP_MEDIA_TXT_DOMAIN) . '</a></li>
296
  <li><a href="' . sprintf('%s', 'http://feeds.feedburner.com/rtcamp/') . '" title="' . __('Subscribe to our feeds', BP_MEDIA_TXT_DOMAIN) . '" class="bp-media-rss bp-media-social">' . __('RSS Feed', BP_MEDIA_TXT_DOMAIN) . '</a></li>
297
  </ul>';
298
+ new BPMediaAdminWidget('branding', '', $branding);
299
 
300
+ $support = '<p><ul>
301
  <li>' . sprintf('<a href="%s">' . __("Read FAQ", BP_MEDIA_TXT_DOMAIN) . '</a>', 'http://rtcamp.com/buddypress-media/faq/') . '</li>
302
  <li>' . sprintf('<a href="%s">' . __("Free Support Forum", BP_MEDIA_TXT_DOMAIN) . '</a>', $bp_media->support_url) . '</li>
303
  <li>' . sprintf('<a href="%s">' . __("Github Issue Tracker", BP_MEDIA_TXT_DOMAIN) . '</a>', 'https://github.com/rtCamp/buddypress-media/issues/') . '</li>
304
  <li>' . sprintf('<a href="%s">' . __("Hire Us!", BP_MEDIA_TXT_DOMAIN) . '</a> ' . __("To get professional customisation/setup service.", BP_MEDIA_TXT_DOMAIN), 'http://rtcamp.com/buddypress-media/hire/') . '</li>
305
  </ul></p>';
306
+ new BPMediaAdminWidget('support', __('Need Help?', BP_MEDIA_TXT_DOMAIN), $support);
307
 
308
+ $donate = '<span><a href="http://rtcamp.com/donate/" title="' . __('Help the development keep going.', BP_MEDIA_TXT_DOMAIN) . '"><img class="bp-media-donation-image" src ="' . BP_MEDIA_URL . 'app/assets/img/donate.gif" /></a></span>
309
  <p>' . sprintf(__('Help us release more amazing features faster. Consider making a donation to our consistent efforts.', BP_MEDIA_TXT_DOMAIN)) . '</p>';
310
+ new BPMediaAdminWidget('donate', __('Donate', BP_MEDIA_TXT_DOMAIN), $donate);
311
 
312
+ $addons = '<ul>
313
  <li><a href="http://rtcamp.com/store/buddypress-media-kaltura/" title="' . __('BuddyPress Media Kaltura', BP_MEDIA_TXT_DOMAIN) . '">' . __('BPM-Kaltura', BP_MEDIA_TXT_DOMAIN) . '</a> - ' . __('Add support for Kaltura.com/Kaltura-CE based video conversion support', BP_MEDIA_TXT_DOMAIN) . '</li>
314
  <li><a href="http://rtcamp.com/store/buddy-press-media-ffmpeg/" title="' . __('BuddyPress Media FFMPEG', BP_MEDIA_TXT_DOMAIN) . '">' . __('BPM-FFMPEG', BP_MEDIA_TXT_DOMAIN) . '</a> - ' . __('Add FFMEG-based audio/video conversion support', BP_MEDIA_TXT_DOMAIN) . '</li>
315
  </ul>
316
  <h4>' . sprintf(__('Are you a developer?', BP_MEDIA_TXT_DOMAIN)) . '</h4>
317
  <p>' . sprintf(__('If you are developing a BuddyPress Media addon we would like to include it in above list. We can also help you sell them. <a href="%s">More info!</a>', BP_MEDIA_TXT_DOMAIN), 'http://rtcamp.com/contact/') . '</p></h4>';
318
+ new BPMediaAdminWidget('premium-addons', __('Premium Addons', BP_MEDIA_TXT_DOMAIN), $addons);
319
 
320
+ $news = '<img src ="' . admin_url('/images/wpspin_light.gif') . '" /> Loading...';
321
+ new BPMediaAdminWidget('latest-news', __('Latest News', BP_MEDIA_TXT_DOMAIN), $news);
322
+ }
323
 
324
+ }
325
 
326
+ }
327
  ?>
app/helper/BPMediaAddon.php CHANGED
@@ -52,6 +52,11 @@ if (!class_exists('BPMediaAddon')) {
52
  }
53
  }
54
 
 
 
 
 
 
55
  public function addon($args) {
56
  global $bp_media;
57
 
52
  }
53
  }
54
 
55
+ /**
56
+ *
57
+ * @global type $bp_media
58
+ * @param type $args
59
+ */
60
  public function addon($args) {
61
  global $bp_media;
62
 
app/helper/BPMediaAdminWidget.php CHANGED
@@ -9,6 +9,13 @@ if (!class_exists('BPMediaAdminWidget')) {
9
 
10
  class BPMediaAdminWidget {
11
 
 
 
 
 
 
 
 
12
  public function __construct($id = NULL, $title = NULL, $content = NULL) {
13
  global $bp_media;
14
  if ($id) {
9
 
10
  class BPMediaAdminWidget {
11
 
12
+ /**
13
+ *
14
+ * @global type $bp_media
15
+ * @param type $id
16
+ * @param type $title
17
+ * @param type $content
18
+ */
19
  public function __construct($id = NULL, $title = NULL, $content = NULL) {
20
  global $bp_media;
21
  if ($id) {
app/helper/BPMediaFeed.php CHANGED
@@ -18,6 +18,11 @@ class BPMediaFeed {
18
  /**
19
  * Get BuddyPress Media Feed from rtCamp.com
20
  */
 
 
 
 
 
21
  public function fetch_feed() {
22
  global $bp_media;
23
  // Get RSS Feed(s)
18
  /**
19
  * Get BuddyPress Media Feed from rtCamp.com
20
  */
21
+
22
+ /**
23
+ *
24
+ * @global type $bp_media
25
+ */
26
  public function fetch_feed() {
27
  global $bp_media;
28
  // Get RSS Feed(s)
app/helper/BPMediaLog.php CHANGED
@@ -5,61 +5,82 @@
5
  *
6
  * @author Saurabh Shukla <saurabh.shukla@rtcamp.com>
7
  */
8
- if ( ! class_exists( 'BPMediaLog' ) ) {
9
 
10
- class BPMediaLog {
 
 
 
 
 
 
 
11
 
12
- /**
13
- * Formats and logs the error message
14
- *
15
- * @param any $msg The message to log
16
- * @param string $context The context string, optional
17
- * @return boolean True if successful
18
- */
19
- public function __construct( $msg, $context = '', $log_file = '' ) {
20
- $log_msg = $this->log_msg( $msg, $context = '' );
21
- if ($log_file == ''){
22
- $log_file = BP_MEDIA_PATH.'log/bpmedia.log';
23
- }
24
- return $this->log( $log_msg, $log_file );
25
- }
26
 
27
- /**
28
- * Formats the message
29
- *
30
- * @param any $msg The message to format
31
- * @param string $context The context string, optional
32
- * @return string The formatted log entry
33
- */
34
- function log_msg( $msg, $context = '' ) {
35
- $logmsg = gmdate( "Y-m-d H:i:s " ) . " | ";
36
- if ( $context ) {
37
- $logmsg .= $context . " | ";
38
- }
39
- if ( ! is_string( $msg ) ) {
40
- $msg = var_export( $msg, false );
41
- }
42
- $logmsg .= $msg;
43
- return $logmsg;
44
- }
45
 
46
- /**
47
- * Logs the entry to the log file
48
- *
49
- * @param string $logmsg The formatted log entry
50
- * @param string $file The log file's path
51
- * @return boolean Success
52
- */
53
- public function log( $logmsg, $file ) {
54
- $fp = fopen( BP_MEDIA_PATH . 'plugin.log', "a+" );
55
- if ( $fp ) {
56
- fwrite( $fp, "\n" . $logmsg );
57
- fclose( $fp );
58
- }
59
- return true;
60
- }
 
 
61
 
62
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  }
65
  ?>
5
  *
6
  * @author Saurabh Shukla <saurabh.shukla@rtcamp.com>
7
  */
8
+ if (!class_exists('BPMediaLog')) {
9
 
10
+ class BPMediaLog {
11
+ /**
12
+ * Formats and logs the error message
13
+ *
14
+ * @param any $msg The message to log
15
+ * @param string $context The context string, optional
16
+ * @return boolean True if successful
17
+ */
18
 
19
+ /**
20
+ *
21
+ * @param type $msg
22
+ * @param string $context
23
+ * @param string $log_file
24
+ * @return type
25
+ */
26
+ public function __construct($msg, $context = '', $log_file = '') {
27
+ $log_msg = $this->log_msg($msg, $context = '');
28
+ if ($log_file == '') {
29
+ $log_file = BP_MEDIA_PATH . 'log/bpmedia.log';
30
+ }
31
+ return $this->log($log_msg, $log_file);
32
+ }
33
 
34
+ /**
35
+ * Formats the message
36
+ *
37
+ * @param any $msg The message to format
38
+ * @param string $context The context string, optional
39
+ * @return string The formatted log entry
40
+ */
 
 
 
 
 
 
 
 
 
 
 
41
 
42
+ /**
43
+ *
44
+ * @param type $msg
45
+ * @param type $context
46
+ * @return type
47
+ */
48
+ function log_msg($msg, $context = '') {
49
+ $logmsg = gmdate("Y-m-d H:i:s ") . " | ";
50
+ if ($context) {
51
+ $logmsg .= $context . " | ";
52
+ }
53
+ if (!is_string($msg)) {
54
+ $msg = var_export($msg, false);
55
+ }
56
+ $logmsg .= $msg;
57
+ return $logmsg;
58
+ }
59
 
60
+ /**
61
+ * Logs the entry to the log file
62
+ *
63
+ * @param string $logmsg The formatted log entry
64
+ * @param string $file The log file's path
65
+ * @return boolean Success
66
+ */
67
+
68
+ /**
69
+ *
70
+ * @param type $logmsg
71
+ * @param type $file
72
+ * @return boolean
73
+ */
74
+ public function log($logmsg, $file) {
75
+ $fp = fopen(BP_MEDIA_PATH . 'plugin.log', "a+");
76
+ if ($fp) {
77
+ fwrite($fp, "\n" . $logmsg);
78
+ fclose($fp);
79
+ }
80
+ return true;
81
+ }
82
+
83
+ }
84
 
85
  }
86
  ?>
app/helper/BPMediaSettings.php CHANGED
@@ -15,9 +15,14 @@ if (!class_exists('BPMediaSettings')) {
15
 
16
  /**
17
  * Register Settings
18
- *
19
  * @global string BP_MEDIA_TXT_DOMAIN
20
  */
 
 
 
 
 
21
  public function settings() {
22
  global $bp_media_addon;
23
  add_settings_section('bpm-settings', __('BuddyPress Media Settings', BP_MEDIA_TXT_DOMAIN), is_multisite() ? array($this, 'network_notices') : '', 'bp-media-settings');
@@ -56,6 +61,15 @@ if (!class_exists('BPMediaSettings')) {
56
  'name' => __('Re-Count', BP_MEDIA_TXT_DOMAIN),
57
  'desc' => __('It will re-count all media entries of all users and correct any discrepancies.', BP_MEDIA_TXT_DOMAIN)
58
  ));
 
 
 
 
 
 
 
 
 
59
  $bp_media_addon = new BPMediaAddon();
60
  add_settings_section('bpm-addons', __('BuddyPress Media Addons for Audio/Video Conversion', BP_MEDIA_TXT_DOMAIN), array($bp_media_addon, 'get_addons'), 'bp-media-addons');
61
  add_settings_section('bpm-support', __('Submit a request form', BP_MEDIA_TXT_DOMAIN), '', 'bp-media-support');
@@ -84,6 +98,13 @@ if (!class_exists('BPMediaSettings')) {
84
  /**
85
  * Sanitizes the settings
86
  */
 
 
 
 
 
 
 
87
  public function sanitize($input) {
88
  global $bp_media_admin;
89
  if (isset($_POST['refresh-count'])) {
@@ -107,10 +128,17 @@ if (!class_exists('BPMediaSettings')) {
107
 
108
  /**
109
  * Output a checkbox
110
- *
111
  * @global array $bp_media
112
  * @param array $args
113
  */
 
 
 
 
 
 
 
114
  public function checkbox($args) {
115
  global $bp_media;
116
  $options = $bp_media->options;
@@ -137,16 +165,23 @@ if (!class_exists('BPMediaSettings')) {
137
  ?>
138
  <label for="<?php echo $option; ?>">
139
  <input<?php checked($options[$option]); ?> name="<?php echo $name; ?>" id="<?php echo $option; ?>" value="1" type="checkbox" />
140
- <?php echo $desc; ?>
141
  </label><?php
142
  }
143
 
144
  /**
145
  * Outputs Radio Buttons
146
- *
147
  * @global array $bp_media
148
  * @param array $args
149
  */
 
 
 
 
 
 
 
150
  public function radio($args) {
151
  global $bp_media;
152
  $options = $bp_media->options;
@@ -177,17 +212,24 @@ if (!class_exists('BPMediaSettings')) {
177
  }
178
 
179
  foreach ($radios as $value => $desc) {
180
- ?>
181
  <label for="<?php echo sanitize_title($desc); ?>"><input<?php checked($options[$option], $value); ?> value="<?php echo $value; ?>" name="<?php echo $name; ?>" id="<?php echo sanitize_title($desc); ?>" type="radio" /><?php echo $desc; ?></label><br /><?php
182
  }
183
  }
184
 
185
  /**
186
  * Outputs Textbox
187
- *
188
  * @global array $bp_media
189
  * @param array $args
190
  */
 
 
 
 
 
 
 
191
  public function textbox($args) {
192
  global $bp_media;
193
  $options = $bp_media->options;
@@ -213,20 +255,26 @@ if (!class_exists('BPMediaSettings')) {
213
  if ((isset($options[$option]) && empty($options[$option])) || !isset($options[$option])) {
214
  $options[$option] = '';
215
  }
216
- ?>
217
  <label for="<?php echo sanitize_title($option); ?>"><input value="<?php echo $options[$option]; ?>" name="<?php echo $name; ?>" id="<?php echo sanitize_title($option); ?>" type="<?php echo $password ? 'password' : 'text'; ?>" /><?php
218
  if (!empty($desc)) {
219
  echo '<br /><span class="description">' . $desc . '</span>';
220
  }
221
- ?></label><br /><?php
222
  }
223
 
224
  /**
225
  * Outputs Dropdown
226
- *
227
  * @global array $bp_media
228
  * @param array $args
229
  */
 
 
 
 
 
 
230
  public function dropdown($args) {
231
  $defaults = array(
232
  'setting' => '',
@@ -253,23 +301,29 @@ if (!class_exists('BPMediaSettings')) {
253
  if ((isset($options[$option]) && empty($options[$option])) || !isset($options[$option])) {
254
  $options[$option] = '';
255
  }
256
- ?>
257
  <select name="<?php echo $name; ?>" id="<?php echo $option; ?>"><?php if ($none) { ?>
258
  <option><?php __e('None', BP_MEDIA_TXT_DOMAIN); ?></option><?php
259
  }
260
  foreach ($values as $value => $text) {
261
- ?>
262
- <option<?php selected($options[$option], $value); ?> value="<?php echo $value; ?>"><?php echo $text; ?></option><?php }
263
  ?>
 
 
264
  </select><?php
265
  }
266
 
267
  /**
268
  * Outputs a Button
269
- *
270
  * @global array $bp_media
271
  * @param array $args
272
  */
 
 
 
 
 
 
273
  public function button($args) {
274
  $defaults = array(
275
  'setting' => '',
@@ -289,7 +343,7 @@ if (!class_exists('BPMediaSettings')) {
289
  $button = $option;
290
  submit_button($name, '', $button, false);
291
  if (!empty($desc)) {
292
- ?>
293
  <span class="description"><?php echo $desc; ?></a><?php
294
  }
295
  }
@@ -297,4 +351,4 @@ if (!class_exists('BPMediaSettings')) {
297
  }
298
 
299
  }
300
- ?>
15
 
16
  /**
17
  * Register Settings
18
+ *
19
  * @global string BP_MEDIA_TXT_DOMAIN
20
  */
21
+
22
+ /**
23
+ *
24
+ * @global BPMediaAddon $bp_media_addon
25
+ */
26
  public function settings() {
27
  global $bp_media_addon;
28
  add_settings_section('bpm-settings', __('BuddyPress Media Settings', BP_MEDIA_TXT_DOMAIN), is_multisite() ? array($this, 'network_notices') : '', 'bp-media-settings');
61
  'name' => __('Re-Count', BP_MEDIA_TXT_DOMAIN),
62
  'desc' => __('It will re-count all media entries of all users and correct any discrepancies.', BP_MEDIA_TXT_DOMAIN)
63
  ));
64
+ /*add_settings_section('bpm-admin-bar-menu', __('Admin Bar Menu', BP_MEDIA_TXT_DOMAIN), '', 'bp-media-settings');
65
+ add_settings_field('bpm-admin-bar-menu', __('Spread the Word', BP_MEDIA_TXT_DOMAIN), array($this, 'radio'), 'bp-media-settings', 'bpm-spread-the-word', array(
66
+ 'setting' => 'bp_media_options',
67
+ 'option' => 'remove_linkback',
68
+ 'radios' => array(
69
+ 2 => __('Yes, I support BuddyPress Media', BP_MEDIA_TXT_DOMAIN),
70
+ 1 => __('No, I don\'t want to support BuddyPress Media', BP_MEDIA_TXT_DOMAIN)),
71
+ 'default' => 2)
72
+ );*/
73
  $bp_media_addon = new BPMediaAddon();
74
  add_settings_section('bpm-addons', __('BuddyPress Media Addons for Audio/Video Conversion', BP_MEDIA_TXT_DOMAIN), array($bp_media_addon, 'get_addons'), 'bp-media-addons');
75
  add_settings_section('bpm-support', __('Submit a request form', BP_MEDIA_TXT_DOMAIN), '', 'bp-media-support');
98
  /**
99
  * Sanitizes the settings
100
  */
101
+
102
+ /**
103
+ *
104
+ * @global type $bp_media_admin
105
+ * @param type $input
106
+ * @return type
107
+ */
108
  public function sanitize($input) {
109
  global $bp_media_admin;
110
  if (isset($_POST['refresh-count'])) {
128
 
129
  /**
130
  * Output a checkbox
131
+ *
132
  * @global array $bp_media
133
  * @param array $args
134
  */
135
+
136
+ /**
137
+ *
138
+ * @global array $bp_media
139
+ * @param type $args
140
+ * @return type
141
+ */
142
  public function checkbox($args) {
143
  global $bp_media;
144
  $options = $bp_media->options;
165
  ?>
166
  <label for="<?php echo $option; ?>">
167
  <input<?php checked($options[$option]); ?> name="<?php echo $name; ?>" id="<?php echo $option; ?>" value="1" type="checkbox" />
168
+ <?php echo $desc; ?>
169
  </label><?php
170
  }
171
 
172
  /**
173
  * Outputs Radio Buttons
174
+ *
175
  * @global array $bp_media
176
  * @param array $args
177
  */
178
+
179
+ /**
180
+ *
181
+ * @global array $bp_media
182
+ * @param type $args
183
+ * @return type
184
+ */
185
  public function radio($args) {
186
  global $bp_media;
187
  $options = $bp_media->options;
212
  }
213
 
214
  foreach ($radios as $value => $desc) {
215
+ ?>
216
  <label for="<?php echo sanitize_title($desc); ?>"><input<?php checked($options[$option], $value); ?> value="<?php echo $value; ?>" name="<?php echo $name; ?>" id="<?php echo sanitize_title($desc); ?>" type="radio" /><?php echo $desc; ?></label><br /><?php
217
  }
218
  }
219
 
220
  /**
221
  * Outputs Textbox
222
+ *
223
  * @global array $bp_media
224
  * @param array $args
225
  */
226
+
227
+ /**
228
+ *
229
+ * @global array $bp_media
230
+ * @param type $args
231
+ * @return type
232
+ */
233
  public function textbox($args) {
234
  global $bp_media;
235
  $options = $bp_media->options;
255
  if ((isset($options[$option]) && empty($options[$option])) || !isset($options[$option])) {
256
  $options[$option] = '';
257
  }
258
+ ?>
259
  <label for="<?php echo sanitize_title($option); ?>"><input value="<?php echo $options[$option]; ?>" name="<?php echo $name; ?>" id="<?php echo sanitize_title($option); ?>" type="<?php echo $password ? 'password' : 'text'; ?>" /><?php
260
  if (!empty($desc)) {
261
  echo '<br /><span class="description">' . $desc . '</span>';
262
  }
263
+ ?></label><br /><?php
264
  }
265
 
266
  /**
267
  * Outputs Dropdown
268
+ *
269
  * @global array $bp_media
270
  * @param array $args
271
  */
272
+
273
+ /**
274
+ *
275
+ * @param type $args
276
+ * @return type
277
+ */
278
  public function dropdown($args) {
279
  $defaults = array(
280
  'setting' => '',
301
  if ((isset($options[$option]) && empty($options[$option])) || !isset($options[$option])) {
302
  $options[$option] = '';
303
  }
304
+ ?>
305
  <select name="<?php echo $name; ?>" id="<?php echo $option; ?>"><?php if ($none) { ?>
306
  <option><?php __e('None', BP_MEDIA_TXT_DOMAIN); ?></option><?php
307
  }
308
  foreach ($values as $value => $text) {
 
 
309
  ?>
310
+ <option<?php selected($options[$option], $value); ?> value="<?php echo $value; ?>"><?php echo $text; ?></option><?php }
311
+ ?>
312
  </select><?php
313
  }
314
 
315
  /**
316
  * Outputs a Button
317
+ *
318
  * @global array $bp_media
319
  * @param array $args
320
  */
321
+
322
+ /**
323
+ *
324
+ * @param type $args
325
+ * @return type
326
+ */
327
  public function button($args) {
328
  $defaults = array(
329
  'setting' => '',
343
  $button = $option;
344
  submit_button($name, '', $button, false);
345
  if (!empty($desc)) {
346
+ ?>
347
  <span class="description"><?php echo $desc; ?></a><?php
348
  }
349
  }
351
  }
352
 
353
  }
354
+ ?>
app/helper/BPMediaSupport.php CHANGED
@@ -13,6 +13,11 @@ if (!class_exists('BPMediaSupport')) {
13
  ;
14
  }
15
 
 
 
 
 
 
16
  public function get_form($form) {
17
  if (empty($form))
18
  $form = (isset($_POST['form'])) ? $_POST['form'] : '';
@@ -91,6 +96,10 @@ if (!class_exists('BPMediaSupport')) {
91
  }
92
  }
93
 
 
 
 
 
94
  public function submit_request() {
95
  global $bp_media;
96
  $form_data = wp_parse_args($_POST['form_data']);
13
  ;
14
  }
15
 
16
+ /**
17
+ *
18
+ * @global type $current_user
19
+ * @param type $form
20
+ */
21
  public function get_form($form) {
22
  if (empty($form))
23
  $form = (isset($_POST['form'])) ? $_POST['form'] : '';
96
  }
97
  }
98
 
99
+ /**
100
+ *
101
+ * @global type $bp_media
102
+ */
103
  public function submit_request() {
104
  global $bp_media;
105
  $form_data = wp_parse_args($_POST['form_data']);
app/helper/BPMediaUpgrade.php CHANGED
@@ -23,6 +23,11 @@ if (!class_exists('BPMediaUpgrade')) {
23
  *
24
  * @global string BP_MEDIA_TXT_DOMAIN
25
  */
 
 
 
 
 
26
  public function upgrade_db() {
27
  global $bp_media;
28
  ?>
@@ -53,9 +58,15 @@ if (!class_exists('BPMediaUpgrade')) {
53
  * @global wpdb $wpdb
54
  * @global string BP_MEDIA_TXT_DOMAIN
55
  */
 
 
 
 
 
 
56
  public function upgrade_1_0_to_2_1() {
57
  global $wpdb, $bp_media;
58
- $post_wall =__( 'Wall Posts', BP_MEDIA_TXT_DOMAIN );
59
  remove_filter('bp_activity_get_user_join_filter', 'BPMediaFilters::activity_query_filter', 10);
60
  /* @var $wpdb wpdb */
61
  $wall_posts_album_ids = array();
@@ -124,17 +135,22 @@ if (!class_exists('BPMediaUpgrade')) {
124
  *
125
  * @global string BP_MEDIA_TXT_DOMAIN
126
  */
 
 
 
 
 
127
  public function upgrade_2_0_to_2_1() {
128
  global $bp_media;
129
  $page = 0;
130
  while ($media_entries = BPMediaUpgradeScript::return_query_posts(array(
131
- 'post_type' => 'attachment',
132
- 'post_status' => 'any',
133
- 'meta_key' => 'bp-media-key',
134
- 'meta_value' => 0,
135
- 'meta_compare' => '>',
136
- 'paged' => ++$page,
137
- 'postsperpage' => 10
138
  ))) {
139
  foreach ($media_entries as $media) {
140
  try {
23
  *
24
  * @global string BP_MEDIA_TXT_DOMAIN
25
  */
26
+
27
+ /**
28
+ *
29
+ * @global type $bp_media
30
+ */
31
  public function upgrade_db() {
32
  global $bp_media;
33
  ?>
58
  * @global wpdb $wpdb
59
  * @global string BP_MEDIA_TXT_DOMAIN
60
  */
61
+
62
+ /**
63
+ *
64
+ * @global wpdb $wpdb
65
+ * @global type $bp_media
66
+ */
67
  public function upgrade_1_0_to_2_1() {
68
  global $wpdb, $bp_media;
69
+ $post_wall = __('Wall Posts', BP_MEDIA_TXT_DOMAIN);
70
  remove_filter('bp_activity_get_user_join_filter', 'BPMediaFilters::activity_query_filter', 10);
71
  /* @var $wpdb wpdb */
72
  $wall_posts_album_ids = array();
135
  *
136
  * @global string BP_MEDIA_TXT_DOMAIN
137
  */
138
+
139
+ /**
140
+ *
141
+ * @global type $bp_media
142
+ */
143
  public function upgrade_2_0_to_2_1() {
144
  global $bp_media;
145
  $page = 0;
146
  while ($media_entries = BPMediaUpgradeScript::return_query_posts(array(
147
+ 'post_type' => 'attachment',
148
+ 'post_status' => 'any',
149
+ 'meta_key' => 'bp-media-key',
150
+ 'meta_value' => 0,
151
+ 'meta_compare' => '>',
152
+ 'paged' => ++$page,
153
+ 'postsperpage' => 10
154
  ))) {
155
  foreach ($media_entries as $media) {
156
  try {
app/helper/rtPluginInfo.php CHANGED
@@ -1,116 +1,124 @@
1
  <?php
 
2
  /**
3
  * A container class for holding and transforming various plugin metadata.
4
  *
5
  * @author faishal
6
  */
7
  class rtPluginInfo {
8
- //Most fields map directly to the contents of the plugin's info.json file.
9
- //See the relevant docs for a description of their meaning.
10
- public $name;
11
- public $slug;
12
- public $version;
13
- public $homepage;
14
- public $sections;
15
- public $download_url;
16
-
17
- public $author;
18
- public $author_homepage;
19
-
20
- public $requires;
21
- public $tested;
22
- public $upgrade_notice;
23
-
24
- public $rating;
25
- public $num_ratings;
26
- public $downloaded;
27
- public $last_updated;
28
-
29
- public $id = 0; //The native WP.org API returns numeric plugin IDs, but they're not used for anything.
30
-
31
- /**
32
- * Create a new instance of PluginInfo from JSON-encoded plugin info
33
- * returned by an external update API.
34
- *
35
- * @param string $json Valid JSON string representing plugin info.
36
- * @param bool $triggerErrors
37
- * @return PluginInfo|null New instance of PluginInfo, or NULL on error.
38
- */
39
- public static function fromJson($json, $triggerErrors = false){
40
- /** @var StdClass $apiResponse */
41
- $apiResponse = json_decode($json);
42
- if ( empty($apiResponse) || !is_object($apiResponse) ){
43
- if ( $triggerErrors ) {
44
- trigger_error(
45
- "Failed to parse plugin metadata. Try validating your .json file with http://jsonlint.com/",
46
- E_USER_NOTICE
47
- );
48
- }
49
- return null;
50
- }
51
-
52
- //Very, very basic validation.
53
- $valid = isset($apiResponse->name) && !empty($apiResponse->name) && isset($apiResponse->version) && !empty($apiResponse->version);
54
- if ( !$valid ){
55
- if ( $triggerErrors ) {
56
- trigger_error(
57
- "The plugin metadata file does not contain the required 'name' and/or 'version' keys.",
58
- E_USER_NOTICE
59
- );
60
- }
61
- return null;
62
- }
63
-
64
- $info = new self();
65
- foreach(get_object_vars($apiResponse) as $key => $value){
66
- $info->$key = $value;
67
- }
68
-
69
- return $info;
70
- }
71
-
72
- /**
73
- * Transform plugin info into the format used by the native WordPress.org API
74
- *
75
- * @return object
76
- */
77
- public function toWpFormat(){
78
- $info = new StdClass;
79
-
80
- //The custom update API is built so that many fields have the same name and format
81
- //as those returned by the native WordPress.org API. These can be assigned directly.
82
- $sameFormat = array(
83
- 'name', 'slug', 'version', 'requires', 'tested', 'rating', 'upgrade_notice',
84
- 'num_ratings', 'downloaded', 'homepage', 'last_updated',
85
- );
86
- foreach($sameFormat as $field){
87
- if ( isset($this->$field) ) {
88
- $info->$field = $this->$field;
89
- } else {
90
- $info->$field = null;
91
- }
92
- }
93
-
94
- //Other fields need to be renamed and/or transformed.
95
- $info->download_link = $this->download_url;
96
-
97
- if ( !empty($this->author_homepage) ){
98
- $info->author = sprintf('<a href="%s">%s</a>', $this->author_homepage, $this->author);
99
- } else {
100
- $info->author = $this->author;
101
- }
102
-
103
- if ( is_object($this->sections) ){
104
- $info->sections = get_object_vars($this->sections);
105
- } elseif ( is_array($this->sections) ) {
106
- $info->sections = $this->sections;
107
- } else {
108
- $info->sections = array('description' => '');
109
- }
110
-
111
- return $info;
112
- }
 
 
 
 
 
 
 
 
113
  }
114
-
115
 
116
  ?>
1
  <?php
2
+
3
  /**
4
  * A container class for holding and transforming various plugin metadata.
5
  *
6
  * @author faishal
7
  */
8
  class rtPluginInfo {
9
+
10
+ //Most fields map directly to the contents of the plugin's info.json file.
11
+ //See the relevant docs for a description of their meaning.
12
+ public $name;
13
+ public $slug;
14
+ public $version;
15
+ public $homepage;
16
+ public $sections;
17
+ public $download_url;
18
+ public $author;
19
+ public $author_homepage;
20
+ public $requires;
21
+ public $tested;
22
+ public $upgrade_notice;
23
+ public $rating;
24
+ public $num_ratings;
25
+ public $downloaded;
26
+ public $last_updated;
27
+ public $id = 0; //The native WP.org API returns numeric plugin IDs, but they're not used for anything.
28
+
29
+ /**
30
+ * Create a new instance of PluginInfo from JSON-encoded plugin info
31
+ * returned by an external update API.
32
+ *
33
+ * @param string $json Valid JSON string representing plugin info.
34
+ * @param bool $triggerErrors
35
+ * @return PluginInfo|null New instance of PluginInfo, or NULL on error.
36
+ */
37
+
38
+ /**
39
+ *
40
+ * @param type $json
41
+ * @param type $triggerErrors
42
+ * @return null|\self
43
+ */
44
+ public static function fromJson($json, $triggerErrors = false) {
45
+ /** @var StdClass $apiResponse */
46
+ $apiResponse = json_decode($json);
47
+ if (empty($apiResponse) || !is_object($apiResponse)) {
48
+ if ($triggerErrors) {
49
+ trigger_error(
50
+ "Failed to parse plugin metadata. Try validating your .json file with http://jsonlint.com/", E_USER_NOTICE
51
+ );
52
+ }
53
+ return null;
54
+ }
55
+
56
+ //Very, very basic validation.
57
+ $valid = isset($apiResponse->name) && !empty($apiResponse->name) && isset($apiResponse->version) && !empty($apiResponse->version);
58
+ if (!$valid) {
59
+ if ($triggerErrors) {
60
+ trigger_error(
61
+ "The plugin metadata file does not contain the required 'name' and/or 'version' keys.", E_USER_NOTICE
62
+ );
63
+ }
64
+ return null;
65
+ }
66
+
67
+ $info = new self();
68
+ foreach (get_object_vars($apiResponse) as $key => $value) {
69
+ $info->$key = $value;
70
+ }
71
+
72
+ return $info;
73
+ }
74
+
75
+ /**
76
+ * Transform plugin info into the format used by the native WordPress.org API
77
+ *
78
+ * @return object
79
+ */
80
+
81
+ /**
82
+ *
83
+ * @return \StdClass
84
+ */
85
+ public function toWpFormat() {
86
+ $info = new StdClass;
87
+
88
+ //The custom update API is built so that many fields have the same name and format
89
+ //as those returned by the native WordPress.org API. These can be assigned directly.
90
+ $sameFormat = array(
91
+ 'name', 'slug', 'version', 'requires', 'tested', 'rating', 'upgrade_notice',
92
+ 'num_ratings', 'downloaded', 'homepage', 'last_updated',
93
+ );
94
+ foreach ($sameFormat as $field) {
95
+ if (isset($this->$field)) {
96
+ $info->$field = $this->$field;
97
+ } else {
98
+ $info->$field = null;
99
+ }
100
+ }
101
+
102
+ //Other fields need to be renamed and/or transformed.
103
+ $info->download_link = $this->download_url;
104
+
105
+ if (!empty($this->author_homepage)) {
106
+ $info->author = sprintf('<a href="%s">%s</a>', $this->author_homepage, $this->author);
107
+ } else {
108
+ $info->author = $this->author;
109
+ }
110
+
111
+ if (is_object($this->sections)) {
112
+ $info->sections = get_object_vars($this->sections);
113
+ } elseif (is_array($this->sections)) {
114
+ $info->sections = $this->sections;
115
+ } else {
116
+ $info->sections = array('description' => '');
117
+ }
118
+
119
+ return $info;
120
+ }
121
+
122
  }
 
123
 
124
  ?>
app/helper/rtPluginUpdate.php CHANGED
@@ -1,98 +1,130 @@
1
  <?php
 
2
  /**
3
  * Description of rtPluginUpdate
4
  * A simple container class for holding information about an available update.
5
  * @author faishal
6
  */
7
  class rtPluginUpdate {
8
- public $id = 0;
9
- public $slug;
10
- public $version;
11
- public $homepage;
12
- public $download_url;
13
- public $upgrade_notice;
14
- private static $fields = array('id', 'slug', 'version', 'homepage', 'download_url', 'upgrade_notice');
15
-
16
- /**
17
- * Create a new instance of PluginUpdate from its JSON-encoded representation.
18
- *
19
- * @param string $json
20
- * @param bool $triggerErrors
21
- * @return PluginUpdate|null
22
- */
23
- public static function fromJson($json, $triggerErrors = false){
24
- //Since update-related information is simply a subset of the full plugin info,
25
- //we can parse the update JSON as if it was a plugin info string, then copy over
26
- //the parts that we care about.
27
- $pluginInfo = rtPluginInfo::fromJson($json, $triggerErrors);
28
- if ( $pluginInfo != null ) {
29
- return self::fromPluginInfo($pluginInfo);
30
- } else {
31
- return null;
32
- }
33
- }
34
-
35
- /**
36
- * Create a new instance of PluginUpdate based on an instance of PluginInfo.
37
- * Basically, this just copies a subset of fields from one object to another.
38
- *
39
- * @param PluginInfo $info
40
- * @return PluginUpdate
41
- */
42
- public static function fromPluginInfo($info){
43
- return self::fromObject($info);
44
- }
45
-
46
- /**
47
- * Create a new instance of PluginUpdate by copying the necessary fields from
48
- * another object.
49
- *
50
- * @param StdClass|PluginInfo|PluginUpdate $object The source object.
51
- * @return PluginUpdate The new copy.
52
- */
53
- public static function fromObject($object) {
54
- $update = new self();
55
- foreach(self::$fields as $field){
56
- $update->$field = $object->$field;
57
- }
58
- return $update;
59
- }
60
-
61
- /**
62
- * Create an instance of StdClass that can later be converted back to
63
- * a PluginUpdate. Useful for serialization and caching, as it avoids
64
- * the "incomplete object" problem if the cached value is loaded before
65
- * this class.
66
- *
67
- * @return StdClass
68
- */
69
- public function toStdClass() {
70
- $object = new StdClass();
71
- foreach(self::$fields as $field){
72
- $object->$field = $this->$field;
73
- }
74
- return $object;
75
- }
76
-
77
-
78
- /**
79
- * Transform the update into the format used by WordPress native plugin API.
80
- *
81
- * @return object
82
- */
83
- public function toWpFormat(){
84
- $update = new StdClass;
85
-
86
- $update->id = $this->id;
87
- $update->slug = $this->slug;
88
- $update->new_version = $this->version;
89
- $update->url = $this->homepage;
90
- $update->package = $this->download_url;
91
- if ( !empty($this->upgrade_notice) ){
92
- $update->upgrade_notice = $this->upgrade_notice;
93
- }
94
-
95
- return $update;
96
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
 
98
  ?>
1
  <?php
2
+
3
  /**
4
  * Description of rtPluginUpdate
5
  * A simple container class for holding information about an available update.
6
  * @author faishal
7
  */
8
  class rtPluginUpdate {
9
+
10
+ public $id = 0;
11
+ public $slug;
12
+ public $version;
13
+ public $homepage;
14
+ public $download_url;
15
+ public $upgrade_notice;
16
+ private static $fields = array('id', 'slug', 'version', 'homepage', 'download_url', 'upgrade_notice');
17
+
18
+ /**
19
+ * Create a new instance of PluginUpdate from its JSON-encoded representation.
20
+ *
21
+ * @param string $json
22
+ * @param bool $triggerErrors
23
+ * @return PluginUpdate|null
24
+ */
25
+
26
+ /**
27
+ *
28
+ * @param type $json
29
+ * @param type $triggerErrors
30
+ * @return null
31
+ */
32
+ public static function fromJson($json, $triggerErrors = false) {
33
+ //Since update-related information is simply a subset of the full plugin info,
34
+ //we can parse the update JSON as if it was a plugin info string, then copy over
35
+ //the parts that we care about.
36
+ $pluginInfo = rtPluginInfo::fromJson($json, $triggerErrors);
37
+ if ($pluginInfo != null) {
38
+ return self::fromPluginInfo($pluginInfo);
39
+ } else {
40
+ return null;
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Create a new instance of PluginUpdate based on an instance of PluginInfo.
46
+ * Basically, this just copies a subset of fields from one object to another.
47
+ *
48
+ * @param PluginInfo $info
49
+ * @return PluginUpdate
50
+ */
51
+
52
+ /**
53
+ *
54
+ * @param type $info
55
+ * @return type
56
+ */
57
+ public static function fromPluginInfo($info) {
58
+ return self::fromObject($info);
59
+ }
60
+
61
+ /**
62
+ * Create a new instance of PluginUpdate by copying the necessary fields from
63
+ * another object.
64
+ *
65
+ * @param StdClass|PluginInfo|PluginUpdate $object The source object.
66
+ * @return PluginUpdate The new copy.
67
+ */
68
+
69
+ /**
70
+ *
71
+ * @param type $object
72
+ * @return \self
73
+ */
74
+ public static function fromObject($object) {
75
+ $update = new self();
76
+ foreach (self::$fields as $field) {
77
+ $update->$field = $object->$field;
78
+ }
79
+ return $update;
80
+ }
81
+
82
+ /**
83
+ * Create an instance of StdClass that can later be converted back to
84
+ * a PluginUpdate. Useful for serialization and caching, as it avoids
85
+ * the "incomplete object" problem if the cached value is loaded before
86
+ * this class.
87
+ *
88
+ * @return StdClass
89
+ */
90
+
91
+ /**
92
+ *
93
+ * @return \StdClass
94
+ */
95
+ public function toStdClass() {
96
+ $object = new StdClass();
97
+ foreach (self::$fields as $field) {
98
+ $object->$field = $this->$field;
99
+ }
100
+ return $object;
101
+ }
102
+
103
+ /**
104
+ * Transform the update into the format used by WordPress native plugin API.
105
+ *
106
+ * @return object
107
+ */
108
+
109
+ /**
110
+ *
111
+ * @return \StdClass
112
+ */
113
+ public function toWpFormat() {
114
+ $update = new StdClass;
115
+
116
+ $update->id = $this->id;
117
+ $update->slug = $this->slug;
118
+ $update->new_version = $this->version;
119
+ $update->url = $this->homepage;
120
+ $update->package = $this->download_url;
121
+ if (!empty($this->upgrade_notice)) {
122
+ $update->upgrade_notice = $this->upgrade_notice;
123
+ }
124
+
125
+ return $update;
126
+ }
127
+
128
  }
129
+
130
  ?>
app/helper/rtPluginUpdateChecker.php CHANGED
@@ -7,563 +7,660 @@
7
  * @author faishal
8
  */
9
  class rtPluginUpdateChecker {
10
- public $metadataUrl = ''; //The URL of the plugin's metadata file.
11
- public $pluginFile = ''; //Plugin filename relative to the plugins directory.
12
- public $slug = ''; //Plugin slug.
13
- public $checkPeriod = 12; //How often to check for updates (in hours).
14
- public $optionName = ''; //Where to store the update info.
15
-
16
- public $debugMode = true; //Set to TRUE to enable error reporting. Errors are raised using trigger_error()
17
- //and should be logged to the standard PHP error log.
18
-
19
- private $cronHook = null;
20
- private $debugBarPlugin = null;
21
-
22
- /**
23
- * Class constructor.
24
- *
25
- * @param string $metadataUrl The URL of the plugin's metadata file.
26
- * @param string $pluginFile Fully qualified path to the main plugin file.
27
- * @param string $slug The plugin's 'slug'. If not specified, the filename part of $pluginFile sans '.php' will be used as the slug.
28
- * @param integer $checkPeriod How often to check for updates (in hours). Defaults to checking every 12 hours. Set to 0 to disable automatic update checks.
29
- * @param string $optionName Where to store book-keeping info about update checks. Defaults to 'external_updates-$slug'.
30
- */
31
- public function __construct($metadataUrl, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = ''){
32
- $this->metadataUrl = $metadataUrl;
33
- $this->pluginFile = plugin_basename($pluginFile);
34
- $this->checkPeriod = $checkPeriod;
35
- $this->slug = $slug;
36
- $this->optionName = $optionName;
37
- $this->debugMode = defined('WP_DEBUG') && WP_DEBUG;
38
-
39
- //If no slug is specified, use the name of the main plugin file as the slug.
40
- //For example, 'my-cool-plugin/cool-plugin.php' becomes 'cool-plugin'.
41
- if ( empty($this->slug) ){
42
- $this->slug = basename($this->pluginFile, '.php');
43
- }
44
-
45
- if ( empty($this->optionName) ){
46
- $this->optionName = 'external_updates-' . $this->slug;
47
- }
48
-
49
- $this->installHooks();
50
- }
51
-
52
- /**
53
- * Install the hooks required to run periodic update checks and inject update info
54
- * into WP data structures.
55
- *
56
- * @return void
57
- */
58
- protected function installHooks(){
59
- //Override requests for plugin information
60
- add_filter('plugins_api', array($this, 'injectInfo'), 20, 3);
61
-
62
- //Insert our update info into the update array maintained by WP
63
- add_filter('site_transient_update_plugins', array($this,'injectUpdate')); //WP 3.0+
64
- add_filter('transient_update_plugins', array($this,'injectUpdate')); //WP 2.8+
65
-
66
- add_filter('plugin_row_meta', array($this, 'addCheckForUpdatesLink'), 10, 4);
67
- add_action('admin_init', array($this, 'handleManualCheck'));
68
- add_action('all_admin_notices', array($this, 'displayManualCheckResult'));
69
-
70
- //Set up the periodic update checks
71
- $this->cronHook = 'check_plugin_updates-' . $this->slug;
72
- if ( $this->checkPeriod > 0 ){
73
-
74
- //Trigger the check via Cron
75
- add_filter('cron_schedules', array($this, '_addCustomSchedule'));
76
- if ( !wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING') ) {
77
- $scheduleName = 'every' . $this->checkPeriod . 'hours';
78
- wp_schedule_event(time(), $scheduleName, $this->cronHook);
79
- }
80
- add_action($this->cronHook, array($this, 'checkForUpdates'));
81
-
82
- register_deactivation_hook($this->pluginFile, array($this, '_removeUpdaterCron'));
83
-
84
- //In case Cron is disabled or unreliable, we also manually trigger
85
- //the periodic checks while the user is browsing the Dashboard.
86
- add_action( 'admin_init', array($this, 'maybeCheckForUpdates') );
87
-
88
- } else {
89
- //Periodic checks are disabled.
90
- wp_clear_scheduled_hook($this->cronHook);
91
- }
92
-
93
- add_action('plugins_loaded', array($this, 'initDebugBarPanel'));
94
- }
95
-
96
- /**
97
- * Add our custom schedule to the array of Cron schedules used by WP.
98
- *
99
- * @param array $schedules
100
- * @return array
101
- */
102
- public function _addCustomSchedule($schedules){
103
- if ( $this->checkPeriod && ($this->checkPeriod > 0) ){
104
- $scheduleName = 'every' . $this->checkPeriod . 'hours';
105
- $schedules[$scheduleName] = array(
106
- 'interval' => $this->checkPeriod * 3600,
107
- 'display' => sprintf('Every %d hours', $this->checkPeriod),
108
- );
109
- }
110
- return $schedules;
111
- }
112
-
113
- /**
114
- * Remove the scheduled cron event that the library uses to check for updates.
115
- *
116
- * @return void
117
- */
118
- public function _removeUpdaterCron(){
119
- wp_clear_scheduled_hook($this->cronHook);
120
- }
121
-
122
- /**
123
- * Get the name of the update checker's WP-cron hook. Mostly useful for debugging.
124
- *
125
- * @return string
126
- */
127
- public function getCronHookName() {
128
- return $this->cronHook;
129
- }
130
-
131
- /**
132
- * Retrieve plugin info from the configured API endpoint.
133
- *
134
- * @uses wp_remote_get()
135
- *
136
- * @param array $queryArgs Additional query arguments to append to the request. Optional.
137
- * @return PluginInfo
138
- */
139
- public function requestInfo($queryArgs = array()){
140
- //Query args to append to the URL. Plugins can add their own by using a filter callback (see addQueryArgFilter()).
141
- $installedVersion = $this->getInstalledVersion();
142
- $queryArgs['installed_version'] = ($installedVersion !== null) ? $installedVersion : '';
143
- $queryArgs['admin_email'] = get_option("admin_email");
144
- $queryArgs['slug'] =$this->slug;
145
- $queryArgs = apply_filters('puc_request_info_query_args-'.$this->slug, $queryArgs);
146
- //Various options for the wp_remote_get() call. Plugins can filter these, too.
147
- $options = array(
148
- 'timeout' => 10, //seconds
149
- 'headers' => array(
150
- 'Accept' => 'application/json'
151
- ),
152
- );
153
- $options = apply_filters('puc_request_info_options-'.$this->slug, $options);
154
-
155
- //The plugin info should be at 'http://your-api.com/url/here/$slug/info.json'
156
- $url = $this->metadataUrl;
157
- if ( !empty($queryArgs) ){
158
- $url = add_query_arg($queryArgs, $url);
159
- }
160
-
161
- $result = wp_remote_get(
162
- $url,
163
- $options
164
- );
165
- //Try to parse the response
166
- $pluginInfo = null;
167
- if ( !is_wp_error($result) && isset($result['response']['code']) && ($result['response']['code'] == 200) && !empty($result['body']) ){
168
- $pluginInfo = rtPluginInfo::fromJson($result['body'], $this->debugMode);
169
-
170
- } else if ( $this->debugMode ) {
171
- $message = sprintf("The URL %s does not point to a valid plugin metadata file. ", $url);
172
- if ( is_wp_error($result) ) {
173
- $message .= "WP HTTP error: " . $result->get_error_message();
174
- } else if ( isset($result['response']['code']) ) {
175
- $message .= "HTTP response code is " . $result['response']['code'] . " (expected: 200)";
176
- } else {
177
- $message .= "wp_remote_get() returned an unexpected result.";
178
- }
179
- trigger_error($message, E_USER_WARNING);
180
- }
181
-
182
- $pluginInfo = apply_filters('puc_request_info_result-'.$this->slug, $pluginInfo, $result);
183
- return $pluginInfo;
184
- }
185
-
186
- /**
187
- * Retrieve the latest update (if any) from the configured API endpoint.
188
- *
189
- * @uses PluginUpdateChecker::requestInfo()
190
- *
191
- * @return PluginUpdate An instance of PluginUpdate, or NULL when no updates are available.
192
- */
193
- public function requestUpdate(){
194
- //For the sake of simplicity, this function just calls requestInfo()
195
- //and transforms the result accordingly.
196
- $pluginInfo = $this->requestInfo(array('checking_for_updates' => '1'));
197
- if ( $pluginInfo == null ){
198
- return null;
199
- }
200
- return rtPluginUpdate::fromPluginInfo($pluginInfo);
201
- }
202
-
203
- /**
204
- * Get the currently installed version of the plugin.
205
- *
206
- * @return string Version number.
207
- */
208
- public function getInstalledVersion(){
209
-
210
- if ( !function_exists('get_plugins') ){
211
- if(is_multisite()){
212
- require_once( ABSPATH .'/wp-admin/network/includes/plugin.php' );
213
- }else{require_once( ABSPATH .'/wp-admin/includes/plugin.php' );}
214
- }
215
- $allPlugins = get_plugins();
216
- if ( array_key_exists($this->pluginFile, $allPlugins) && array_key_exists('Version', $allPlugins[$this->pluginFile]) ){
217
- return $allPlugins[$this->pluginFile]['Version'];
218
-
219
- } else {
220
- //This can happen if the filename is wrong or the plugin is installed in mu-plugins.
221
- if ( $this->debugMode ) {
222
- trigger_error(
223
- sprintf(
224
- "Can't to read the Version header for %s. The filename may be incorrect, or the file is not present in /wp-content/plugins.",
225
- $this->pluginFile
226
- ),
227
- E_USER_WARNING
228
- );
229
- }
230
- return null;
231
- }
232
- }
233
-
234
- /**
235
- * Check for plugin updates.
236
- * The results are stored in the DB option specified in $optionName.
237
- *
238
- * @return PluginUpdate|null
239
- */
240
- public function checkForUpdates(){
241
- $installedVersion = $this->getInstalledVersion();
242
- //Fail silently if we can't find the plugin or read its header.
243
- if ( $installedVersion === null ) {
244
- if ( $this->debugMode ) {
245
- trigger_error(
246
- sprintf('Skipping update check for %s - installed version unknown.', $this->pluginFile),
247
- E_USER_WARNING
248
- );
249
- }
250
- return null;
251
- }
252
-
253
- $state = $this->getUpdateState();
254
- if ( empty($state) ){
255
- $state = new StdClass;
256
- $state->lastCheck = 0;
257
- $state->checkedVersion = '';
258
- $state->update = null;
259
- }
260
-
261
- $state->lastCheck = time();
262
- $state->checkedVersion = $installedVersion;
263
- $this->setUpdateState($state); //Save before checking in case something goes wrong
264
-
265
- $state->update = $this->requestUpdate();
266
- $this->setUpdateState($state);
267
-
268
- return $this->getUpdate();
269
- }
270
-
271
- /**
272
- * Check for updates only if the configured check interval has already elapsed.
273
- *
274
- * @return void
275
- */
276
- public function maybeCheckForUpdates(){
277
- if ( empty($this->checkPeriod) ){
278
- return;
279
- }
280
- $state = $this->getUpdateState();
281
-
282
- $shouldCheck =
283
- empty($state) ||
284
- !isset($state->lastCheck) ||
285
- ( (time() - $state->lastCheck) >= $this->checkPeriod*3600 );
286
-
287
- if ( $shouldCheck ){
288
- $this->checkForUpdates();
289
- }
290
- }
291
-
292
- /**
293
- * Load the update checker state from the DB.
294
- *
295
- * @return StdClass|null
296
- */
297
- public function getUpdateState() {
298
- $state = get_site_option($this->optionName, null);
299
- if ( empty($state) || !is_object($state)) {
300
- $state = null;
301
- }
302
-
303
- if ( !empty($state) && isset($state->update) && is_object($state->update) ){
304
- $state->update = rtPluginUpdate::fromObject($state->update);
305
- }
306
- return $state;
307
- }
308
-
309
-
310
- /**
311
- * Persist the update checker state to the DB.
312
- *
313
- * @param StdClass $state
314
- * @return void
315
- */
316
- private function setUpdateState($state) {
317
- if ( isset($state->update) && is_object($state->update) && method_exists($state->update, 'toStdClass') ) {
318
- $update = $state->update; /** @var PluginUpdate $update */
319
- $state->update = $update->toStdClass();
320
- }
321
- update_site_option($this->optionName, $state);
322
- }
323
-
324
- /**
325
- * Reset update checker state - i.e. last check time, cached update data and so on.
326
- *
327
- * Call this when your plugin is being uninstalled, or if you want to
328
- * clear the update cache.
329
- */
330
- public function resetUpdateState() {
331
- delete_site_option($this->optionName);
332
- }
333
-
334
- /**
335
- * Intercept plugins_api() calls that request information about our plugin and
336
- * use the configured API endpoint to satisfy them.
337
- *
338
- * @see plugins_api()
339
- *
340
- * @param mixed $result
341
- * @param string $action
342
- * @param array|object $args
343
- * @return mixed
344
- */
345
- public function injectInfo($result, $action = null, $args = null){
346
- $relevant = ($action == 'plugin_information') && isset($args->slug) && ($args->slug == $this->slug);
347
- if ( !$relevant ){
348
- return $result;
349
- }
350
-
351
- $pluginInfo = $this->requestInfo();
352
- $pluginInfo = apply_filters('puc_pre_inject_info-' . $this->slug, $pluginInfo);
353
- if ($pluginInfo){
354
- return $pluginInfo->toWpFormat();
355
- }
356
-
357
- return $result;
358
- }
359
-
360
- /**
361
- * Insert the latest update (if any) into the update list maintained by WP.
362
- *
363
- * @param StdClass $updates Update list.
364
- * @return StdClass Modified update list.
365
- */
366
- public function injectUpdate($updates){
367
- //Is there an update to insert?
368
- $update = $this->getUpdate();
369
- if ( !empty($update) ) {
370
- //Let plugins filter the update info before it's passed on to WordPress.
371
- $update = apply_filters('puc_pre_inject_update-' . $this->slug, $update);
372
- if ( !is_object($updates) ) {
373
- $updates = new StdClass();
374
- $updates->response = array();
375
- }
376
- $updates->response[$this->pluginFile] = $update->toWpFormat();
377
- } else if ( isset($updates, $updates->response) ) {
378
- unset($updates->response[$this->pluginFile]);
379
- }
380
-
381
- return $updates;
382
- }
383
-
384
- /**
385
- * Get the details of the currently available update, if any.
386
- *
387
- * If no updates are available, or if the last known update version is below or equal
388
- * to the currently installed version, this method will return NULL.
389
- *
390
- * Uses cached update data. To retrieve update information straight from
391
- * the metadata URL, call requestUpdate() instead.
392
- *
393
- * @return PluginUpdate|null
394
- */
395
- public function getUpdate() {
396
- $state = $this->getUpdateState(); /** @var StdClass $state */
397
-
398
- //Is there an update available insert?
399
- if ( !empty($state) && isset($state->update) && !empty($state->update) ){
400
- $update = $state->update;
401
- //Check if the update is actually newer than the currently installed version.
402
- $installedVersion = $this->getInstalledVersion();
403
- if ( ($installedVersion !== null) && version_compare($update->version, $installedVersion, '>') ){
404
- return $update;
405
- }
406
- }
407
- return null;
408
- }
409
-
410
- /**
411
- * Add a "Check for updates" link to the plugin row in the "Plugins" page. By default,
412
- * the new link will appear after the "Visit plugin site" link.
413
- *
414
- * You can change the link text by using the "puc_manual_check_link-$slug" filter.
415
- * Returning an empty string from the filter will disable the link.
416
- *
417
- * @param array $pluginMeta Array of meta links.
418
- * @param string $pluginFile
419
- * @param array|null $pluginData Currently ignored.
420
- * @param string|null $status Currently ignored.
421
- * @return array
422
- */
423
- public function addCheckForUpdatesLink($pluginMeta, $pluginFile, $pluginData = null, $status = null) {
424
- if ( $pluginFile == $this->pluginFile && current_user_can('update_plugins') ) {
425
- $linkUrl = wp_nonce_url(
426
- add_query_arg(
427
- array(
428
- 'puc_check_for_updates' => 1,
429
- 'puc_slug' => $this->slug,
430
- ),
431
- is_network_admin() ? network_admin_url('plugins.php') : admin_url('plugins.php')
432
- ),
433
- 'puc_check_for_updates'
434
- );
435
-
436
- $linkText = apply_filters('puc_manual_check_link-' . $this->slug, 'Check for updates');
437
- if ( !empty($linkText) ) {
438
- $pluginMeta[] = sprintf('<a href="%s">%s</a>', esc_attr($linkUrl), $linkText);
439
- }
440
- }
441
- return $pluginMeta;
442
- }
443
-
444
- /**
445
- * Check for updates when the user clicks the "Check for updates" link.
446
- * @see self::addCheckForUpdatesLink()
447
- *
448
- * @return void
449
- */
450
- public function handleManualCheck() {
451
- $shouldCheck =
452
- isset($_GET['puc_check_for_updates'], $_GET['puc_slug'])
453
- && $_GET['puc_slug'] == $this->slug
454
- && current_user_can('update_plugins')
455
- && check_admin_referer('puc_check_for_updates');
456
-
457
- if ( $shouldCheck ) {
458
- $update = $this->checkForUpdates();
459
- $status = ($update === null) ? 'no_update' : 'update_available';
460
- wp_redirect(add_query_arg(
461
- array(
462
- 'puc_update_check_result' => $status,
463
- 'puc_slug' => $this->slug,
464
- ),
465
- is_network_admin() ? network_admin_url('plugins.php') : admin_url('plugins.php')
466
- ));
467
- }
468
- }
469
-
470
- /**
471
- * Display the results of a manual update check.
472
- * @see self::handleManualCheck()
473
- *
474
- * You can change the result message by using the "puc_manual_check_message-$slug" filter.
475
- */
476
- public function displayManualCheckResult() {
477
- if ( isset($_GET['puc_update_check_result'], $_GET['puc_slug']) && ($_GET['puc_slug'] == $this->slug) ) {
478
- $status = strval($_GET['puc_update_check_result']);
479
- if ( $status == 'no_update' ) {
480
- $message = 'This plugin is up to date.';
481
- } else if ( $status == 'update_available' ) {
482
- $message = 'A new version of this plugin is available.';
483
- } else {
484
- $message = sprintf('Unknown update checker status "%s"', htmlentities($status));
485
- }
486
- printf(
487
- '<div class="updated"><p>%s</p></div>',
488
- apply_filters('puc_manual_check_message-' . $this->slug, $message, $status)
489
- );
490
- }
491
- }
492
-
493
- /**
494
- * Register a callback for filtering query arguments.
495
- *
496
- * The callback function should take one argument - an associative array of query arguments.
497
- * It should return a modified array of query arguments.
498
- *
499
- * @uses add_filter() This method is a convenience wrapper for add_filter().
500
- *
501
- * @param callable $callback
502
- * @return void
503
- */
504
- public function addQueryArgFilter($callback){
505
- add_filter('puc_request_info_query_args-'.$this->slug, $callback);
506
- }
507
-
508
- /**
509
- * Register a callback for filtering arguments passed to wp_remote_get().
510
- *
511
- * The callback function should take one argument - an associative array of arguments -
512
- * and return a modified array or arguments. See the WP documentation on wp_remote_get()
513
- * for details on what arguments are available and how they work.
514
- *
515
- * @uses add_filter() This method is a convenience wrapper for add_filter().
516
- *
517
- * @param callable $callback
518
- * @return void
519
- */
520
- public function addHttpRequestArgFilter($callback){
521
- add_filter('puc_request_info_options-'.$this->slug, $callback);
522
- }
523
-
524
- /**
525
- * Register a callback for filtering the plugin info retrieved from the external API.
526
- *
527
- * The callback function should take two arguments. If the plugin info was retrieved
528
- * successfully, the first argument passed will be an instance of PluginInfo. Otherwise,
529
- * it will be NULL. The second argument will be the corresponding return value of
530
- * wp_remote_get (see WP docs for details).
531
- *
532
- * The callback function should return a new or modified instance of PluginInfo or NULL.
533
- *
534
- * @uses add_filter() This method is a convenience wrapper for add_filter().
535
- *
536
- * @param callable $callback
537
- * @return void
538
- */
539
- public function addResultFilter($callback){
540
- add_filter('puc_request_info_result-'.$this->slug, $callback, 10, 2);
541
- }
542
-
543
- /**
544
- * Register a callback for one of the update checker filters.
545
- *
546
- * Identical to add_filter(), except it automatically adds the "puc_" prefix
547
- * and the "-$plugin_slug" suffix to the filter name. For example, "request_info_result"
548
- * becomes "puc_request_info_result-your_plugin_slug".
549
- *
550
- * @param string $tag
551
- * @param callable $callback
552
- * @param int $priority
553
- * @param int $acceptedArgs
554
- */
555
- public function addFilter($tag, $callback, $priority = 10, $acceptedArgs = 1) {
556
- add_filter('puc_' . $tag . '-' . $this->slug, $callback, $priority, $acceptedArgs);
557
- }
558
-
559
- /**
560
- * Initialize the update checker Debug Bar plugin/add-on thingy.
561
- */
562
- public function initDebugBarPanel() {
563
- if ( class_exists('Debug_Bar') ) {
564
- require_once dirname(__FILE__) . '/debug-bar-plugin.php';
565
- $this->debugBarPlugin = new PucDebugBarPlugin($this);
566
- }
567
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
  }
 
569
  ?>
7
  * @author faishal
8
  */
9
  class rtPluginUpdateChecker {
10
+
11
+ public $metadataUrl = ''; //The URL of the plugin's metadata file.
12
+ public $pluginFile = ''; //Plugin filename relative to the plugins directory.
13
+ public $slug = ''; //Plugin slug.
14
+ public $checkPeriod = 12; //How often to check for updates (in hours).
15
+ public $optionName = ''; //Where to store the update info.
16
+ public $debugMode = true; //Set to TRUE to enable error reporting. Errors are raised using trigger_error()
17
+ //and should be logged to the standard PHP error log.
18
+ private $cronHook = null;
19
+ private $debugBarPlugin = null;
20
+
21
+ /**
22
+ * Class constructor.
23
+ *
24
+ * @param string $metadataUrl The URL of the plugin's metadata file.
25
+ * @param string $pluginFile Fully qualified path to the main plugin file.
26
+ * @param string $slug The plugin's 'slug'. If not specified, the filename part of $pluginFile sans '.php' will be used as the slug.
27
+ * @param integer $checkPeriod How often to check for updates (in hours). Defaults to checking every 12 hours. Set to 0 to disable automatic update checks.
28
+ * @param string $optionName Where to store book-keeping info about update checks. Defaults to 'external_updates-$slug'.
29
+ */
30
+
31
+ /**
32
+ *
33
+ * @param type $metadataUrl
34
+ * @param type $pluginFile
35
+ * @param type $slug
36
+ * @param type $checkPeriod
37
+ * @param type $optionName
38
+ */
39
+ public function __construct($metadataUrl, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '') {
40
+ $this->metadataUrl = $metadataUrl;
41
+ $this->pluginFile = plugin_basename($pluginFile);
42
+ $this->checkPeriod = $checkPeriod;
43
+ $this->slug = $slug;
44
+ $this->optionName = $optionName;
45
+ $this->debugMode = defined('WP_DEBUG') && WP_DEBUG;
46
+
47
+ //If no slug is specified, use the name of the main plugin file as the slug.
48
+ //For example, 'my-cool-plugin/cool-plugin.php' becomes 'cool-plugin'.
49
+ if (empty($this->slug)) {
50
+ $this->slug = basename($this->pluginFile, '.php');
51
+ }
52
+
53
+ if (empty($this->optionName)) {
54
+ $this->optionName = 'external_updates-' . $this->slug;
55
+ }
56
+
57
+ $this->installHooks();
58
+ }
59
+
60
+ /**
61
+ * Install the hooks required to run periodic update checks and inject update info
62
+ * into WP data structures.
63
+ *
64
+ * @return void
65
+ */
66
+ protected function installHooks() {
67
+ //Override requests for plugin information
68
+ add_filter('plugins_api', array($this, 'injectInfo'), 20, 3);
69
+
70
+ //Insert our update info into the update array maintained by WP
71
+ add_filter('site_transient_update_plugins', array($this, 'injectUpdate')); //WP 3.0+
72
+ add_filter('transient_update_plugins', array($this, 'injectUpdate')); //WP 2.8+
73
+
74
+ add_filter('plugin_row_meta', array($this, 'addCheckForUpdatesLink'), 10, 4);
75
+ add_action('admin_init', array($this, 'handleManualCheck'));
76
+ add_action('all_admin_notices', array($this, 'displayManualCheckResult'));
77
+
78
+ //Set up the periodic update checks
79
+ $this->cronHook = 'check_plugin_updates-' . $this->slug;
80
+ if ($this->checkPeriod > 0) {
81
+
82
+ //Trigger the check via Cron
83
+ add_filter('cron_schedules', array($this, '_addCustomSchedule'));
84
+ if (!wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING')) {
85
+ $scheduleName = 'every' . $this->checkPeriod . 'hours';
86
+ wp_schedule_event(time(), $scheduleName, $this->cronHook);
87
+ }
88
+ add_action($this->cronHook, array($this, 'checkForUpdates'));
89
+
90
+ register_deactivation_hook($this->pluginFile, array($this, '_removeUpdaterCron'));
91
+
92
+ //In case Cron is disabled or unreliable, we also manually trigger
93
+ //the periodic checks while the user is browsing the Dashboard.
94
+ add_action('admin_init', array($this, 'maybeCheckForUpdates'));
95
+ } else {
96
+ //Periodic checks are disabled.
97
+ wp_clear_scheduled_hook($this->cronHook);
98
+ }
99
+
100
+ add_action('plugins_loaded', array($this, 'initDebugBarPanel'));
101
+ }
102
+
103
+ /**
104
+ * Add our custom schedule to the array of Cron schedules used by WP.
105
+ *
106
+ * @param array $schedules
107
+ * @return array
108
+ */
109
+
110
+ /**
111
+ *
112
+ * @param type $schedules
113
+ * @return type
114
+ */
115
+ public function _addCustomSchedule($schedules) {
116
+ if ($this->checkPeriod && ($this->checkPeriod > 0)) {
117
+ $scheduleName = 'every' . $this->checkPeriod . 'hours';
118
+ $schedules[$scheduleName] = array(
119
+ 'interval' => $this->checkPeriod * 3600,
120
+ 'display' => sprintf('Every %d hours', $this->checkPeriod),
121
+ );
122
+ }
123
+ return $schedules;
124
+ }
125
+
126
+ /**
127
+ * Remove the scheduled cron event that the library uses to check for updates.
128
+ *
129
+ * @return void
130
+ */
131
+ public function _removeUpdaterCron() {
132
+ wp_clear_scheduled_hook($this->cronHook);
133
+ }
134
+
135
+ /**
136
+ * Get the name of the update checker's WP-cron hook. Mostly useful for debugging.
137
+ *
138
+ * @return string
139
+ */
140
+
141
+ /**
142
+ *
143
+ * @return type
144
+ */
145
+ public function getCronHookName() {
146
+ return $this->cronHook;
147
+ }
148
+
149
+ /**
150
+ * Retrieve plugin info from the configured API endpoint.
151
+ *
152
+ * @uses wp_remote_get()
153
+ *
154
+ * @param array $queryArgs Additional query arguments to append to the request. Optional.
155
+ * @return PluginInfo
156
+ */
157
+
158
+ /**
159
+ *
160
+ * @param type $queryArgs
161
+ * @return type
162
+ */
163
+ public function requestInfo($queryArgs = array()) {
164
+ //Query args to append to the URL. Plugins can add their own by using a filter callback (see addQueryArgFilter()).
165
+ $installedVersion = $this->getInstalledVersion();
166
+ $queryArgs['installed_version'] = ($installedVersion !== null) ? $installedVersion : '';
167
+ $queryArgs['admin_email'] = get_option("admin_email");
168
+ $queryArgs['slug'] = $this->slug;
169
+ $queryArgs = apply_filters('puc_request_info_query_args-' . $this->slug, $queryArgs);
170
+ //Various options for the wp_remote_get() call. Plugins can filter these, too.
171
+ $options = array(
172
+ 'timeout' => 10, //seconds
173
+ 'headers' => array(
174
+ 'Accept' => 'application/json'
175
+ ),
176
+ );
177
+ $options = apply_filters('puc_request_info_options-' . $this->slug, $options);
178
+
179
+ //The plugin info should be at 'http://your-api.com/url/here/$slug/info.json'
180
+ $url = $this->metadataUrl;
181
+ if (!empty($queryArgs)) {
182
+ $url = add_query_arg($queryArgs, $url);
183
+ }
184
+
185
+ $result = wp_remote_get(
186
+ $url, $options
187
+ );
188
+ //Try to parse the response
189
+ $pluginInfo = null;
190
+ if (!is_wp_error($result) && isset($result['response']['code']) && ($result['response']['code'] == 200) && !empty($result['body'])) {
191
+ $pluginInfo = rtPluginInfo::fromJson($result['body'], $this->debugMode);
192
+ } else if ($this->debugMode) {
193
+ $message = sprintf("The URL %s does not point to a valid plugin metadata file. ", $url);
194
+ if (is_wp_error($result)) {
195
+ $message .= "WP HTTP error: " . $result->get_error_message();
196
+ } else if (isset($result['response']['code'])) {
197
+ $message .= "HTTP response code is " . $result['response']['code'] . " (expected: 200)";
198
+ } else {
199
+ $message .= "wp_remote_get() returned an unexpected result.";
200
+ }
201
+ trigger_error($message, E_USER_WARNING);
202
+ }
203
+
204
+ $pluginInfo = apply_filters('puc_request_info_result-' . $this->slug, $pluginInfo, $result);
205
+ return $pluginInfo;
206
+ }
207
+
208
+ /**
209
+ * Retrieve the latest update (if any) from the configured API endpoint.
210
+ *
211
+ * @uses PluginUpdateChecker::requestInfo()
212
+ *
213
+ * @return PluginUpdate An instance of PluginUpdate, or NULL when no updates are available.
214
+ */
215
+
216
+ /**
217
+ *
218
+ * @return null
219
+ */
220
+ public function requestUpdate() {
221
+ //For the sake of simplicity, this function just calls requestInfo()
222
+ //and transforms the result accordingly.
223
+ $pluginInfo = $this->requestInfo(array('checking_for_updates' => '1'));
224
+ if ($pluginInfo == null) {
225
+ return null;
226
+ }
227
+ return rtPluginUpdate::fromPluginInfo($pluginInfo);
228
+ }
229
+
230
+ /**
231
+ * Get the currently installed version of the plugin.
232
+ *
233
+ * @return string Version number.
234
+ */
235
+
236
+ /**
237
+ *
238
+ * @return null
239
+ */
240
+ public function getInstalledVersion() {
241
+
242
+ if (!function_exists('get_plugins')) {
243
+ if (is_multisite()) {
244
+ require_once( ABSPATH . '/wp-admin/network/includes/plugin.php' );
245
+ } else {
246
+ require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
247
+ }
248
+ }
249
+ $allPlugins = get_plugins();
250
+ if (array_key_exists($this->pluginFile, $allPlugins) && array_key_exists('Version', $allPlugins[$this->pluginFile])) {
251
+ return $allPlugins[$this->pluginFile]['Version'];
252
+ } else {
253
+ //This can happen if the filename is wrong or the plugin is installed in mu-plugins.
254
+ if ($this->debugMode) {
255
+ trigger_error(
256
+ sprintf(
257
+ "Can't to read the Version header for %s. The filename may be incorrect, or the file is not present in /wp-content/plugins.", $this->pluginFile
258
+ ), E_USER_WARNING
259
+ );
260
+ }
261
+ return null;
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Check for plugin updates.
267
+ * The results are stored in the DB option specified in $optionName.
268
+ *
269
+ * @return PluginUpdate|null
270
+ */
271
+
272
+ /**
273
+ *
274
+ * @return null
275
+ */
276
+ public function checkForUpdates() {
277
+ $installedVersion = $this->getInstalledVersion();
278
+ //Fail silently if we can't find the plugin or read its header.
279
+ if ($installedVersion === null) {
280
+ if ($this->debugMode) {
281
+ trigger_error(
282
+ sprintf('Skipping update check for %s - installed version unknown.', $this->pluginFile), E_USER_WARNING
283
+ );
284
+ }
285
+ return null;
286
+ }
287
+
288
+ $state = $this->getUpdateState();
289
+ if (empty($state)) {
290
+ $state = new StdClass;
291
+ $state->lastCheck = 0;
292
+ $state->checkedVersion = '';
293
+ $state->update = null;
294
+ }
295
+
296
+ $state->lastCheck = time();
297
+ $state->checkedVersion = $installedVersion;
298
+ $this->setUpdateState($state); //Save before checking in case something goes wrong
299
+
300
+ $state->update = $this->requestUpdate();
301
+ $this->setUpdateState($state);
302
+
303
+ return $this->getUpdate();
304
+ }
305
+
306
+ /**
307
+ * Check for updates only if the configured check interval has already elapsed.
308
+ *
309
+ * @return void
310
+ */
311
+
312
+ /**
313
+ *
314
+ * @return type
315
+ */
316
+ public function maybeCheckForUpdates() {
317
+ if (empty($this->checkPeriod)) {
318
+ return;
319
+ }
320
+ $state = $this->getUpdateState();
321
+
322
+ $shouldCheck =
323
+ empty($state) ||
324
+ !isset($state->lastCheck) ||
325
+ ( (time() - $state->lastCheck) >= $this->checkPeriod * 3600 );
326
+
327
+ if ($shouldCheck) {
328
+ $this->checkForUpdates();
329
+ }
330
+ }
331
+
332
+ /**
333
+ * Load the update checker state from the DB.
334
+ *
335
+ * @return StdClass|null
336
+ */
337
+
338
+ /**
339
+ *
340
+ * @return null
341
+ */
342
+ public function getUpdateState() {
343
+ $state = get_site_option($this->optionName, null);
344
+ if (empty($state) || !is_object($state)) {
345
+ $state = null;
346
+ }
347
+
348
+ if (!empty($state) && isset($state->update) && is_object($state->update)) {
349
+ $state->update = rtPluginUpdate::fromObject($state->update);
350
+ }
351
+ return $state;
352
+ }
353
+
354
+ /**
355
+ * Persist the update checker state to the DB.
356
+ *
357
+ * @param StdClass $state
358
+ * @return void
359
+ */
360
+
361
+ /**
362
+ *
363
+ * @param type $state
364
+ */
365
+ private function setUpdateState($state) {
366
+ if (isset($state->update) && is_object($state->update) && method_exists($state->update, 'toStdClass')) {
367
+ $update = $state->update;/** @var PluginUpdate $update */
368
+ $state->update = $update->toStdClass();
369
+ }
370
+ update_site_option($this->optionName, $state);
371
+ }
372
+
373
+ /**
374
+ * Reset update checker state - i.e. last check time, cached update data and so on.
375
+ *
376
+ * Call this when your plugin is being uninstalled, or if you want to
377
+ * clear the update cache.
378
+ */
379
+ public function resetUpdateState() {
380
+ delete_site_option($this->optionName);
381
+ }
382
+
383
+ /**
384
+ * Intercept plugins_api() calls that request information about our plugin and
385
+ * use the configured API endpoint to satisfy them.
386
+ *
387
+ * @see plugins_api()
388
+ *
389
+ * @param mixed $result
390
+ * @param string $action
391
+ * @param array|object $args
392
+ * @return mixed
393
+ */
394
+
395
+ /**
396
+ *
397
+ * @param type $result
398
+ * @param type $action
399
+ * @param type $args
400
+ * @return type
401
+ */
402
+ public function injectInfo($result, $action = null, $args = null) {
403
+ $relevant = ($action == 'plugin_information') && isset($args->slug) && ($args->slug == $this->slug);
404
+ if (!$relevant) {
405
+ return $result;
406
+ }
407
+
408
+ $pluginInfo = $this->requestInfo();
409
+ $pluginInfo = apply_filters('puc_pre_inject_info-' . $this->slug, $pluginInfo);
410
+ if ($pluginInfo) {
411
+ return $pluginInfo->toWpFormat();
412
+ }
413
+
414
+ return $result;
415
+ }
416
+
417
+ /**
418
+ * Insert the latest update (if any) into the update list maintained by WP.
419
+ *
420
+ * @param StdClass $updates Update list.
421
+ * @return StdClass Modified update list.
422
+ */
423
+
424
+ /**
425
+ *
426
+ * @param StdClass $updates
427
+ * @return \StdClass
428
+ */
429
+ public function injectUpdate($updates) {
430
+ //Is there an update to insert?
431
+ $update = $this->getUpdate();
432
+ if (!empty($update)) {
433
+ //Let plugins filter the update info before it's passed on to WordPress.
434
+ $update = apply_filters('puc_pre_inject_update-' . $this->slug, $update);
435
+ if (!is_object($updates)) {
436
+ $updates = new StdClass();
437
+ $updates->response = array();
438
+ }
439
+ $updates->response[$this->pluginFile] = $update->toWpFormat();
440
+ } else if (isset($updates, $updates->response)) {
441
+ unset($updates->response[$this->pluginFile]);
442
+ }
443
+
444
+ return $updates;
445
+ }
446
+
447
+ /**
448
+ * Get the details of the currently available update, if any.
449
+ *
450
+ * If no updates are available, or if the last known update version is below or equal
451
+ * to the currently installed version, this method will return NULL.
452
+ *
453
+ * Uses cached update data. To retrieve update information straight from
454
+ * the metadata URL, call requestUpdate() instead.
455
+ *
456
+ * @return PluginUpdate|null
457
+ */
458
+
459
+ /**
460
+ *
461
+ * @return null
462
+ */
463
+ public function getUpdate() {
464
+ $state = $this->getUpdateState();/** @var StdClass $state */
465
+ //Is there an update available insert?
466
+ if (!empty($state) && isset($state->update) && !empty($state->update)) {
467
+ $update = $state->update;
468
+ //Check if the update is actually newer than the currently installed version.
469
+ $installedVersion = $this->getInstalledVersion();
470
+ if (($installedVersion !== null) && version_compare($update->version, $installedVersion, '>')) {
471
+ return $update;
472
+ }
473
+ }
474
+ return null;
475
+ }
476
+
477
+ /**
478
+ * Add a "Check for updates" link to the plugin row in the "Plugins" page. By default,
479
+ * the new link will appear after the "Visit plugin site" link.
480
+ *
481
+ * You can change the link text by using the "puc_manual_check_link-$slug" filter.
482
+ * Returning an empty string from the filter will disable the link.
483
+ *
484
+ * @param array $pluginMeta Array of meta links.
485
+ * @param string $pluginFile
486
+ * @param array|null $pluginData Currently ignored.
487
+ * @param string|null $status Currently ignored.
488
+ * @return array
489
+ */
490
+
491
+ /**
492
+ *
493
+ * @param type $pluginMeta
494
+ * @param type $pluginFile
495
+ * @param type $pluginData
496
+ * @param type $status
497
+ * @return type
498
+ */
499
+ public function addCheckForUpdatesLink($pluginMeta, $pluginFile, $pluginData = null, $status = null) {
500
+ if ($pluginFile == $this->pluginFile && current_user_can('update_plugins')) {
501
+ $linkUrl = wp_nonce_url(
502
+ add_query_arg(
503
+ array(
504
+ 'puc_check_for_updates' => 1,
505
+ 'puc_slug' => $this->slug,
506
+ ), is_network_admin() ? network_admin_url('plugins.php') : admin_url('plugins.php')
507
+ ), 'puc_check_for_updates'
508
+ );
509
+
510
+ $linkText = apply_filters('puc_manual_check_link-' . $this->slug, 'Check for updates');
511
+ if (!empty($linkText)) {
512
+ $pluginMeta[] = sprintf('<a href="%s">%s</a>', esc_attr($linkUrl), $linkText);
513
+ }
514
+ }
515
+ return $pluginMeta;
516
+ }
517
+
518
+ /**
519
+ * Check for updates when the user clicks the "Check for updates" link.
520
+ * @see self::addCheckForUpdatesLink()
521
+ *
522
+ * @return void
523
+ */
524
+ public function handleManualCheck() {
525
+ $shouldCheck =
526
+ isset($_GET['puc_check_for_updates'], $_GET['puc_slug'])
527
+ && $_GET['puc_slug'] == $this->slug
528
+ && current_user_can('update_plugins')
529
+ && check_admin_referer('puc_check_for_updates');
530
+
531
+ if ($shouldCheck) {
532
+ $update = $this->checkForUpdates();
533
+ $status = ($update === null) ? 'no_update' : 'update_available';
534
+ wp_redirect(add_query_arg(
535
+ array(
536
+ 'puc_update_check_result' => $status,
537
+ 'puc_slug' => $this->slug,
538
+ ), is_network_admin() ? network_admin_url('plugins.php') : admin_url('plugins.php')
539
+ ));
540
+ }
541
+ }
542
+
543
+ /**
544
+ * Display the results of a manual update check.
545
+ * @see self::handleManualCheck()
546
+ *
547
+ * You can change the result message by using the "puc_manual_check_message-$slug" filter.
548
+ */
549
+ public function displayManualCheckResult() {
550
+ if (isset($_GET['puc_update_check_result'], $_GET['puc_slug']) && ($_GET['puc_slug'] == $this->slug)) {
551
+ $status = strval($_GET['puc_update_check_result']);
552
+ if ($status == 'no_update') {
553
+ $message = 'This plugin is up to date.';
554
+ } else if ($status == 'update_available') {
555
+ $message = 'A new version of this plugin is available.';
556
+ } else {
557
+ $message = sprintf('Unknown update checker status "%s"', htmlentities($status));
558
+ }
559
+ printf(
560
+ '<div class="updated"><p>%s</p></div>', apply_filters('puc_manual_check_message-' . $this->slug, $message, $status)
561
+ );
562
+ }
563
+ }
564
+
565
+ /**
566
+ * Register a callback for filtering query arguments.
567
+ *
568
+ * The callback function should take one argument - an associative array of query arguments.
569
+ * It should return a modified array of query arguments.
570
+ *
571
+ * @uses add_filter() This method is a convenience wrapper for add_filter().
572
+ *
573
+ * @param callable $callback
574
+ * @return void
575
+ */
576
+
577
+ /**
578
+ *
579
+ * @param type $callback
580
+ */
581
+ public function addQueryArgFilter($callback) {
582
+ add_filter('puc_request_info_query_args-' . $this->slug, $callback);
583
+ }
584
+
585
+ /**
586
+ * Register a callback for filtering arguments passed to wp_remote_get().
587
+ *
588
+ * The callback function should take one argument - an associative array of arguments -
589
+ * and return a modified array or arguments. See the WP documentation on wp_remote_get()
590
+ * for details on what arguments are available and how they work.
591
+ *
592
+ * @uses add_filter() This method is a convenience wrapper for add_filter().
593
+ *
594
+ * @param callable $callback
595
+ * @return void
596
+ */
597
+
598
+ /**
599
+ *
600
+ * @param type $callback
601
+ */
602
+ public function addHttpRequestArgFilter($callback) {
603
+ add_filter('puc_request_info_options-' . $this->slug, $callback);
604
+ }
605
+
606
+ /**
607
+ * Register a callback for filtering the plugin info retrieved from the external API.
608
+ *
609
+ * The callback function should take two arguments. If the plugin info was retrieved
610
+ * successfully, the first argument passed will be an instance of PluginInfo. Otherwise,
611
+ * it will be NULL. The second argument will be the corresponding return value of
612
+ * wp_remote_get (see WP docs for details).
613
+ *
614
+ * The callback function should return a new or modified instance of PluginInfo or NULL.
615
+ *
616
+ * @uses add_filter() This method is a convenience wrapper for add_filter().
617
+ *
618
+ * @param callable $callback
619
+ * @return void
620
+ */
621
+
622
+ /**
623
+ *
624
+ * @param type $callback
625
+ */
626
+ public function addResultFilter($callback) {
627
+ add_filter('puc_request_info_result-' . $this->slug, $callback, 10, 2);
628
+ }
629
+
630
+ /**
631
+ * Register a callback for one of the update checker filters.
632
+ *
633
+ * Identical to add_filter(), except it automatically adds the "puc_" prefix
634
+ * and the "-$plugin_slug" suffix to the filter name. For example, "request_info_result"
635
+ * becomes "puc_request_info_result-your_plugin_slug".
636
+ *
637
+ * @param string $tag
638
+ * @param callable $callback
639
+ * @param int $priority
640
+ * @param int $acceptedArgs
641
+ */
642
+
643
+ /**
644
+ *
645
+ * @param type $tag
646
+ * @param type $callback
647
+ * @param type $priority
648
+ * @param type $acceptedArgs
649
+ */
650
+ public function addFilter($tag, $callback, $priority = 10, $acceptedArgs = 1) {
651
+ add_filter('puc_' . $tag . '-' . $this->slug, $callback, $priority, $acceptedArgs);
652
+ }
653
+
654
+ /**
655
+ * Initialize the update checker Debug Bar plugin/add-on thingy.
656
+ */
657
+ public function initDebugBarPanel() {
658
+ if (class_exists('Debug_Bar')) {
659
+ require_once dirname(__FILE__) . '/debug-bar-plugin.php';
660
+ $this->debugBarPlugin = new PucDebugBarPlugin($this);
661
+ }
662
+ }
663
+
664
  }
665
+
666
  ?>
app/main/BPMediaLoader.php CHANGED
@@ -13,106 +13,122 @@
13
  */
14
  class BPMediaLoader {
15
 
16
- /**
17
- * Hooks into BuddyPress
18
- *
19
- * Hooks into bp_loaded to load itself
20
- * Hooks into bp_setup_nav to add tabs to the profile and group navigation
21
- * Hooks into after_setup_theme to add its thumbnail sizes
22
- *
23
- * @uses bp_loaded
24
- * @uses bp_setup_nav
25
- * @uses after_setup_theme
26
- */
27
- public function __construct() {
28
- add_action( 'bp_loaded', array( $this, 'load_component' ) );
29
- add_action( 'bp_setup_nav', array( $this, 'custom_nav' ), 999 );
30
- add_action( 'after_setup_theme', array( $this, 'thumbnail' ) );
31
- }
32
 
33
- /**
34
- * BuddyPress Media Loader
35
- *
36
- * Loads and adds it to the BuddyPress global object
37
- *
38
- * @global object $bp BuddyPress object
39
- */
40
- public function load_component() {
41
- global $bp;
42
- $bp->{BP_MEDIA_SLUG} = new BPMediaComponent();
43
- }
44
 
45
- /**
46
- * Navigation Loader
47
- *
48
- * Loads BuddyPress Media's navigation
49
- *
50
- * @global object $bp BuddyPress object
51
- */
52
- public function custom_nav() {
53
- global $bp;
54
- foreach ( $bp->bp_nav as $key => $nav_item ) {
55
- switch ( $nav_item[ 'slug' ] ) {
56
- case BP_MEDIA_IMAGES_SLUG:
57
- case BP_MEDIA_VIDEOS_SLUG:
58
- case BP_MEDIA_AUDIO_SLUG:
59
- case BP_MEDIA_ALBUMS_SLUG:
60
- $bp->bp_options_nav[ BP_MEDIA_SLUG ][ ] = array(
61
- 'name' => $nav_item[ 'name' ],
62
- 'link' => (isset( $bp->displayed_user->domain ) ? $bp->displayed_user->domain : (isset( $bp->loggedin_user->domain ) ? $bp->loggedin_user->domain : '')) . $nav_item[ 'slug' ] . '/',
63
- 'slug' => $nav_item[ 'slug' ],
64
- 'css_id' => $nav_item[ 'css_id' ],
65
- 'position' => $nav_item[ 'position' ],
66
- 'screen_function' => $nav_item[ 'screen_function' ],
67
- 'user_has_access' => true,
68
- 'parent_url' => trailingslashit( bp_displayed_user_domain() )
69
- );
70
- unset( $bp->bp_nav[ $key ] );
71
- break;
72
- case BP_MEDIA_UPLOAD_SLUG:
73
- $bp->bp_options_nav[ BP_MEDIA_SLUG ][ ] = array(
74
- 'name' => $nav_item[ 'name' ],
75
- 'link' => (isset( $bp->displayed_user->domain ) ? $bp->displayed_user->domain : (isset( $bp->loggedin_user->domain ) ? $bp->loggedin_user->domain : '')) . $nav_item[ 'slug' ] . '/',
76
- 'slug' => $nav_item[ 'slug' ],
77
- 'css_id' => $nav_item[ 'css_id' ],
78
- 'position' => $nav_item[ 'position' ],
79
- 'screen_function' => $nav_item[ 'screen_function' ],
80
- 'user_has_access' => bp_is_my_profile(),
81
- 'parent_url' => trailingslashit( bp_displayed_user_domain() )
82
- );
83
- unset( $bp->bp_nav[ $key ] );
84
- }
85
- switch ( $bp->current_component ) {
86
- case BP_MEDIA_IMAGES_SLUG:
87
- case BP_MEDIA_VIDEOS_SLUG:
88
- case BP_MEDIA_AUDIO_SLUG:
89
- case BP_MEDIA_ALBUMS_SLUG:
90
- case BP_MEDIA_UPLOAD_SLUG:
91
- $count = count( $bp->action_variables );
92
- for ( $i = $count; $i > 0; $i -- ) {
93
- $bp->action_variables[ $i ] = $bp->action_variables[ $i - 1 ];
94
- }
95
- $bp->action_variables[ 0 ] = $bp->current_action;
96
- $bp->current_action = $bp->current_component;
97
- $bp->current_component = BP_MEDIA_SLUG;
98
- }
99
- }
100
- }
101
- /**
102
- * Custom Thumbnail Sizes
103
- *
104
- * Adds image sizes required by the plugin to existing WordPress sizes
105
- *
106
- * @global object $bp_media
107
- */
108
- public function thumbnail() {
109
- global $bp_media;
110
 
111
- $default_sizes = $bp_media->media_sizes();
 
 
 
 
 
 
112
 
113
- add_image_size( 'bp_media_activity_image', $default_sizes[ 'activity_image' ][ 'width' ], $default_sizes[ 'activity_image' ][ 'height' ], true );
114
- add_image_size( 'bp_media_single_image', $default_sizes[ 'single_image' ][ 'width' ], $default_sizes[ 'single_image' ][ 'height' ], true );
115
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  }
118
 
13
  */
14
  class BPMediaLoader {
15
 
16
+ /**
17
+ * Hooks into BuddyPress
18
+ *
19
+ * Hooks into bp_loaded to load itself
20
+ * Hooks into bp_setup_nav to add tabs to the profile and group navigation
21
+ * Hooks into after_setup_theme to add its thumbnail sizes
22
+ *
23
+ * @uses bp_loaded
24
+ * @uses bp_setup_nav
25
+ * @uses after_setup_theme
26
+ */
27
+ public function __construct() {
28
+ add_action('bp_loaded', array($this, 'load_component'));
29
+ add_action('bp_setup_nav', array($this, 'custom_nav'), 999);
30
+ add_action('after_setup_theme', array($this, 'thumbnail'));
31
+ }
32
 
33
+ /**
34
+ * BuddyPress Media Loader
35
+ *
36
+ * Loads and adds it to the BuddyPress global object
37
+ *
38
+ * @global object $bp BuddyPress object
39
+ */
 
 
 
 
40
 
41
+ /**
42
+ *
43
+ * @global object $bp
44
+ */
45
+ public function load_component() {
46
+ global $bp;
47
+ $bp->{BP_MEDIA_SLUG} = new BPMediaComponent();
48
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
+ /**
51
+ * Navigation Loader
52
+ *
53
+ * Loads BuddyPress Media's navigation
54
+ *
55
+ * @global object $bp BuddyPress object
56
+ */
57
 
58
+ /**
59
+ *
60
+ * @global object $bp
61
+ */
62
+ public function custom_nav() {
63
+ global $bp;
64
+ foreach ($bp->bp_nav as $key => $nav_item) {
65
+ switch ($nav_item['slug']) {
66
+ case BP_MEDIA_IMAGES_SLUG:
67
+ case BP_MEDIA_VIDEOS_SLUG:
68
+ case BP_MEDIA_AUDIO_SLUG:
69
+ case BP_MEDIA_ALBUMS_SLUG:
70
+ $bp->bp_options_nav[BP_MEDIA_SLUG][] = array(
71
+ 'name' => $nav_item['name'],
72
+ 'link' => (isset($bp->displayed_user->domain) ? $bp->displayed_user->domain : (isset($bp->loggedin_user->domain) ? $bp->loggedin_user->domain : '')) . $nav_item['slug'] . '/',
73
+ 'slug' => $nav_item['slug'],
74
+ 'css_id' => $nav_item['css_id'],
75
+ 'position' => $nav_item['position'],
76
+ 'screen_function' => $nav_item['screen_function'],
77
+ 'user_has_access' => true,
78
+ 'parent_url' => trailingslashit(bp_displayed_user_domain())
79
+ );
80
+ unset($bp->bp_nav[$key]);
81
+ break;
82
+ case BP_MEDIA_UPLOAD_SLUG:
83
+ $bp->bp_options_nav[BP_MEDIA_SLUG][] = array(
84
+ 'name' => $nav_item['name'],
85
+ 'link' => (isset($bp->displayed_user->domain) ? $bp->displayed_user->domain : (isset($bp->loggedin_user->domain) ? $bp->loggedin_user->domain : '')) . $nav_item['slug'] . '/',
86
+ 'slug' => $nav_item['slug'],
87
+ 'css_id' => $nav_item['css_id'],
88
+ 'position' => $nav_item['position'],
89
+ 'screen_function' => $nav_item['screen_function'],
90
+ 'user_has_access' => bp_is_my_profile(),
91
+ 'parent_url' => trailingslashit(bp_displayed_user_domain())
92
+ );
93
+ unset($bp->bp_nav[$key]);
94
+ }
95
+ switch ($bp->current_component) {
96
+ case BP_MEDIA_IMAGES_SLUG:
97
+ case BP_MEDIA_VIDEOS_SLUG:
98
+ case BP_MEDIA_AUDIO_SLUG:
99
+ case BP_MEDIA_ALBUMS_SLUG:
100
+ case BP_MEDIA_UPLOAD_SLUG:
101
+ $count = count($bp->action_variables);
102
+ for ($i = $count; $i > 0; $i--) {
103
+ $bp->action_variables[$i] = $bp->action_variables[$i - 1];
104
+ }
105
+ $bp->action_variables[0] = $bp->current_action;
106
+ $bp->current_action = $bp->current_component;
107
+ $bp->current_component = BP_MEDIA_SLUG;
108
+ }
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Custom Thumbnail Sizes
114
+ *
115
+ * Adds image sizes required by the plugin to existing WordPress sizes
116
+ *
117
+ * @global object $bp_media
118
+ */
119
+
120
+ /**
121
+ *
122
+ * @global type $bp_media
123
+ */
124
+ public function thumbnail() {
125
+ global $bp_media;
126
+
127
+ $default_sizes = $bp_media->media_sizes();
128
+
129
+ add_image_size('bp_media_activity_image', $default_sizes['activity_image']['width'], $default_sizes['activity_image']['height'], true);
130
+ add_image_size('bp_media_single_image', $default_sizes['single_image']['width'], $default_sizes['single_image']['height'], true);
131
+ }
132
 
133
  }
134
 
app/main/BuddyPressMedia.php CHANGED
@@ -48,9 +48,9 @@ class BuddyPressMedia {
48
  */
49
  add_action('bp_include', array($this, 'init'));
50
  add_action('widgets_init', array($this, 'widgets_init'), 1);
51
- add_action('plugins_loaded',array($this,'load_translation'));
52
- global $bp_media_counter;
53
- $bp_media_counter = 0;
54
  }
55
 
56
  public function bp_exists() {
@@ -191,6 +191,10 @@ class BuddyPressMedia {
191
  define('BP_MEDIA_SUPPORT_EMAIL', $this->support_email);
192
  }
193
 
 
 
 
 
194
  function init() {
195
  $this->get_option();
196
 
@@ -209,13 +213,19 @@ class BuddyPressMedia {
209
  $bp_media_admin = new BPMediaAdmin();
210
  }
211
 
212
- static function load_translation(){
213
- load_plugin_textdomain(BP_MEDIA_TXT_DOMAIN, false, basename(BP_MEDIA_PATH).'/languages/');
214
- }
215
 
 
 
 
 
 
 
216
  function settings_link($links, $file) {
217
  /* create link */
218
- $plugin_name = plugin_basename(BP_MEDIA_PATH.'index.php');
219
  $admin_link = $this->get_admin_url(add_query_arg(array('page' => 'bp-media-settings'), 'admin.php'));
220
  if ($file == $plugin_name) {
221
  array_unshift(
@@ -225,6 +235,10 @@ class BuddyPressMedia {
225
  return $links;
226
  }
227
 
 
 
 
 
228
  function media_sizes() {
229
  $def_sizes = array(
230
  'activity_image' => array(
@@ -254,6 +268,10 @@ class BuddyPressMedia {
254
  return apply_filters('bpm_media_sizes', $def_sizes);
255
  }
256
 
 
 
 
 
257
  function excerpt_lengths() {
258
  global $bp_media_default_excerpts;
259
  $def_excerpt = array(
@@ -266,6 +284,10 @@ class BuddyPressMedia {
266
  $bp_media_default_excerpts = apply_filters('bpm_excerpt_lengths', $def_excerpt);
267
  }
268
 
 
 
 
 
269
  public function admin_notice() {
270
  global $current_user;
271
  $user_id = $current_user->ID;
@@ -302,6 +324,12 @@ class BuddyPressMedia {
302
  }
303
  }
304
 
 
 
 
 
 
 
305
  function get_admin_url($path = '', $scheme = 'admin') {
306
 
307
  // Links belong in network admin
48
  */
49
  add_action('bp_include', array($this, 'init'));
50
  add_action('widgets_init', array($this, 'widgets_init'), 1);
51
+ add_action('plugins_loaded', array($this, 'load_translation'));
52
+ global $bp_media_counter;
53
+ $bp_media_counter = 0;
54
  }
55
 
56
  public function bp_exists() {
191
  define('BP_MEDIA_SUPPORT_EMAIL', $this->support_email);
192
  }
193
 
194
+ /**
195
+ *
196
+ * @global BPMediaAdmin $bp_media_admin
197
+ */
198
  function init() {
199
  $this->get_option();
200
 
213
  $bp_media_admin = new BPMediaAdmin();
214
  }
215
 
216
+ static function load_translation() {
217
+ load_plugin_textdomain(BP_MEDIA_TXT_DOMAIN, false, basename(BP_MEDIA_PATH) . '/languages/');
218
+ }
219
 
220
+ /**
221
+ *
222
+ * @param type $links
223
+ * @param type $file
224
+ * @return type
225
+ */
226
  function settings_link($links, $file) {
227
  /* create link */
228
+ $plugin_name = plugin_basename(BP_MEDIA_PATH . 'index.php');
229
  $admin_link = $this->get_admin_url(add_query_arg(array('page' => 'bp-media-settings'), 'admin.php'));
230
  if ($file == $plugin_name) {
231
  array_unshift(
235
  return $links;
236
  }
237
 
238
+ /**
239
+ *
240
+ * @return type
241
+ */
242
  function media_sizes() {
243
  $def_sizes = array(
244
  'activity_image' => array(
268
  return apply_filters('bpm_media_sizes', $def_sizes);
269
  }
270
 
271
+ /**
272
+ *
273
+ * @global type $bp_media_default_excerpts
274
+ */
275
  function excerpt_lengths() {
276
  global $bp_media_default_excerpts;
277
  $def_excerpt = array(
284
  $bp_media_default_excerpts = apply_filters('bpm_excerpt_lengths', $def_excerpt);
285
  }
286
 
287
+ /**
288
+ *
289
+ * @global type $current_user
290
+ */
291
  public function admin_notice() {
292
  global $current_user;
293
  $user_id = $current_user->ID;
324
  }
325
  }
326
 
327
+ /**
328
+ *
329
+ * @param type $path
330
+ * @param type $scheme
331
+ * @return type
332
+ */
333
  function get_admin_url($path = '', $scheme = 'admin') {
334
 
335
  // Links belong in network admin
app/main/group/BPMediaGroup.php CHANGED
@@ -29,6 +29,12 @@ class BPMediaGroup {
29
  *
30
  * @since BuddyPress Media 2.3
31
  */
 
 
 
 
 
 
32
  function custom_nav() {
33
  global $bp;
34
  $current_group = isset($bp->groups->current_group->slug) ? $bp->groups->current_group->slug : null;
@@ -72,6 +78,13 @@ class BPMediaGroup {
72
  *
73
  * @since BuddyPress Media 2.3
74
  */
 
 
 
 
 
 
 
75
  function multipart_params_handler($multipart_params) {
76
  if (is_array($multipart_params)) {
77
  global $bp;
@@ -92,12 +105,18 @@ class BPMediaGroup {
92
  *
93
  * @since BuddyPress Media 2.3
94
  */
 
 
 
 
 
 
95
  static function navigation_menu() {
96
  global $bp;
97
  if (!isset($bp->current_action) || $bp->current_action != BP_MEDIA_SLUG)
98
  return false;
99
- $bp_media_upload = new BPMediaUploadScreen( 'upload', BP_MEDIA_UPLOAD_SLUG );
100
- $bp_media_image = new BPMediaScreen( 'image', BP_MEDIA_IMAGES_SLUG );
101
  $current_tab = BP_MEDIA_IMAGES_SLUG;
102
 
103
  if (isset($bp->action_variables[0])) {
@@ -105,18 +124,18 @@ class BPMediaGroup {
105
  }
106
 
107
  // if (BPMediaGroup::can_upload()) {
108
- $bp_media_nav[BP_MEDIA_IMAGES_SLUG] = array(
109
- 'url' => trailingslashit(bp_get_group_permalink($bp->groups->current_group)) . BP_MEDIA_SLUG,
110
- 'label' => BP_MEDIA_IMAGES_LABEL,
111
- 'screen_function' => array( $bp_media_image, 'screen' )
112
- );
113
  // } else {
114
  // $bp_media_nav = array();
115
  // }
116
 
117
  foreach (array('VIDEOS', 'AUDIO', 'ALBUMS', 'UPLOAD') as $type) {
118
- if ( $type == 'UPLOAD' ) {
119
- if ( BPMediaGroup::can_upload() ) {
120
  $bp_media_nav[constant('BP_MEDIA_' . $type . '_SLUG')] = array(
121
  'url' => trailingslashit(bp_get_group_permalink($bp->groups->current_group)) . constant('BP_MEDIA_' . $type . '_SLUG'),
122
  'label' => constant('BP_MEDIA_' . $type . '_LABEL'),
@@ -153,6 +172,12 @@ class BPMediaGroup {
153
  *
154
  * @since BuddyPress Media 2.3
155
  */
 
 
 
 
 
 
156
  static function can_upload() {
157
  /** @todo Implementation Pending */
158
  global $bp;
@@ -172,6 +197,12 @@ class BPMediaGroup {
172
  *
173
  * @since BuddyPress Media 2.3
174
  */
 
 
 
 
 
 
175
  function admin_bar() {
176
  global $wp_admin_bar, $bp;
177
  $wp_admin_bar->add_menu(array(
@@ -195,6 +226,13 @@ class BPMediaGroup {
195
  *
196
  * @return boolean True if the user can create an album in the group, false if not
197
  */
 
 
 
 
 
 
 
198
  static function user_can_create_album($group_id, $user_id = 0) {
199
  if ($user_id == 0)
200
  $user_id = get_current_user_id();
@@ -215,11 +253,15 @@ class BPMediaGroup {
215
  return false;
216
  }
217
 
 
 
 
 
218
  static function bp_media_display_error($errorMessage) {
219
  ?>
220
  <div id="message" class="error">
221
  <p>
222
- <?php _e($errorMessage, BP_MEDIA_TXT_DOMAIN); ?>
223
  </p>
224
  </div>
225
  <?php
29
  *
30
  * @since BuddyPress Media 2.3
31
  */
32
+
33
+ /**
34
+ *
35
+ * @global type $bp
36
+ * @return type
37
+ */
38
  function custom_nav() {
39
  global $bp;
40
  $current_group = isset($bp->groups->current_group->slug) ? $bp->groups->current_group->slug : null;
78
  *
79
  * @since BuddyPress Media 2.3
80
  */
81
+
82
+ /**
83
+ *
84
+ * @global type $bp
85
+ * @param type $multipart_params
86
+ * @return type
87
+ */
88
  function multipart_params_handler($multipart_params) {
89
  if (is_array($multipart_params)) {
90
  global $bp;
105
  *
106
  * @since BuddyPress Media 2.3
107
  */
108
+
109
+ /**
110
+ *
111
+ * @global type $bp
112
+ * @return boolean
113
+ */
114
  static function navigation_menu() {
115
  global $bp;
116
  if (!isset($bp->current_action) || $bp->current_action != BP_MEDIA_SLUG)
117
  return false;
118
+ $bp_media_upload = new BPMediaUploadScreen('upload', BP_MEDIA_UPLOAD_SLUG);
119
+ $bp_media_image = new BPMediaScreen('image', BP_MEDIA_IMAGES_SLUG);
120
  $current_tab = BP_MEDIA_IMAGES_SLUG;
121
 
122
  if (isset($bp->action_variables[0])) {
124
  }
125
 
126
  // if (BPMediaGroup::can_upload()) {
127
+ $bp_media_nav[BP_MEDIA_IMAGES_SLUG] = array(
128
+ 'url' => trailingslashit(bp_get_group_permalink($bp->groups->current_group)) . BP_MEDIA_SLUG,
129
+ 'label' => BP_MEDIA_IMAGES_LABEL,
130
+ 'screen_function' => array($bp_media_image, 'screen')
131
+ );
132
  // } else {
133
  // $bp_media_nav = array();
134
  // }
135
 
136
  foreach (array('VIDEOS', 'AUDIO', 'ALBUMS', 'UPLOAD') as $type) {
137
+ if ($type == 'UPLOAD') {
138
+ if (BPMediaGroup::can_upload()) {
139
  $bp_media_nav[constant('BP_MEDIA_' . $type . '_SLUG')] = array(
140
  'url' => trailingslashit(bp_get_group_permalink($bp->groups->current_group)) . constant('BP_MEDIA_' . $type . '_SLUG'),
141
  'label' => constant('BP_MEDIA_' . $type . '_LABEL'),
172
  *
173
  * @since BuddyPress Media 2.3
174
  */
175
+
176
+ /**
177
+ *
178
+ * @global type $bp
179
+ * @return boolean
180
+ */
181
  static function can_upload() {
182
  /** @todo Implementation Pending */
183
  global $bp;
197
  *
198
  * @since BuddyPress Media 2.3
199
  */
200
+
201
+ /**
202
+ *
203
+ * @global type $wp_admin_bar
204
+ * @global type $bp
205
+ */
206
  function admin_bar() {
207
  global $wp_admin_bar, $bp;
208
  $wp_admin_bar->add_menu(array(
226
  *
227
  * @return boolean True if the user can create an album in the group, false if not
228
  */
229
+
230
+ /**
231
+ *
232
+ * @param type $group_id
233
+ * @param type $user_id
234
+ * @return boolean
235
+ */
236
  static function user_can_create_album($group_id, $user_id = 0) {
237
  if ($user_id == 0)
238
  $user_id = get_current_user_id();
253
  return false;
254
  }
255
 
256
+ /**
257
+ *
258
+ * @param type $errorMessage
259
+ */
260
  static function bp_media_display_error($errorMessage) {
261
  ?>
262
  <div id="message" class="error">
263
  <p>
264
+ <?php _e($errorMessage, BP_MEDIA_TXT_DOMAIN); ?>
265
  </p>
266
  </div>
267
  <?php
app/main/group/BPMediaGroupAction.php CHANGED
@@ -6,7 +6,6 @@
6
  * @author faishal
7
  */
8
  class BPMediaGroupAction {
9
-
10
  /**
11
  * Called on bp_init by screen functions
12
  *
@@ -14,6 +13,13 @@ class BPMediaGroupAction {
14
  *
15
  * @since BuddyPress Media 2.0
16
  */
 
 
 
 
 
 
 
17
  static function bp_media_groups_set_query() {
18
  global $bp, $bp_media_query, $bp_media_posts_per_page;
19
  if (isset($bp->current_action) && $bp->current_action == BP_MEDIA_SLUG) {
@@ -65,6 +71,12 @@ class BPMediaGroupAction {
65
  *
66
  * @since BuddyPress Media 2.2
67
  */
 
 
 
 
 
 
68
  static function bp_media_groups_albums_set_query() {
69
  global $bp, $bp_media_albums_query;
70
  if (isset($bp->action_variables) && isset($bp->action_variables[1]) && $bp->action_variables[1] == 'page' && isset($bp->action_variables[2]) && is_numeric($bp->action_variables[2])) {
@@ -82,10 +94,15 @@ class BPMediaGroupAction {
82
  'meta_compare' => '='
83
  );
84
  $bp_media_albums_query = new WP_Query($args);
85
-
86
  }
87
  }
88
 
 
 
 
 
 
 
89
  static function bp_media_groups_activity_create_after_add_media($media, $hidden = false) {
90
  if (function_exists('bp_activity_add')) {
91
  if (!is_object($media)) {
@@ -114,7 +131,15 @@ class BPMediaGroupAction {
114
  }
115
 
116
  //add_action('bp_media_groups_after_add_media','bp_media_groups_activity_create_after_add_media',10,2);
 
 
 
 
117
 
 
 
 
 
118
  static function bp_media_groups_redirection_handler() {
119
  global $bp;
120
  echo '<pre>';
@@ -124,7 +149,10 @@ class BPMediaGroupAction {
124
  }
125
 
126
  //add_action('bp_media_init','bp_media_groups_redirection_handler');
127
-
 
 
 
128
  static function bp_media_groups_force_hide_activity() {
129
  return true;
130
  }
6
  * @author faishal
7
  */
8
  class BPMediaGroupAction {
 
9
  /**
10
  * Called on bp_init by screen functions
11
  *
13
  *
14
  * @since BuddyPress Media 2.0
15
  */
16
+
17
+ /**
18
+ *
19
+ * @global type $bp
20
+ * @global WP_Query $bp_media_query
21
+ * @global type $bp_media_posts_per_page
22
+ */
23
  static function bp_media_groups_set_query() {
24
  global $bp, $bp_media_query, $bp_media_posts_per_page;
25
  if (isset($bp->current_action) && $bp->current_action == BP_MEDIA_SLUG) {
71
  *
72
  * @since BuddyPress Media 2.2
73
  */
74
+
75
+ /**
76
+ *
77
+ * @global type $bp
78
+ * @global WP_Query $bp_media_albums_query
79
+ */
80
  static function bp_media_groups_albums_set_query() {
81
  global $bp, $bp_media_albums_query;
82
  if (isset($bp->action_variables) && isset($bp->action_variables[1]) && $bp->action_variables[1] == 'page' && isset($bp->action_variables[2]) && is_numeric($bp->action_variables[2])) {
94
  'meta_compare' => '='
95
  );
96
  $bp_media_albums_query = new WP_Query($args);
 
97
  }
98
  }
99
 
100
+ /**
101
+ *
102
+ * @param BPMediaHostWordpress $media
103
+ * @param type $hidden
104
+ * @return boolean
105
+ */
106
  static function bp_media_groups_activity_create_after_add_media($media, $hidden = false) {
107
  if (function_exists('bp_activity_add')) {
108
  if (!is_object($media)) {
131
  }
132
 
133
  //add_action('bp_media_groups_after_add_media','bp_media_groups_activity_create_after_add_media',10,2);
134
+ /**
135
+ *
136
+ * @global type $bp
137
+ */
138
 
139
+ /**
140
+ *
141
+ * @global type $bp
142
+ */
143
  static function bp_media_groups_redirection_handler() {
144
  global $bp;
145
  echo '<pre>';
149
  }
150
 
151
  //add_action('bp_media_init','bp_media_groups_redirection_handler');
152
+ /**
153
+ *
154
+ * @return boolean
155
+ */
156
  static function bp_media_groups_force_hide_activity() {
157
  return true;
158
  }
app/main/group/BPMediaGroupElementExtension.php CHANGED
@@ -11,11 +11,23 @@ if (class_exists('BP_Group_Extension')) :
11
  var $enable_edit_item = false;
12
  var $enable_create_step = false;
13
 
 
 
 
 
 
14
  function __construct($name, $slug) {
15
  $this->name = $name;
16
  $this->slug = $slug;
17
  }
18
 
 
 
 
 
 
 
 
19
  function display() {
20
  global $bp;
21
  BPMediaGroupAction::bp_media_groups_set_query();
@@ -26,7 +38,7 @@ if (class_exists('BP_Group_Extension')) :
26
  BPMediaGroup::navigation_menu();
27
  $media_type = "";
28
  $slug = "";
29
- switch ( $current_tab ) {
30
  case BP_MEDIA_IMAGES_SLUG:
31
  $media_type = "image";
32
  $slug = BP_MEDIA_IMAGES_SLUG;
@@ -73,7 +85,7 @@ if (class_exists('BP_Group_Extension')) :
73
  }
74
  if ($media_type == "album") {
75
  $bp_media_content = new BPMediaAlbumScreen($media_type, BP_MEDIA_ALBUMS_ENTRY_SLUG);
76
- $bp->action_variables[ 0 ]= BP_MEDIA_ALBUMS_ENTRY_SLUG;
77
  $bp_media_content->entry_screen();
78
  } else {
79
  $bp_media_content = new BPMediaScreen($media_type, $slug);
@@ -90,7 +102,7 @@ if (class_exists('BP_Group_Extension')) :
90
  BPMediaGroupAction::bp_media_groups_albums_set_query();
91
  $bp_media_content = new BPMediaAlbumScreen($media_type, $slug);
92
  $bp_media_content->screen_content();
93
- } else if ( $media_type == 'upload' ) {
94
  if (BPMediaGroup::can_upload()) {
95
  $bp_media_upload = new BPMediaUploadScreen('upload', BP_MEDIA_UPLOAD_SLUG);
96
  $bp_media_upload->upload_screen_content();
@@ -104,9 +116,13 @@ if (class_exists('BP_Group_Extension')) :
104
  }
105
 
106
  function widget_display() {
107
-
108
  }
109
 
 
 
 
 
110
  function bp_media_display_error($errorMessage) {
111
  ?>
112
  <div id="message" class="error">
11
  var $enable_edit_item = false;
12
  var $enable_create_step = false;
13
 
14
+ /**
15
+ *
16
+ * @param type $name
17
+ * @param type $slug
18
+ */
19
  function __construct($name, $slug) {
20
  $this->name = $name;
21
  $this->slug = $slug;
22
  }
23
 
24
+ /**
25
+ *
26
+ * @global type $bp
27
+ * @global BPMediaHostWordpress $bp_media_current_entry
28
+ * @return type
29
+ * @throws Exception
30
+ */
31
  function display() {
32
  global $bp;
33
  BPMediaGroupAction::bp_media_groups_set_query();
38
  BPMediaGroup::navigation_menu();
39
  $media_type = "";
40
  $slug = "";
41
+ switch ($current_tab) {
42
  case BP_MEDIA_IMAGES_SLUG:
43
  $media_type = "image";
44
  $slug = BP_MEDIA_IMAGES_SLUG;
85
  }
86
  if ($media_type == "album") {
87
  $bp_media_content = new BPMediaAlbumScreen($media_type, BP_MEDIA_ALBUMS_ENTRY_SLUG);
88
+ $bp->action_variables[0] = BP_MEDIA_ALBUMS_ENTRY_SLUG;
89
  $bp_media_content->entry_screen();
90
  } else {
91
  $bp_media_content = new BPMediaScreen($media_type, $slug);
102
  BPMediaGroupAction::bp_media_groups_albums_set_query();
103
  $bp_media_content = new BPMediaAlbumScreen($media_type, $slug);
104
  $bp_media_content->screen_content();
105
+ } else if ($media_type == 'upload') {
106
  if (BPMediaGroup::can_upload()) {
107
  $bp_media_upload = new BPMediaUploadScreen('upload', BP_MEDIA_UPLOAD_SLUG);
108
  $bp_media_upload->upload_screen_content();
116
  }
117
 
118
  function widget_display() {
119
+
120
  }
121
 
122
+ /**
123
+ *
124
+ * @param type $errorMessage
125
+ */
126
  function bp_media_display_error($errorMessage) {
127
  ?>
128
  <div id="message" class="error">
app/main/group/BPMediaGroupsExtension.php CHANGED
@@ -7,7 +7,6 @@
7
  if (class_exists('BP_Group_Extension')) :// Recommended, to prevent problems during upgrade or when Groups are disabled
8
 
9
  class BPMediaGroupsExtension extends BPMediaGroupElementExtension {
10
-
11
  /**
12
  * Constructor for the BP_Group_Extension adding values to the variables defined
13
  *
@@ -15,14 +14,24 @@ if (class_exists('BP_Group_Extension')) :// Recommended, to prevent problems dur
15
  *
16
  * @since BuddyPress Media 2.3
17
  */
 
 
 
 
 
18
  function __construct() {
19
  global $bp;
20
- $this->name = __(BP_MEDIA_LABEL,BP_MEDIA_TXT_DOMAIN);
21
  $this->slug = BP_MEDIA_SLUG;
22
  $this->create_step_position = 21;
23
  $this->nav_item_position = 31;
24
- }
25
 
 
 
 
 
 
26
  function create_screen() {
27
  global $bp_media;
28
  if (!bp_is_group_creation_step($this->slug))
@@ -49,6 +58,10 @@ if (class_exists('BP_Group_Extension')) :// Recommended, to prevent problems dur
49
  wp_nonce_field('groups_create_save_' . $this->slug);
50
  }
51
 
 
 
 
 
52
  function create_screen_save() {
53
  global $bp;
54
 
@@ -59,6 +72,11 @@ if (class_exists('BP_Group_Extension')) :// Recommended, to prevent problems dur
59
  groups_update_groupmeta($bp->groups->new_group_id, 'bp_media_group_control_level', $_POST['bp_album_creation_control']);
60
  }
61
 
 
 
 
 
 
62
  function edit_screen() {
63
  global $bp_media;
64
  if (!bp_is_group_admin_screen($this->slug))
@@ -88,6 +106,12 @@ if (class_exists('BP_Group_Extension')) :// Recommended, to prevent problems dur
88
  wp_nonce_field('groups_edit_save_' . $this->slug);
89
  }
90
 
 
 
 
 
 
 
91
  function edit_screen_save() {
92
  global $bp, $bp_media;
93
 
@@ -115,6 +139,11 @@ if (class_exists('BP_Group_Extension')) :// Recommended, to prevent problems dur
115
  *
116
  * @since BuddyPress Media 2.3
117
  */
 
 
 
 
 
118
  function widget_display() {
119
  global $bp_media;
120
  ?>
@@ -128,9 +157,11 @@ if (class_exists('BP_Group_Extension')) :// Recommended, to prevent problems dur
128
  <?php
129
  }
130
 
 
131
 
 
132
 
133
- }
134
 
135
 
136
  endif; // class_exists( 'BP_Group_Extension' )
7
  if (class_exists('BP_Group_Extension')) :// Recommended, to prevent problems during upgrade or when Groups are disabled
8
 
9
  class BPMediaGroupsExtension extends BPMediaGroupElementExtension {
 
10
  /**
11
  * Constructor for the BP_Group_Extension adding values to the variables defined
12
  *
14
  *
15
  * @since BuddyPress Media 2.3
16
  */
17
+
18
+ /**
19
+ *
20
+ * @global type $bp
21
+ */
22
  function __construct() {
23
  global $bp;
24
+ $this->name = __(BP_MEDIA_LABEL, BP_MEDIA_TXT_DOMAIN);
25
  $this->slug = BP_MEDIA_SLUG;
26
  $this->create_step_position = 21;
27
  $this->nav_item_position = 31;
28
+ }
29
 
30
+ /**
31
+ *
32
+ * @global type $bp_media
33
+ * @return boolean
34
+ */
35
  function create_screen() {
36
  global $bp_media;
37
  if (!bp_is_group_creation_step($this->slug))
58
  wp_nonce_field('groups_create_save_' . $this->slug);
59
  }
60
 
61
+ /**
62
+ *
63
+ * @global type $bp
64
+ */
65
  function create_screen_save() {
66
  global $bp;
67
 
72
  groups_update_groupmeta($bp->groups->new_group_id, 'bp_media_group_control_level', $_POST['bp_album_creation_control']);
73
  }
74
 
75
+ /**
76
+ *
77
+ * @global type $bp_media
78
+ * @return boolean
79
+ */
80
  function edit_screen() {
81
  global $bp_media;
82
  if (!bp_is_group_admin_screen($this->slug))
106
  wp_nonce_field('groups_edit_save_' . $this->slug);
107
  }
108
 
109
+ /**
110
+ *
111
+ * @global type $bp
112
+ * @global type $bp_media
113
+ * @return boolean
114
+ */
115
  function edit_screen_save() {
116
  global $bp, $bp_media;
117
 
139
  *
140
  * @since BuddyPress Media 2.3
141
  */
142
+
143
+ /**
144
+ *
145
+ * @global type $bp_media
146
+ */
147
  function widget_display() {
148
  global $bp_media;
149
  ?>
157
  <?php
158
  }
159
 
160
+ }
161
 
162
+
163
 
164
+
165
 
166
 
167
  endif; // class_exists( 'BP_Group_Extension' )
app/main/group/dummy/BPMediaGroupAlbum.php CHANGED
@@ -1,17 +1,20 @@
1
  <?php
 
2
  /**
3
  * Description of BPMediaGroupImage
4
  *
5
  * @author faishal
6
  */
7
- if ( class_exists( 'BP_Group_Extension' ) ) :
8
- class BPMediaGroupAlbum extends BPMediaGroupElementExtension {
 
 
 
 
 
 
9
 
10
- function __construct() {
11
- parent::__construct(BP_MEDIA_ALBUMS_LABEL, BP_MEDIA_ALBUMS_SLUG);
12
- bp_register_group_extension("BPMediaGroupAlbum");
13
  }
14
 
15
- }
16
- endif;
17
  ?>
1
  <?php
2
+
3
  /**
4
  * Description of BPMediaGroupImage
5
  *
6
  * @author faishal
7
  */
8
+ if (class_exists('BP_Group_Extension')) :
9
+
10
+ class BPMediaGroupAlbum extends BPMediaGroupElementExtension {
11
+
12
+ function __construct() {
13
+ parent::__construct(BP_MEDIA_ALBUMS_LABEL, BP_MEDIA_ALBUMS_SLUG);
14
+ bp_register_group_extension("BPMediaGroupAlbum");
15
+ }
16
 
 
 
 
17
  }
18
 
19
+ endif;
 
20
  ?>
app/main/includes/BPMediaActions.php CHANGED
@@ -7,6 +7,10 @@
7
  */
8
  class BPMediaActions {
9
 
 
 
 
 
10
  function __construct() {
11
  add_action('bp_media_before_content', 'BPMediaActions::show_messages');
12
  add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'), 11);
@@ -34,6 +38,13 @@ class BPMediaActions {
34
  *
35
  * @since BuddyPress Media 2.0
36
  */
 
 
 
 
 
 
 
37
  static function handle_uploads() {
38
  global $bp, $bp_media_options;
39
  $bp_media_options = get_site_option('bp_media_options', array(
@@ -105,6 +116,11 @@ class BPMediaActions {
105
  *
106
  * @since BuddyPress Media 2.0
107
  */
 
 
 
 
 
108
  static function show_messages() {
109
  global $bp;
110
  if (is_array($bp->{BP_MEDIA_SLUG}->messages)) {
@@ -122,6 +138,11 @@ class BPMediaActions {
122
  *
123
  * @since BuddyPress Media 2.0
124
  */
 
 
 
 
 
125
  function enqueue_scripts_styles() {
126
 
127
  wp_enqueue_script('jquery-ui-tabs');
@@ -149,6 +170,13 @@ class BPMediaActions {
149
  wp_enqueue_style('bp-media-default', BP_MEDIA_URL . 'app/assets/css/main.css');
150
  }
151
 
 
 
 
 
 
 
 
152
  static function delete_activity_handler($args) {
153
  remove_action('bp_media_before_delete_media', 'BPMediaActions::delete_media_handler');
154
  global $bp_media_count, $wpdb;
@@ -184,6 +212,11 @@ class BPMediaActions {
184
  }
185
  }
186
 
 
 
 
 
 
187
  static function delete_media_handler($media_id) {
188
  /* @var $media BPMediaHostWordpress */
189
  remove_action('bp_before_activity_delete', 'BPMediaActions::delete_activity_handler');
@@ -200,6 +233,13 @@ class BPMediaActions {
200
  *
201
  * @since BuddyPress Media 2.0
202
  */
 
 
 
 
 
 
 
203
  function set_query() {
204
  global $bp, $bp_media_query, $bp_media_posts_per_page;
205
  switch ($bp->current_action) {
@@ -243,6 +283,13 @@ class BPMediaActions {
243
  *
244
  * @since BuddyPress Media 2.0
245
  */
 
 
 
 
 
 
 
246
  function action_buttons() {
247
  if (!in_array('bp_media_current_entry', $GLOBALS))
248
  return false;
@@ -282,6 +329,13 @@ class BPMediaActions {
282
  *
283
  * @since BuddyPress Media 2.0
284
  */
 
 
 
 
 
 
 
285
  static function init_count($user = null) {
286
  global $bp_media_count;
287
  if (!$user)
@@ -352,6 +406,12 @@ class BPMediaActions {
352
  *
353
  * @since BuddyPress Media 2.2
354
  */
 
 
 
 
 
 
355
  function albums_set_query() {
356
  global $bp, $bp_media_albums_query;
357
  if (isset($bp->action_variables) && is_array($bp->action_variables) && isset($bp->action_variables[0]) && $bp->action_variables[0] == 'page' && isset($bp->action_variables[1]) && is_numeric($bp->action_variables[1])) {
@@ -375,6 +435,13 @@ class BPMediaActions {
375
  /**
376
  * Function to return the media for the ajax requests
377
  */
 
 
 
 
 
 
 
378
  function load_more() {
379
 
380
  global $bp, $bp_media_query, $bp_media_posts_per_page;
@@ -462,6 +529,12 @@ class BPMediaActions {
462
  die();
463
  }
464
 
 
 
 
 
 
 
465
  function delete_attachment_handler($attachment_id) {
466
  if (get_post_meta($attachment_id, 'bp-media-key')) {
467
  do_action('bp_media_before_delete_media', $attachment_id);
@@ -531,7 +604,10 @@ class BPMediaActions {
531
 
532
  //add_action('bp_after_activity_post_form','add_new_from_activity');
533
 
534
-
 
 
 
535
  function album_create_activity($album) {
536
  /* @var $album BP_Media_Album */
537
  $args = array(
@@ -546,15 +622,29 @@ class BPMediaActions {
546
  update_post_meta($album->get_id(), 'bp_media_child_activity', $activity_id);
547
  }
548
 
 
 
 
 
549
  function album_activity_update($album_id) {
550
  BPMediaFunction::update_album_activity($album_id);
551
  }
552
 
 
 
 
 
553
  function album_activity_sync($media_id) {
554
  $album_id = wp_get_post_parent_id($media_id);
555
  BPMediaFunction::update_album_activity($album_id, false, $media_id);
556
  }
557
 
 
 
 
 
 
 
558
  static function activity_create_after_add_media($media, $hidden = false) {
559
  if (function_exists('bp_activity_add')) {
560
  if (!is_object($media)) {
@@ -564,8 +654,8 @@ class BPMediaActions {
564
  return false;
565
  }
566
  }
567
- $activity_content = $media->get_media_activity_content();
568
- new BPMediaLog($activity_content);
569
  $args = array(
570
  'action' => apply_filters('bp_media_added_media', sprintf(__('%1$s added a %2$s', BP_MEDIA_TXT_DOMAIN), bp_core_get_userlink($media->get_author()), '<a href="' . $media->get_url() . '">' . $media->get_media_activity_type() . '</a>')),
571
  'content' => $activity_content,
7
  */
8
  class BPMediaActions {
9
 
10
+ /**
11
+ *
12
+ * @global type $bp_media_options
13
+ */
14
  function __construct() {
15
  add_action('bp_media_before_content', 'BPMediaActions::show_messages');
16
  add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'), 11);
38
  *
39
  * @since BuddyPress Media 2.0
40
  */
41
+
42
+ /**
43
+ *
44
+ * @global type $bp
45
+ * @global type $bp_media_options
46
+ * @return type
47
+ */
48
  static function handle_uploads() {
49
  global $bp, $bp_media_options;
50
  $bp_media_options = get_site_option('bp_media_options', array(
116
  *
117
  * @since BuddyPress Media 2.0
118
  */
119
+
120
+ /**
121
+ *
122
+ * @global type $bp
123
+ */
124
  static function show_messages() {
125
  global $bp;
126
  if (is_array($bp->{BP_MEDIA_SLUG}->messages)) {
138
  *
139
  * @since BuddyPress Media 2.0
140
  */
141
+
142
+ /**
143
+ *
144
+ * @global type $bp
145
+ */
146
  function enqueue_scripts_styles() {
147
 
148
  wp_enqueue_script('jquery-ui-tabs');
170
  wp_enqueue_style('bp-media-default', BP_MEDIA_URL . 'app/assets/css/main.css');
171
  }
172
 
173
+ /**
174
+ *
175
+ * @global type $bp_media_count
176
+ * @global type $wpdb
177
+ * @param type $args
178
+ * @return boolean
179
+ */
180
  static function delete_activity_handler($args) {
181
  remove_action('bp_media_before_delete_media', 'BPMediaActions::delete_media_handler');
182
  global $bp_media_count, $wpdb;
212
  }
213
  }
214
 
215
+ /**
216
+ *
217
+ * @param type $media_id
218
+ * @return boolean
219
+ */
220
  static function delete_media_handler($media_id) {
221
  /* @var $media BPMediaHostWordpress */
222
  remove_action('bp_before_activity_delete', 'BPMediaActions::delete_activity_handler');
233
  *
234
  * @since BuddyPress Media 2.0
235
  */
236
+
237
+ /**
238
+ *
239
+ * @global type $bp
240
+ * @global WP_Query $bp_media_query
241
+ * @global type $bp_media_posts_per_page
242
+ */
243
  function set_query() {
244
  global $bp, $bp_media_query, $bp_media_posts_per_page;
245
  switch ($bp->current_action) {
283
  *
284
  * @since BuddyPress Media 2.0
285
  */
286
+
287
+ /**
288
+ *
289
+ * @global type $bp_media_current_entry
290
+ * @global type $bp_media_options
291
+ * @return boolean
292
+ */
293
  function action_buttons() {
294
  if (!in_array('bp_media_current_entry', $GLOBALS))
295
  return false;
329
  *
330
  * @since BuddyPress Media 2.0
331
  */
332
+
333
+ /**
334
+ *
335
+ * @global type $bp_media_count
336
+ * @param type $user
337
+ * @return boolean
338
+ */
339
  static function init_count($user = null) {
340
  global $bp_media_count;
341
  if (!$user)
406
  *
407
  * @since BuddyPress Media 2.2
408
  */
409
+
410
+ /**
411
+ *
412
+ * @global type $bp
413
+ * @global WP_Query $bp_media_albums_query
414
+ */
415
  function albums_set_query() {
416
  global $bp, $bp_media_albums_query;
417
  if (isset($bp->action_variables) && is_array($bp->action_variables) && isset($bp->action_variables[0]) && $bp->action_variables[0] == 'page' && isset($bp->action_variables[1]) && is_numeric($bp->action_variables[1])) {
435
  /**
436
  * Function to return the media for the ajax requests
437
  */
438
+
439
+ /**
440
+ *
441
+ * @global type $bp
442
+ * @global WP_Query $bp_media_query
443
+ * @global type $bp_media_posts_per_page
444
+ */
445
  function load_more() {
446
 
447
  global $bp, $bp_media_query, $bp_media_posts_per_page;
529
  die();
530
  }
531
 
532
+ /**
533
+ *
534
+ * @global type $bp_media_count
535
+ * @param type $attachment_id
536
+ * @return boolean
537
+ */
538
  function delete_attachment_handler($attachment_id) {
539
  if (get_post_meta($attachment_id, 'bp-media-key')) {
540
  do_action('bp_media_before_delete_media', $attachment_id);
604
 
605
  //add_action('bp_after_activity_post_form','add_new_from_activity');
606
 
607
+ /**
608
+ *
609
+ * @param type $album
610
+ */
611
  function album_create_activity($album) {
612
  /* @var $album BP_Media_Album */
613
  $args = array(
622
  update_post_meta($album->get_id(), 'bp_media_child_activity', $activity_id);
623
  }
624
 
625
+ /**
626
+ *
627
+ * @param type $album_id
628
+ */
629
  function album_activity_update($album_id) {
630
  BPMediaFunction::update_album_activity($album_id);
631
  }
632
 
633
+ /**
634
+ *
635
+ * @param type $media_id
636
+ */
637
  function album_activity_sync($media_id) {
638
  $album_id = wp_get_post_parent_id($media_id);
639
  BPMediaFunction::update_album_activity($album_id, false, $media_id);
640
  }
641
 
642
+ /**
643
+ *
644
+ * @param BPMediaHostWordpress $media
645
+ * @param type $hidden
646
+ * @return boolean
647
+ */
648
  static function activity_create_after_add_media($media, $hidden = false) {
649
  if (function_exists('bp_activity_add')) {
650
  if (!is_object($media)) {
654
  return false;
655
  }
656
  }
657
+ $activity_content = $media->get_media_activity_content();
658
+ new BPMediaLog($activity_content);
659
  $args = array(
660
  'action' => apply_filters('bp_media_added_media', sprintf(__('%1$s added a %2$s', BP_MEDIA_TXT_DOMAIN), bp_core_get_userlink($media->get_author()), '<a href="' . $media->get_url() . '">' . $media->get_media_activity_type() . '</a>')),
661
  'content' => $activity_content,
app/main/includes/BPMediaComponent.php CHANGED
@@ -12,103 +12,117 @@
12
  */
13
  class BPMediaComponent extends BP_Component {
14
 
15
- /**
16
- * Hold the messages generated during initialization process and will be shown on the screen functions
17
- *
18
- * @since BuddyPress Media 2.0
19
- */
20
- var $messages = array(
21
- 'error' => array( ),
22
- 'info' => array( ),
23
- 'updated' => array( )
24
- );
25
-
26
- /**
27
- * Constructor for the BuddyPress Media
28
- *
29
- * @since BuddyPress Media 2.0
30
- */
31
- function __construct() {
32
- global $bp;
33
- parent::start( BP_MEDIA_SLUG, BP_MEDIA_LABEL, BP_MEDIA_PATH );
34
- $this->includes();
35
- $bp->active_components[ $this->id ] = '1';
36
- add_action( 'init', array( &$this, 'register_post_types' ),10);
37
- }
38
-
39
- /**
40
- * Includes the files required for the BuddyPress Media and calls the parent class' includes function
41
- *
42
- * @since BuddyPress Media 2.0
43
- */
44
- function includes() {
45
- $inc_path_prefix = 'app/main/includes/';
46
- $includes = array(
47
- $inc_path_prefix . 'bp-media-functions.php',
48
- $inc_path_prefix . 'bp-media-template-functions.php',
49
- $inc_path_prefix . 'bp-media-interface.php',
50
- $inc_path_prefix . 'bp-media-shortcodes.php',
51
- $inc_path_prefix . 'bp-media-widgets.php'
52
- //$inc_path_prefix . 'BPMediaFilter.php',
53
- );
54
- parent::includes( $includes );
55
- do_action( 'bp_media_init' );
56
- }
57
-
58
- /**
59
- * Initializes the global variables of the BuddyPress Media and its parent class.
60
- */
61
- function setup_globals() {
62
- global $bp;
63
- $globals = array(
64
- 'slug' => BP_MEDIA_SLUG,
65
- 'root_slug' => isset( $bp->pages->{$this->id}->slug ) ? $bp->pages->{$this->id}->slug : BP_MEDIA_SLUG,
66
- /* 'has_directory' => true, /* Set to false if not required */
67
- 'search_string' => __( 'Search Media...', BP_MEDIA_TXT_DOMAIN ),
68
- );
69
- parent::setup_globals( $globals );
70
- }
71
-
72
- function setup_nav() {
73
- /* Add 'Media' to the main navigation */
74
- global $bp;
75
- $bp_media_upload = new BPMediaUploadScreen( 'upload', BP_MEDIA_UPLOAD_SLUG );
76
-
77
- $bp_media_image = new BPMediaScreen( 'image', BP_MEDIA_IMAGES_SLUG );
78
- $bp_media_video = new BPMediaScreen( 'video', BP_MEDIA_VIDEOS_SLUG );
79
- $bp_media_audio = new BPMediaScreen( 'audio', BP_MEDIA_AUDIO_SLUG );
80
-
81
- $bp_media_album = new BPMediaAlbumScreen( 'album', BP_MEDIA_ALBUMS_SLUG );
82
- switch ( $bp->current_component ) {
83
- case BP_MEDIA_IMAGES_SLUG:
84
- if ( is_numeric( $bp->current_action ) ) {
85
- $bp->action_variables[ 0 ] = $bp->current_action;
86
- $bp->current_action = BP_MEDIA_IMAGES_ENTRY_SLUG;
87
- }
88
- break;
89
- case BP_MEDIA_AUDIO_SLUG:
90
- if ( is_numeric( $bp->current_action ) ) {
91
- $bp->action_variables[ 0 ] = $bp->current_action;
92
- $bp->current_action = BP_MEDIA_AUDIO_ENTRY_SLUG;
93
- }
94
- break;
95
- case BP_MEDIA_VIDEOS_SLUG:
96
- if ( is_numeric( $bp->current_action ) ) {
97
- $bp->action_variables[ 0 ] = $bp->current_action;
98
- $bp->current_action = BP_MEDIA_VIDEOS_ENTRY_SLUG;
99
- }
100
- break;
101
- case BP_MEDIA_ALBUMS_SLUG:
102
- if ( is_numeric( $bp->current_action ) ) {
103
- $bp->action_variables[ 0 ] = $bp->current_action;
104
- $bp->current_action = BP_MEDIA_ALBUMS_ENTRY_SLUG;
105
- }
106
- break;
107
- }
108
-
109
-
110
-
111
- // -------------- Removed Upload as default tab ------------- //
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  // if ( bp_is_my_profile() ) {
113
  // $main_nav = array(
114
  // 'name' => BP_MEDIA_LABEL,
@@ -118,249 +132,249 @@ class BPMediaComponent extends BP_Component {
118
  // 'default_subnav_slug' => BP_MEDIA_UPLOAD_SLUG
119
  // );
120
  // } else {
121
- $main_nav = array(
122
- 'name' => __(BP_MEDIA_LABEL,BP_MEDIA_TXT_DOMAIN),
123
- 'slug' => BP_MEDIA_SLUG,
124
- 'position' => 80,
125
- 'screen_function' => array( $bp_media_image, 'screen' ),
126
- 'default_subnav_slug' => BP_MEDIA_IMAGES_SLUG
127
- );
128
  // }
129
- $sub_nav[ ] = array();
130
- parent::setup_nav( $main_nav, $sub_nav );
131
- bp_core_new_nav_item( array(
132
- 'name' => __(BP_MEDIA_IMAGES_LABEL,BP_MEDIA_TXT_DOMAIN),
133
- 'slug' => BP_MEDIA_IMAGES_SLUG,
134
- 'screen_function' => array( $bp_media_image, 'screen' ),
135
- ) );
136
-
137
-
138
- bp_core_new_subnav_item( array(
139
- 'name' => 'View', /* Display name for the nav item(It won't be shown anywhere) */
140
- 'slug' => BP_MEDIA_IMAGES_ENTRY_SLUG, /* URL slug for the nav item */
141
- 'parent_slug' => BP_MEDIA_IMAGES_SLUG, /* URL slug of the parent nav item */
142
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_IMAGES_SLUG ), /* URL of the parent item */
143
- 'position' => 90, /* Index of where this nav item should be positioned */
144
- 'screen_function' => array( $bp_media_image, 'screen' ), /* The name of the function to run when clicked */
145
- ) );
146
-
147
- bp_core_new_subnav_item( array(
148
- 'name' => 'Edit', /* Display name for the nav item(It won't be shown anywhere) */
149
- 'slug' => BP_MEDIA_IMAGES_EDIT_SLUG, /* URL slug for the nav item */
150
- 'parent_slug' => BP_MEDIA_IMAGES_SLUG, /* URL slug of the parent nav item */
151
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_IMAGES_SLUG ), /* URL of the parent item */
152
- 'position' => 90, /* Index of where this nav item should be positioned */
153
- 'screen_function' => array( $bp_media_image, 'edit_screen' ), /* The name of the function to run when clicked */
154
- ) );
155
-
156
- bp_core_new_subnav_item( array(
157
- 'name' => 'Delete', /* Display name for the nav item(It won't be shown anywhere) */
158
- 'slug' => BP_MEDIA_DELETE_SLUG, /* URL slug for the nav item */
159
- 'parent_slug' => BP_MEDIA_IMAGES_SLUG, /* URL slug of the parent nav item */
160
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_IMAGES_SLUG ), /* URL of the parent item */
161
- 'position' => 90, /* Index of where this nav item should be positioned */
162
- 'screen_function' => array( $bp_media_image, 'screen' ), /* The name of the function to run when clicked */
163
- ) );
164
-
165
- bp_core_new_subnav_item( array(
166
- 'name' => 'Page', /* Display name for the nav item(It won't be shown anywhere) */
167
- 'slug' => 'page', /* URL slug for the nav item */
168
- 'parent_slug' => BP_MEDIA_IMAGES_SLUG, /* URL slug of the parent nav item */
169
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_IMAGES_SLUG ), /* URL of the parent item */
170
- 'position' => 90, /* Index of where this nav item should be positioned */
171
- 'screen_function' => array( $bp_media_image, 'screen' ), /* The name of the function to run when clicked */
172
- ) );
173
-
174
-
175
- bp_core_new_nav_item( array(
176
- 'name' => __(BP_MEDIA_VIDEOS_LABEL,BP_MEDIA_TXT_DOMAIN),
177
- 'slug' => BP_MEDIA_VIDEOS_SLUG,
178
- 'screen_function' => array( $bp_media_video, 'screen' )
179
- ) );
180
-
181
- bp_core_new_subnav_item( array(
182
- 'name' => 'Watch', /* Display name for the nav item(It won't be shown anywhere) */
183
- 'slug' => BP_MEDIA_VIDEOS_ENTRY_SLUG, /* URL slug for the nav item */
184
- 'parent_slug' => BP_MEDIA_VIDEOS_SLUG, /* URL slug of the parent nav item */
185
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_VIDEOS_SLUG ), /* URL of the parent item */
186
- 'position' => 90, /* Index of where this nav item should be positioned */
187
- 'screen_function' => array( $bp_media_video, 'screen' ), /* The name of the function to run when clicked */
188
- ) );
189
-
190
- bp_core_new_subnav_item( array(
191
- 'name' => 'Edit', /* Display name for the nav item(It won't be shown anywhere) */
192
- 'slug' => BP_MEDIA_VIDEOS_EDIT_SLUG, /* URL slug for the nav item */
193
- 'parent_slug' => BP_MEDIA_VIDEOS_SLUG, /* URL slug of the parent nav item */
194
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_VIDEOS_SLUG ), /* URL of the parent item */
195
- 'position' => 90, /* Index of where this nav item should be positioned */
196
- 'screen_function' => array( $bp_media_video, 'edit_screen' ), /* The name of the function to run when clicked */
197
- ) );
198
-
199
- bp_core_new_subnav_item( array(
200
- 'name' => 'Delete', /* Display name for the nav item(It won't be shown anywhere) */
201
- 'slug' => BP_MEDIA_DELETE_SLUG, /* URL slug for the nav item */
202
- 'parent_slug' => BP_MEDIA_VIDEOS_SLUG, /* URL slug of the parent nav item */
203
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_VIDEOS_SLUG ), /* URL of the parent item */
204
- 'position' => 90, /* Index of where this nav item should be positioned */
205
- 'screen_function' => array( $bp_media_video, 'screen' ), /* The name of the function to run when clicked */
206
- ) );
207
-
208
- bp_core_new_subnav_item( array(
209
- 'name' => 'Page', /* Display name for the nav item(It won't be shown anywhere) */
210
- 'slug' => 'page', /* URL slug for the nav item */
211
- 'parent_slug' => BP_MEDIA_VIDEOS_SLUG, /* URL slug of the parent nav item */
212
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_VIDEOS_SLUG ), /* URL of the parent item */
213
- 'position' => 90, /* Index of where this nav item should be positioned */
214
- 'screen_function' => array( $bp_media_video, 'screen' ), /* The name of the function to run when clicked */
215
- ) );
216
-
217
-
218
- bp_core_new_nav_item( array(
219
- 'name' => __(BP_MEDIA_AUDIO_LABEL,BP_MEDIA_TXT_DOMAIN),
220
- 'slug' => BP_MEDIA_AUDIO_SLUG,
221
- 'screen_function' => array( $bp_media_audio, 'screen' )
222
- ) );
223
-
224
- bp_core_new_subnav_item( array(
225
- 'name' => 'Listen', /* Display name for the nav item(It won't be shown anywhere) */
226
- 'slug' => BP_MEDIA_AUDIO_ENTRY_SLUG, /* URL slug for the nav item */
227
- 'parent_slug' => BP_MEDIA_AUDIO_SLUG, /* URL slug of the parent nav item */
228
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_AUDIO_SLUG ), /* URL of the parent item */
229
- 'position' => 90, /* Index of where this nav item should be positioned */
230
- 'screen_function' => array( $bp_media_audio, 'screen' ), /* The name of the function to run when clicked */
231
- ) );
232
-
233
- bp_core_new_subnav_item( array(
234
- 'name' => 'Edit', /* Display name for the nav item(It won't be shown anywhere) */
235
- 'slug' => BP_MEDIA_AUDIO_EDIT_SLUG, /* URL slug for the nav item */
236
- 'parent_slug' => BP_MEDIA_AUDIO_SLUG, /* URL slug of the parent nav item */
237
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_AUDIO_SLUG ), /* URL of the parent item */
238
- 'position' => 90, /* Index of where this nav item should be positioned */
239
- 'screen_function' => array( $bp_media_audio, 'edit_screen' ), /* The name of the function to run when clicked */
240
- ) );
241
-
242
- bp_core_new_subnav_item( array(
243
- 'name' => 'Delete', /* Display name for the nav item(It won't be shown anywhere) */
244
- 'slug' => BP_MEDIA_DELETE_SLUG, /* URL slug for the nav item */
245
- 'parent_slug' => BP_MEDIA_AUDIO_SLUG, /* URL slug of the parent nav item */
246
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_AUDIO_SLUG ), /* URL of the parent item */
247
- 'position' => 90, /* Index of where this nav item should be positioned */
248
- 'screen_function' => array( $bp_media_audio, 'screen' ), /* The name of the function to run when clicked */
249
- ) );
250
-
251
- bp_core_new_subnav_item( array(
252
- 'name' => 'Page', /* Display name for the nav item(It won't be shown anywhere) */
253
- 'slug' => 'page', /* URL slug for the nav item */
254
- 'parent_slug' => BP_MEDIA_AUDIO_SLUG, /* URL slug of the parent nav item */
255
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_AUDIO_SLUG ), /* URL of the parent item */
256
- 'position' => 90, /* Index of where this nav item should be positioned */
257
- 'screen_function' => array( $bp_media_audio, 'screen' ), /* The name of the function to run when clicked */
258
- ) );
259
-
260
-
261
- bp_core_new_nav_item( array(
262
- 'name' => __(BP_MEDIA_ALBUMS_LABEL,BP_MEDIA_TXT_DOMAIN),
263
- 'slug' => BP_MEDIA_ALBUMS_SLUG,
264
- 'screen_function' => array( $bp_media_album, 'screen' ),
265
- ) );
266
-
267
- bp_core_new_subnav_item( array(
268
- 'name' => 'View', /* Display name for the nav item(It won't be shown anywhere) */
269
- 'slug' => BP_MEDIA_ALBUMS_ENTRY_SLUG, /* URL slug for the nav item */
270
- 'parent_slug' => BP_MEDIA_ALBUMS_SLUG, /* URL slug of the parent nav item */
271
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_ALBUMS_SLUG ), /* URL of the parent item */
272
- 'position' => 90, /* Index of where this nav item should be positioned */
273
- 'screen_function' => array( $bp_media_album, 'screen' ), /* The name of the function to run when clicked */
274
- ) );
275
-
276
- bp_core_new_subnav_item( array(
277
- 'name' => 'Edit', /* Display name for the nav item(It won't be shown anywhere) */
278
- 'slug' => BP_MEDIA_ALBUMS_EDIT_SLUG, /* URL slug for the nav item */
279
- 'parent_slug' => BP_MEDIA_ALBUMS_SLUG, /* URL slug of the parent nav item */
280
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_ALBUMS_SLUG ), /* URL of the parent item */
281
- 'position' => 90, /* Index of where this nav item should be positioned */
282
- 'screen_function' => array( $bp_media_album, 'edit_screen' ), /* The name of the function to run when clicked */
283
- ) );
284
-
285
- bp_core_new_subnav_item( array(
286
- 'name' => 'Delete', /* Display name for the nav item(It won't be shown anywhere) */
287
- 'slug' => BP_MEDIA_DELETE_SLUG, /* URL slug for the nav item */
288
- 'parent_slug' => BP_MEDIA_ALBUMS_SLUG, /* URL slug of the parent nav item */
289
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_ALBUMS_SLUG ), /* URL of the parent item */
290
- 'position' => 90, /* Index of where this nav item should be positioned */
291
- 'screen_function' => array( $bp_media_album, 'screen' ), /* The name of the function to run when clicked */
292
- ) );
293
-
294
- bp_core_new_subnav_item( array(
295
- 'name' => 'Page', /* Display name for the nav item(It won't be shown anywhere) */
296
- 'slug' => 'page', /* URL slug for the nav item */
297
- 'parent_slug' => BP_MEDIA_ALBUMS_SLUG, /* URL slug of the parent nav item */
298
- 'parent_url' => trailingslashit( bp_loggedin_user_domain() . BP_MEDIA_ALBUMS_SLUG ), /* URL of the parent item */
299
- 'position' => 90, /* Index of where this nav item should be positioned */
300
- 'screen_function' => array( $bp_media_album, 'screen' ), /* The name of the function to run when clicked */
301
- ) );
302
- bp_core_new_nav_item( array(
303
- 'name' => __(BP_MEDIA_UPLOAD_LABEL,BP_MEDIA_TXT_DOMAIN),
304
- 'slug' => BP_MEDIA_UPLOAD_SLUG,
305
- 'screen_function' => array( $bp_media_upload, 'upload_screen' ),
306
- 'user_has_access' => bp_is_my_profile()
307
- ) );
308
- }
309
-
310
- /**
311
- * Creating a custom post type album for BuddyPress Media
312
- */
313
- function register_post_types() {
314
- $labels = array(
315
- 'name' => __( 'Albums', BP_MEDIA_TXT_DOMAIN ),
316
- 'singular_name' => __( 'Album', BP_MEDIA_TXT_DOMAIN ),
317
- 'add_new' => __( 'Create', BP_MEDIA_TXT_DOMAIN ),
318
- 'add_new_item' => __( 'Create Album', BP_MEDIA_TXT_DOMAIN ),
319
- 'edit_item' => __( 'Edit Album', BP_MEDIA_TXT_DOMAIN ),
320
- 'new_item' => __( 'New Album', BP_MEDIA_TXT_DOMAIN ),
321
- 'all_items' => __( 'All Albums', BP_MEDIA_TXT_DOMAIN ),
322
- 'view_item' => __( 'View Album', BP_MEDIA_TXT_DOMAIN ),
323
- 'search_items' => __( 'Search Albums', BP_MEDIA_TXT_DOMAIN ),
324
- 'not_found' => __( 'No album found', BP_MEDIA_TXT_DOMAIN ),
325
- 'not_found_in_trash' => __( 'No album found in Trash', BP_MEDIA_TXT_DOMAIN ),
326
- 'parent_item_colon' => '',
327
- 'menu_name' => __( 'Albums', BP_MEDIA_TXT_DOMAIN )
328
- );
329
-
330
- $args = array(
331
- 'labels' => $labels,
332
- 'public' => true,
333
- 'publicly_queryable' => true,
334
- 'show_ui' => false,
335
- 'show_in_menu' => false,
336
- 'query_var' => true,
337
- 'capability_type' => 'post',
338
- 'has_archive' => true,
339
- 'hierarchical' => false,
340
- 'menu_position' => null,
341
- 'supports' => array( 'title', 'author', 'thumbnail', 'excerpt', 'comments' )
342
- );
343
- register_post_type( 'bp_media_album', $args );
344
- global $bp_media;
345
- /* Set up labels for the post type */
346
- $labels = array(
347
- 'name' => __( 'Media', BP_MEDIA_TXT_DOMAIN),
348
- 'singular' => __( 'Media', BP_MEDIA_TXT_DOMAIN ),
349
- 'add_new' => __( 'Add New Media', BP_MEDIA_TXT_DOMAIN )
350
- );
351
-
352
- /* Set up the argument array for register_post_type() */
353
- $args = array(
354
- 'label' => __( 'Media', BP_MEDIA_TXT_DOMAIN ),
355
- 'labels' => $labels,
356
- 'description' => __('BuddyPress Media\'s Media Files',BP_MEDIA_TXT_DOMAIN),
357
- 'public' => true,
358
- 'show_ui' => false,
359
- 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'custom-fields' )
360
- );
361
- register_post_type( 'bp_media', $args );
362
- parent::register_post_types();
363
- }
364
 
365
  }
366
 
12
  */
13
  class BPMediaComponent extends BP_Component {
14
 
15
+ /**
16
+ * Hold the messages generated during initialization process and will be shown on the screen functions
17
+ *
18
+ * @since BuddyPress Media 2.0
19
+ */
20
+ var $messages = array(
21
+ 'error' => array(),
22
+ 'info' => array(),
23
+ 'updated' => array()
24
+ );
25
+
26
+ /**
27
+ * Constructor for the BuddyPress Media
28
+ *
29
+ * @since BuddyPress Media 2.0
30
+ */
31
+
32
+ /**
33
+ *
34
+ * @global type $bp
35
+ */
36
+ function __construct() {
37
+ global $bp;
38
+ parent::start(BP_MEDIA_SLUG, BP_MEDIA_LABEL, BP_MEDIA_PATH);
39
+ $this->includes();
40
+ $bp->active_components[$this->id] = '1';
41
+ add_action('init', array(&$this, 'register_post_types'), 10);
42
+ }
43
+
44
+ /**
45
+ * Includes the files required for the BuddyPress Media and calls the parent class' includes function
46
+ *
47
+ * @since BuddyPress Media 2.0
48
+ */
49
+ function includes() {
50
+ $inc_path_prefix = 'app/main/includes/';
51
+ $includes = array(
52
+ $inc_path_prefix . 'bp-media-functions.php',
53
+ $inc_path_prefix . 'bp-media-template-functions.php',
54
+ $inc_path_prefix . 'bp-media-interface.php',
55
+ $inc_path_prefix . 'bp-media-shortcodes.php',
56
+ $inc_path_prefix . 'bp-media-widgets.php'
57
+ //$inc_path_prefix . 'BPMediaFilter.php',
58
+ );
59
+ parent::includes($includes);
60
+ do_action('bp_media_init');
61
+ }
62
+
63
+ /**
64
+ * Initializes the global variables of the BuddyPress Media and its parent class.
65
+ */
66
+
67
+ /**
68
+ *
69
+ * @global type $bp
70
+ */
71
+ function setup_globals() {
72
+ global $bp;
73
+ $globals = array(
74
+ 'slug' => BP_MEDIA_SLUG,
75
+ 'root_slug' => isset($bp->pages->{$this->id}->slug) ? $bp->pages->{$this->id}->slug : BP_MEDIA_SLUG,
76
+ /* 'has_directory' => true, /* Set to false if not required */
77
+ 'search_string' => __('Search Media...', BP_MEDIA_TXT_DOMAIN),
78
+ );
79
+ parent::setup_globals($globals);
80
+ }
81
+
82
+ /**
83
+ *
84
+ * @global type $bp
85
+ */
86
+ function setup_nav() {
87
+ /* Add 'Media' to the main navigation */
88
+ global $bp;
89
+ $bp_media_upload = new BPMediaUploadScreen('upload', BP_MEDIA_UPLOAD_SLUG);
90
+
91
+ $bp_media_image = new BPMediaScreen('image', BP_MEDIA_IMAGES_SLUG);
92
+ $bp_media_video = new BPMediaScreen('video', BP_MEDIA_VIDEOS_SLUG);
93
+ $bp_media_audio = new BPMediaScreen('audio', BP_MEDIA_AUDIO_SLUG);
94
+
95
+ $bp_media_album = new BPMediaAlbumScreen('album', BP_MEDIA_ALBUMS_SLUG);
96
+ switch ($bp->current_component) {
97
+ case BP_MEDIA_IMAGES_SLUG:
98
+ if (is_numeric($bp->current_action)) {
99
+ $bp->action_variables[0] = $bp->current_action;
100
+ $bp->current_action = BP_MEDIA_IMAGES_ENTRY_SLUG;
101
+ }
102
+ break;
103
+ case BP_MEDIA_AUDIO_SLUG:
104
+ if (is_numeric($bp->current_action)) {
105
+ $bp->action_variables[0] = $bp->current_action;
106
+ $bp->current_action = BP_MEDIA_AUDIO_ENTRY_SLUG;
107
+ }
108
+ break;
109
+ case BP_MEDIA_VIDEOS_SLUG:
110
+ if (is_numeric($bp->current_action)) {
111
+ $bp->action_variables[0] = $bp->current_action;
112
+ $bp->current_action = BP_MEDIA_VIDEOS_ENTRY_SLUG;
113
+ }
114
+ break;
115
+ case BP_MEDIA_ALBUMS_SLUG:
116
+ if (is_numeric($bp->current_action)) {
117
+ $bp->action_variables[0] = $bp->current_action;
118
+ $bp->current_action = BP_MEDIA_ALBUMS_ENTRY_SLUG;
119
+ }
120
+ break;
121
+ }
122
+
123
+
124
+
125
+ // -------------- Removed Upload as default tab ------------- //
126
  // if ( bp_is_my_profile() ) {
127
  // $main_nav = array(
128
  // 'name' => BP_MEDIA_LABEL,
132
  // 'default_subnav_slug' => BP_MEDIA_UPLOAD_SLUG
133
  // );
134
  // } else {
135
+ $main_nav = array(
136
+ 'name' => __(BP_MEDIA_LABEL, BP_MEDIA_TXT_DOMAIN),
137
+ 'slug' => BP_MEDIA_SLUG,
138
+ 'position' => 80,
139
+ 'screen_function' => array($bp_media_image, 'screen'),
140
+ 'default_subnav_slug' => BP_MEDIA_IMAGES_SLUG
141
+ );
142
  // }
143
+ $sub_nav[] = array();
144
+ parent::setup_nav($main_nav, $sub_nav);
145
+ bp_core_new_nav_item(array(
146
+ 'name' => __(BP_MEDIA_IMAGES_LABEL, BP_MEDIA_TXT_DOMAIN),
147
+ 'slug' => BP_MEDIA_IMAGES_SLUG,
148
+ 'screen_function' => array($bp_media_image, 'screen'),
149
+ ));
150
+
151
+
152
+ bp_core_new_subnav_item(array(
153
+ 'name' => 'View', /* Display name for the nav item(It won't be shown anywhere) */
154
+ 'slug' => BP_MEDIA_IMAGES_ENTRY_SLUG, /* URL slug for the nav item */
155
+ 'parent_slug' => BP_MEDIA_IMAGES_SLUG, /* URL slug of the parent nav item */
156
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_IMAGES_SLUG), /* URL of the parent item */
157
+ 'position' => 90, /* Index of where this nav item should be positioned */
158
+ 'screen_function' => array($bp_media_image, 'screen'), /* The name of the function to run when clicked */
159
+ ));
160
+
161
+ bp_core_new_subnav_item(array(
162
+ 'name' => 'Edit', /* Display name for the nav item(It won't be shown anywhere) */
163
+ 'slug' => BP_MEDIA_IMAGES_EDIT_SLUG, /* URL slug for the nav item */
164
+ 'parent_slug' => BP_MEDIA_IMAGES_SLUG, /* URL slug of the parent nav item */
165
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_IMAGES_SLUG), /* URL of the parent item */
166
+ 'position' => 90, /* Index of where this nav item should be positioned */
167
+ 'screen_function' => array($bp_media_image, 'edit_screen'), /* The name of the function to run when clicked */
168
+ ));
169
+
170
+ bp_core_new_subnav_item(array(
171
+ 'name' => 'Delete', /* Display name for the nav item(It won't be shown anywhere) */
172
+ 'slug' => BP_MEDIA_DELETE_SLUG, /* URL slug for the nav item */
173
+ 'parent_slug' => BP_MEDIA_IMAGES_SLUG, /* URL slug of the parent nav item */
174
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_IMAGES_SLUG), /* URL of the parent item */
175
+ 'position' => 90, /* Index of where this nav item should be positioned */
176
+ 'screen_function' => array($bp_media_image, 'screen'), /* The name of the function to run when clicked */
177
+ ));
178
+
179
+ bp_core_new_subnav_item(array(
180
+ 'name' => 'Page', /* Display name for the nav item(It won't be shown anywhere) */
181
+ 'slug' => 'page', /* URL slug for the nav item */
182
+ 'parent_slug' => BP_MEDIA_IMAGES_SLUG, /* URL slug of the parent nav item */
183
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_IMAGES_SLUG), /* URL of the parent item */
184
+ 'position' => 90, /* Index of where this nav item should be positioned */
185
+ 'screen_function' => array($bp_media_image, 'screen'), /* The name of the function to run when clicked */
186
+ ));
187
+
188
+
189
+ bp_core_new_nav_item(array(
190
+ 'name' => __(BP_MEDIA_VIDEOS_LABEL, BP_MEDIA_TXT_DOMAIN),
191
+ 'slug' => BP_MEDIA_VIDEOS_SLUG,
192
+ 'screen_function' => array($bp_media_video, 'screen')
193
+ ));
194
+
195
+ bp_core_new_subnav_item(array(
196
+ 'name' => 'Watch', /* Display name for the nav item(It won't be shown anywhere) */
197
+ 'slug' => BP_MEDIA_VIDEOS_ENTRY_SLUG, /* URL slug for the nav item */
198
+ 'parent_slug' => BP_MEDIA_VIDEOS_SLUG, /* URL slug of the parent nav item */
199
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_VIDEOS_SLUG), /* URL of the parent item */
200
+ 'position' => 90, /* Index of where this nav item should be positioned */
201
+ 'screen_function' => array($bp_media_video, 'screen'), /* The name of the function to run when clicked */
202
+ ));
203
+
204
+ bp_core_new_subnav_item(array(
205
+ 'name' => 'Edit', /* Display name for the nav item(It won't be shown anywhere) */
206
+ 'slug' => BP_MEDIA_VIDEOS_EDIT_SLUG, /* URL slug for the nav item */
207
+ 'parent_slug' => BP_MEDIA_VIDEOS_SLUG, /* URL slug of the parent nav item */
208
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_VIDEOS_SLUG), /* URL of the parent item */
209
+ 'position' => 90, /* Index of where this nav item should be positioned */
210
+ 'screen_function' => array($bp_media_video, 'edit_screen'), /* The name of the function to run when clicked */
211
+ ));
212
+
213
+ bp_core_new_subnav_item(array(
214
+ 'name' => 'Delete', /* Display name for the nav item(It won't be shown anywhere) */
215
+ 'slug' => BP_MEDIA_DELETE_SLUG, /* URL slug for the nav item */
216
+ 'parent_slug' => BP_MEDIA_VIDEOS_SLUG, /* URL slug of the parent nav item */
217
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_VIDEOS_SLUG), /* URL of the parent item */
218
+ 'position' => 90, /* Index of where this nav item should be positioned */
219
+ 'screen_function' => array($bp_media_video, 'screen'), /* The name of the function to run when clicked */
220
+ ));
221
+
222
+ bp_core_new_subnav_item(array(
223
+ 'name' => 'Page', /* Display name for the nav item(It won't be shown anywhere) */
224
+ 'slug' => 'page', /* URL slug for the nav item */
225
+ 'parent_slug' => BP_MEDIA_VIDEOS_SLUG, /* URL slug of the parent nav item */
226
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_VIDEOS_SLUG), /* URL of the parent item */
227
+ 'position' => 90, /* Index of where this nav item should be positioned */
228
+ 'screen_function' => array($bp_media_video, 'screen'), /* The name of the function to run when clicked */
229
+ ));
230
+
231
+
232
+ bp_core_new_nav_item(array(
233
+ 'name' => __(BP_MEDIA_AUDIO_LABEL, BP_MEDIA_TXT_DOMAIN),
234
+ 'slug' => BP_MEDIA_AUDIO_SLUG,
235
+ 'screen_function' => array($bp_media_audio, 'screen')
236
+ ));
237
+
238
+ bp_core_new_subnav_item(array(
239
+ 'name' => 'Listen', /* Display name for the nav item(It won't be shown anywhere) */
240
+ 'slug' => BP_MEDIA_AUDIO_ENTRY_SLUG, /* URL slug for the nav item */
241
+ 'parent_slug' => BP_MEDIA_AUDIO_SLUG, /* URL slug of the parent nav item */
242
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_AUDIO_SLUG), /* URL of the parent item */
243
+ 'position' => 90, /* Index of where this nav item should be positioned */
244
+ 'screen_function' => array($bp_media_audio, 'screen'), /* The name of the function to run when clicked */
245
+ ));
246
+
247
+ bp_core_new_subnav_item(array(
248
+ 'name' => 'Edit', /* Display name for the nav item(It won't be shown anywhere) */
249
+ 'slug' => BP_MEDIA_AUDIO_EDIT_SLUG, /* URL slug for the nav item */
250
+ 'parent_slug' => BP_MEDIA_AUDIO_SLUG, /* URL slug of the parent nav item */
251
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_AUDIO_SLUG), /* URL of the parent item */
252
+ 'position' => 90, /* Index of where this nav item should be positioned */
253
+ 'screen_function' => array($bp_media_audio, 'edit_screen'), /* The name of the function to run when clicked */
254
+ ));
255
+
256
+ bp_core_new_subnav_item(array(
257
+ 'name' => 'Delete', /* Display name for the nav item(It won't be shown anywhere) */
258
+ 'slug' => BP_MEDIA_DELETE_SLUG, /* URL slug for the nav item */
259
+ 'parent_slug' => BP_MEDIA_AUDIO_SLUG, /* URL slug of the parent nav item */
260
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_AUDIO_SLUG), /* URL of the parent item */
261
+ 'position' => 90, /* Index of where this nav item should be positioned */
262
+ 'screen_function' => array($bp_media_audio, 'screen'), /* The name of the function to run when clicked */
263
+ ));
264
+
265
+ bp_core_new_subnav_item(array(
266
+ 'name' => 'Page', /* Display name for the nav item(It won't be shown anywhere) */
267
+ 'slug' => 'page', /* URL slug for the nav item */
268
+ 'parent_slug' => BP_MEDIA_AUDIO_SLUG, /* URL slug of the parent nav item */
269
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_AUDIO_SLUG), /* URL of the parent item */
270
+ 'position' => 90, /* Index of where this nav item should be positioned */
271
+ 'screen_function' => array($bp_media_audio, 'screen'), /* The name of the function to run when clicked */
272
+ ));
273
+
274
+
275
+ bp_core_new_nav_item(array(
276
+ 'name' => __(BP_MEDIA_ALBUMS_LABEL, BP_MEDIA_TXT_DOMAIN),
277
+ 'slug' => BP_MEDIA_ALBUMS_SLUG,
278
+ 'screen_function' => array($bp_media_album, 'screen'),
279
+ ));
280
+
281
+ bp_core_new_subnav_item(array(
282
+ 'name' => 'View', /* Display name for the nav item(It won't be shown anywhere) */
283
+ 'slug' => BP_MEDIA_ALBUMS_ENTRY_SLUG, /* URL slug for the nav item */
284
+ 'parent_slug' => BP_MEDIA_ALBUMS_SLUG, /* URL slug of the parent nav item */
285
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_ALBUMS_SLUG), /* URL of the parent item */
286
+ 'position' => 90, /* Index of where this nav item should be positioned */
287
+ 'screen_function' => array($bp_media_album, 'screen'), /* The name of the function to run when clicked */
288
+ ));
289
+
290
+ bp_core_new_subnav_item(array(
291
+ 'name' => 'Edit', /* Display name for the nav item(It won't be shown anywhere) */
292
+ 'slug' => BP_MEDIA_ALBUMS_EDIT_SLUG, /* URL slug for the nav item */
293
+ 'parent_slug' => BP_MEDIA_ALBUMS_SLUG, /* URL slug of the parent nav item */
294
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_ALBUMS_SLUG), /* URL of the parent item */
295
+ 'position' => 90, /* Index of where this nav item should be positioned */
296
+ 'screen_function' => array($bp_media_album, 'edit_screen'), /* The name of the function to run when clicked */
297
+ ));
298
+
299
+ bp_core_new_subnav_item(array(
300
+ 'name' => 'Delete', /* Display name for the nav item(It won't be shown anywhere) */
301
+ 'slug' => BP_MEDIA_DELETE_SLUG, /* URL slug for the nav item */
302
+ 'parent_slug' => BP_MEDIA_ALBUMS_SLUG, /* URL slug of the parent nav item */
303
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_ALBUMS_SLUG), /* URL of the parent item */
304
+ 'position' => 90, /* Index of where this nav item should be positioned */
305
+ 'screen_function' => array($bp_media_album, 'screen'), /* The name of the function to run when clicked */
306
+ ));
307
+
308
+ bp_core_new_subnav_item(array(
309
+ 'name' => 'Page', /* Display name for the nav item(It won't be shown anywhere) */
310
+ 'slug' => 'page', /* URL slug for the nav item */
311
+ 'parent_slug' => BP_MEDIA_ALBUMS_SLUG, /* URL slug of the parent nav item */
312
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_ALBUMS_SLUG), /* URL of the parent item */
313
+ 'position' => 90, /* Index of where this nav item should be positioned */
314
+ 'screen_function' => array($bp_media_album, 'screen'), /* The name of the function to run when clicked */
315
+ ));
316
+ bp_core_new_nav_item(array(
317
+ 'name' => __(BP_MEDIA_UPLOAD_LABEL, BP_MEDIA_TXT_DOMAIN),
318
+ 'slug' => BP_MEDIA_UPLOAD_SLUG,
319
+ 'screen_function' => array($bp_media_upload, 'upload_screen'),
320
+ 'user_has_access' => bp_is_my_profile()
321
+ ));
322
+ }
323
+
324
+ /**
325
+ * Creating a custom post type album for BuddyPress Media
326
+ */
327
+ function register_post_types() {
328
+ $labels = array(
329
+ 'name' => __('Albums', BP_MEDIA_TXT_DOMAIN),
330
+ 'singular_name' => __('Album', BP_MEDIA_TXT_DOMAIN),
331
+ 'add_new' => __('Create', BP_MEDIA_TXT_DOMAIN),
332
+ 'add_new_item' => __('Create Album', BP_MEDIA_TXT_DOMAIN),
333
+ 'edit_item' => __('Edit Album', BP_MEDIA_TXT_DOMAIN),
334
+ 'new_item' => __('New Album', BP_MEDIA_TXT_DOMAIN),
335
+ 'all_items' => __('All Albums', BP_MEDIA_TXT_DOMAIN),
336
+ 'view_item' => __('View Album', BP_MEDIA_TXT_DOMAIN),
337
+ 'search_items' => __('Search Albums', BP_MEDIA_TXT_DOMAIN),
338
+ 'not_found' => __('No album found', BP_MEDIA_TXT_DOMAIN),
339
+ 'not_found_in_trash' => __('No album found in Trash', BP_MEDIA_TXT_DOMAIN),
340
+ 'parent_item_colon' => '',
341
+ 'menu_name' => __('Albums', BP_MEDIA_TXT_DOMAIN)
342
+ );
343
+
344
+ $args = array(
345
+ 'labels' => $labels,
346
+ 'public' => true,
347
+ 'publicly_queryable' => true,
348
+ 'show_ui' => false,
349
+ 'show_in_menu' => false,
350
+ 'query_var' => true,
351
+ 'capability_type' => 'post',
352
+ 'has_archive' => true,
353
+ 'hierarchical' => false,
354
+ 'menu_position' => null,
355
+ 'supports' => array('title', 'author', 'thumbnail', 'excerpt', 'comments')
356
+ );
357
+ register_post_type('bp_media_album', $args);
358
+ global $bp_media;
359
+ /* Set up labels for the post type */
360
+ $labels = array(
361
+ 'name' => __('Media', BP_MEDIA_TXT_DOMAIN),
362
+ 'singular' => __('Media', BP_MEDIA_TXT_DOMAIN),
363
+ 'add_new' => __('Add New Media', BP_MEDIA_TXT_DOMAIN)
364
+ );
365
+
366
+ /* Set up the argument array for register_post_type() */
367
+ $args = array(
368
+ 'label' => __('Media', BP_MEDIA_TXT_DOMAIN),
369
+ 'labels' => $labels,
370
+ 'description' => __('BuddyPress Media\'s Media Files', BP_MEDIA_TXT_DOMAIN),
371
+ 'public' => true,
372
+ 'show_ui' => false,
373
+ 'supports' => array('title', 'editor', 'excerpt', 'author', 'thumbnail', 'custom-fields')
374
+ );
375
+ register_post_type('bp_media', $args);
376
+ parent::register_post_types();
377
+ }
378
 
379
  }
380
 
app/main/includes/BPMediaFilters.php CHANGED
@@ -7,6 +7,10 @@
7
  */
8
  class BPMediaFilters {
9
 
 
 
 
 
10
  function __construct() {
11
  add_filter('bp_activity_get_permalink', array($this, 'activity_permalink_filter'), 10, 2);
12
  add_filter('bp_get_activity_delete_link', array($this, 'delete_button_handler'));
@@ -19,6 +23,14 @@ class BPMediaFilters {
19
  $bp_media_activity_types = array('media_upload', 'album_updated', 'album_created');
20
  }
21
 
 
 
 
 
 
 
 
 
22
  function activity_permalink_filter($link, $activity_obj = null) {
23
  global $bp_media_activity_types;
24
  if ($activity_obj != null && in_array($activity_obj->type, $bp_media_activity_types)) {
@@ -53,6 +65,12 @@ class BPMediaFilters {
53
  return $link;
54
  }
55
 
 
 
 
 
 
 
56
  function activity_parent_content_filter($activity_content) {
57
  global $activities_template;
58
  $defaults = array(
@@ -85,7 +103,12 @@ class BPMediaFilters {
85
  }
86
 
87
  //add_filter('bp_get_activity_parent_content', 'activity_parent_content_filter', 1);
88
-
 
 
 
 
 
89
  function delete_button_handler($link) {
90
  global $activities_template;
91
  $media_label = NULL;
@@ -114,6 +137,13 @@ class BPMediaFilters {
114
  return $link;
115
  }
116
 
 
 
 
 
 
 
 
117
  static function items_count_filter($title, $nav_item) {
118
  global $bp_media_count;
119
  $bp_media_count = wp_parse_args($bp_media_count, array(
@@ -146,6 +176,13 @@ class BPMediaFilters {
146
  /**
147
  * To hide some activities of multiple uploads
148
  */
 
 
 
 
 
 
 
149
  static function activity_query_filter($query) {
150
  global $wpdb;
151
  $query = preg_replace('/WHERE/i', 'WHERE a.secondary_item_id!=-999 AND ', $query);
@@ -157,6 +194,11 @@ class BPMediaFilters {
157
  *
158
  * @global type $wp_admin_bar
159
  */
 
 
 
 
 
160
  function my_account_menu() {
161
  global $wp_admin_bar;
162
 
@@ -221,7 +263,12 @@ class BPMediaFilters {
221
  *
222
  * @global type $wp_admin_bar
223
  */
224
- function adminbar_settings_menu() {
 
 
 
 
 
225
  global $wp_admin_bar;
226
 
227
  if (current_user_can('manage_options') && is_super_admin()) {
@@ -274,7 +321,11 @@ class BPMediaFilters {
274
  *
275
  */
276
  //add_action('wp_dashboard_setup','dashboard_widgets');
277
-
 
 
 
 
278
  function dashboard_widgets() {
279
  global $wp_meta_boxes;
280
  // BuddyPress Media
@@ -333,6 +384,11 @@ class BPMediaFilters {
333
  <?php
334
  }
335
 
 
 
 
 
 
336
  function admin_total_count($media_type) {
337
 
338
  switch ($media_type) {
@@ -350,6 +406,11 @@ class BPMediaFilters {
350
  }
351
  }
352
 
 
 
 
 
 
353
  function group_total_count($media_type) {
354
 
355
  switch ($media_type) {
@@ -367,6 +428,12 @@ class BPMediaFilters {
367
  }
368
  }
369
 
 
 
 
 
 
 
370
  function total_count_media($type) {
371
  global $wpdb;
372
 
@@ -382,6 +449,11 @@ class BPMediaFilters {
382
  return false;
383
  }
384
 
 
 
 
 
 
385
  function total_count_albums() {
386
  global $wpdb;
387
 
7
  */
8
  class BPMediaFilters {
9
 
10
+ /**
11
+ *
12
+ * @global array $bp_media_activity_types
13
+ */
14
  function __construct() {
15
  add_filter('bp_activity_get_permalink', array($this, 'activity_permalink_filter'), 10, 2);
16
  add_filter('bp_get_activity_delete_link', array($this, 'delete_button_handler'));
23
  $bp_media_activity_types = array('media_upload', 'album_updated', 'album_created');
24
  }
25
 
26
+ /**
27
+ *
28
+ * @global array $bp_media_activity_types
29
+ * @global type $activities_template
30
+ * @param type $link
31
+ * @param type $activity_obj
32
+ * @return type
33
+ */
34
  function activity_permalink_filter($link, $activity_obj = null) {
35
  global $bp_media_activity_types;
36
  if ($activity_obj != null && in_array($activity_obj->type, $bp_media_activity_types)) {
65
  return $link;
66
  }
67
 
68
+ /**
69
+ *
70
+ * @global type $activities_template
71
+ * @param type $activity_content
72
+ * @return boolean
73
+ */
74
  function activity_parent_content_filter($activity_content) {
75
  global $activities_template;
76
  $defaults = array(
103
  }
104
 
105
  //add_filter('bp_get_activity_parent_content', 'activity_parent_content_filter', 1);
106
+ /**
107
+ *
108
+ * @global type $activities_template
109
+ * @param type $link
110
+ * @return type
111
+ */
112
  function delete_button_handler($link) {
113
  global $activities_template;
114
  $media_label = NULL;
137
  return $link;
138
  }
139
 
140
+ /**
141
+ *
142
+ * @global type $bp_media_count
143
+ * @param type $title
144
+ * @param type $nav_item
145
+ * @return type
146
+ */
147
  static function items_count_filter($title, $nav_item) {
148
  global $bp_media_count;
149
  $bp_media_count = wp_parse_args($bp_media_count, array(
176
  /**
177
  * To hide some activities of multiple uploads
178
  */
179
+
180
+ /**
181
+ *
182
+ * @global type $wpdb
183
+ * @param type $query
184
+ * @return type
185
+ */
186
  static function activity_query_filter($query) {
187
  global $wpdb;
188
  $query = preg_replace('/WHERE/i', 'WHERE a.secondary_item_id!=-999 AND ', $query);
194
  *
195
  * @global type $wp_admin_bar
196
  */
197
+
198
+ /**
199
+ *
200
+ * @global type $wp_admin_bar
201
+ */
202
  function my_account_menu() {
203
  global $wp_admin_bar;
204
 
263
  *
264
  * @global type $wp_admin_bar
265
  */
266
+
267
+ /**
268
+ *
269
+ * @global type $wp_admin_bar
270
+ */
271
+ static function adminbar_settings_menu() {
272
  global $wp_admin_bar;
273
 
274
  if (current_user_can('manage_options') && is_super_admin()) {
321
  *
322
  */
323
  //add_action('wp_dashboard_setup','dashboard_widgets');
324
+ /**
325
+ *
326
+ * @global array $wp_meta_boxes
327
+ * @global array $wp_meta_boxes
328
+ */
329
  function dashboard_widgets() {
330
  global $wp_meta_boxes;
331
  // BuddyPress Media
384
  <?php
385
  }
386
 
387
+ /**
388
+ *
389
+ * @param type $media_type
390
+ * @return type
391
+ */
392
  function admin_total_count($media_type) {
393
 
394
  switch ($media_type) {
406
  }
407
  }
408
 
409
+ /**
410
+ *
411
+ * @param type $media_type
412
+ * @return type
413
+ */
414
  function group_total_count($media_type) {
415
 
416
  switch ($media_type) {
428
  }
429
  }
430
 
431
+ /**
432
+ *
433
+ * @global type $wpdb
434
+ * @param type $type
435
+ * @return boolean
436
+ */
437
  function total_count_media($type) {
438
  global $wpdb;
439
 
449
  return false;
450
  }
451
 
452
+ /**
453
+ *
454
+ * @global type $wpdb
455
+ * @return boolean
456
+ */
457
  function total_count_albums() {
458
  global $wpdb;
459
 
app/main/includes/BPMediaFunction.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
-
 
 
3
  class BPMediaFunction {
4
 
5
  function __construct() {
@@ -9,6 +11,12 @@ class BPMediaFunction {
9
  add_action('wp_ajax_nopriv_my_featured_action', array($this, 'implement_featured_ajax'));
10
  }
11
 
 
 
 
 
 
 
12
  static function record_activity($args = '') {
13
  global $bp;
14
  if (!function_exists('bp_activity_add'))
@@ -22,6 +30,11 @@ class BPMediaFunction {
22
  return $activity_id;
23
  }
24
 
 
 
 
 
 
25
  static function override_allowed_tags($activity_allowedtags) {
26
  $activity_allowedtags['video'] = array();
27
  $activity_allowedtags['video']['id'] = array();
@@ -56,6 +69,11 @@ class BPMediaFunction {
56
  return $activity_allowedtags;
57
  }
58
 
 
 
 
 
 
59
  static function show_formatted_error_message($messages, $type) {
60
  echo '<div id="message" class="' . $type . '">';
61
  if (is_array($messages)) {
@@ -82,6 +100,13 @@ class BPMediaFunction {
82
  *
83
  */
84
 
 
 
 
 
 
 
 
85
  function conditional_override_allowed_tags($content, $activity = null) {
86
  global $bp_media;
87
 
@@ -99,6 +124,12 @@ class BPMediaFunction {
99
  /**
100
  * Updates the media count of all users.
101
  */
 
 
 
 
 
 
102
  static function update_count() {
103
  global $wpdb;
104
  $query =
@@ -133,6 +164,10 @@ class BPMediaFunction {
133
  return true;
134
  }
135
 
 
 
 
 
136
  static function update_media() {
137
  global $bp_media_current_entry;
138
  if ($bp_media_current_entry->update_media(array('description' => esc_html($_POST['bp_media_description']), 'name' => esc_html($_POST['bp_media_title'])))) {
@@ -167,6 +202,12 @@ class BPMediaFunction {
167
  exit;
168
  }
169
 
 
 
 
 
 
 
170
  static function update_album_activity($album, $current_time = true, $delete_media_id = null) {
171
  if (!is_object($album)) {
172
  $album = new BPMediaAlbum($album);
@@ -213,6 +254,10 @@ class BPMediaFunction {
213
  }
214
  }
215
 
 
 
 
 
216
  static function wp_comment_form_mod() {
217
  global $bp_media_current_entry;
218
  echo '<input type="hidden" name="redirect_to" value="' . $bp_media_current_entry->get_url() . '">';
@@ -238,6 +283,14 @@ class BPMediaFunction {
238
  * @param $type String Type of message(updated, success, error, warning), works only if message is set
239
  * @param $status String The HTTP status header for the redirection page.
240
  */
 
 
 
 
 
 
 
 
241
  function redirect($location, $message = '', $type = 'updated', $status = '302') {
242
  if ($message != '')
243
  bp_core_add_message($message, 'error');
1
  <?php
2
+ /**
3
+ *
4
+ */
5
  class BPMediaFunction {
6
 
7
  function __construct() {
11
  add_action('wp_ajax_nopriv_my_featured_action', array($this, 'implement_featured_ajax'));
12
  }
13
 
14
+ /**
15
+ *
16
+ * @global type $bp
17
+ * @param type $args
18
+ * @return boolean
19
+ */
20
  static function record_activity($args = '') {
21
  global $bp;
22
  if (!function_exists('bp_activity_add'))
30
  return $activity_id;
31
  }
32
 
33
+ /**
34
+ *
35
+ * @param type $activity_allowedtags
36
+ * @return array
37
+ */
38
  static function override_allowed_tags($activity_allowedtags) {
39
  $activity_allowedtags['video'] = array();
40
  $activity_allowedtags['video']['id'] = array();
69
  return $activity_allowedtags;
70
  }
71
 
72
+ /**
73
+ *
74
+ * @param type $messages
75
+ * @param type $type
76
+ */
77
  static function show_formatted_error_message($messages, $type) {
78
  echo '<div id="message" class="' . $type . '">';
79
  if (is_array($messages)) {
100
  *
101
  */
102
 
103
+ /**
104
+ *
105
+ * @global type $bp_media
106
+ * @param type $content
107
+ * @param type $activity
108
+ * @return type
109
+ */
110
  function conditional_override_allowed_tags($content, $activity = null) {
111
  global $bp_media;
112
 
124
  /**
125
  * Updates the media count of all users.
126
  */
127
+
128
+ /**
129
+ *
130
+ * @global type $wpdb
131
+ * @return boolean
132
+ */
133
  static function update_count() {
134
  global $wpdb;
135
  $query =
164
  return true;
165
  }
166
 
167
+ /**
168
+ *
169
+ * @global type $bp_media_current_entry
170
+ */
171
  static function update_media() {
172
  global $bp_media_current_entry;
173
  if ($bp_media_current_entry->update_media(array('description' => esc_html($_POST['bp_media_description']), 'name' => esc_html($_POST['bp_media_title'])))) {
202
  exit;
203
  }
204
 
205
+ /**
206
+ *
207
+ * @param BPMediaAlbum $album
208
+ * @param type $current_time
209
+ * @param type $delete_media_id
210
+ */
211
  static function update_album_activity($album, $current_time = true, $delete_media_id = null) {
212
  if (!is_object($album)) {
213
  $album = new BPMediaAlbum($album);
254
  }
255
  }
256
 
257
+ /**
258
+ *
259
+ * @global type $bp_media_current_entry
260
+ */
261
  static function wp_comment_form_mod() {
262
  global $bp_media_current_entry;
263
  echo '<input type="hidden" name="redirect_to" value="' . $bp_media_current_entry->get_url() . '">';
283
  * @param $type String Type of message(updated, success, error, warning), works only if message is set
284
  * @param $status String The HTTP status header for the redirection page.
285
  */
286
+
287
+ /**
288
+ *
289
+ * @param type $location
290
+ * @param type $message
291
+ * @param type $type
292
+ * @param type $status
293
+ */
294
  function redirect($location, $message = '', $type = 'updated', $status = '302') {
295
  if ($message != '')
296
  bp_core_add_message($message, 'error');
app/main/includes/BPMediaHostWordpress.php CHANGED
@@ -25,6 +25,10 @@ class BPMediaHostWordpress {
25
  * @since BuddyPress Media 2.0
26
  */
27
 
 
 
 
 
28
  function __construct($media_id = '') {
29
  if (!$media_id == '') {
30
  $this->init($media_id);
@@ -38,6 +42,13 @@ class BPMediaHostWordpress {
38
  *
39
  * @since BuddyPress Media 2.0
40
  */
 
 
 
 
 
 
 
41
  function init($media_id = '') {
42
  if (is_object($media_id)) {
43
  $media = $media_id;
@@ -59,9 +70,8 @@ class BPMediaHostWordpress {
59
  * But for use in the class, we use group_id as positive integer even though
60
  * we use it as negative value in the bp-media-key meta key
61
  */
62
-
63
  $this->group_id = $meta_key < 0 ? -$meta_key : 0;
64
- if ( !'bp_media_album' == $media->post_type || !empty($media->post_mime_type) )
65
  preg_match_all('/audio|video|image/i', $media->post_mime_type, $result);
66
  else
67
  $result[0][0] = 'album';
@@ -77,6 +87,20 @@ class BPMediaHostWordpress {
77
  *
78
  * @since BuddyPress Media 2.0
79
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  function add_media($name, $description, $album_id = 0, $group = 0, $is_multiple = false) {
81
  do_action('bp_media_before_add_media');
82
  global $bp, $wpdb, $bp_media_count, $bp_media;
@@ -205,6 +229,14 @@ class BPMediaHostWordpress {
205
  * Fetches the content of the activity of media upload based on its type
206
  *
207
  */
 
 
 
 
 
 
 
 
208
  function get_media_activity_content() {
209
  global $bp_media_counter, $bp_media_default_excerpts, $bp_media;
210
  $attachment_id = $this->id;
@@ -232,13 +264,18 @@ class BPMediaHostWordpress {
232
  return false;
233
  }
234
  $activity_content .= '</div>';
235
- $activity_content .= '<div class="bp_media_description">' . wp_html_excerpt($this->description, $bp_media_default_excerpts['activity_entry_description']). '</div>';
236
  return $activity_content;
237
  }
238
 
239
  /**
240
  * Returns the single media entry's URL
241
  */
 
 
 
 
 
242
  function get_media_activity_url() {
243
  if (!bp_is_activity_component())
244
  return false;
@@ -249,6 +286,12 @@ class BPMediaHostWordpress {
249
  /**
250
  * Returns the media activity's action text
251
  */
 
 
 
 
 
 
252
  function get_media_activity_action() {
253
  global $bp_media;
254
  if (!bp_is_activity_component())
@@ -260,6 +303,13 @@ class BPMediaHostWordpress {
260
  /**
261
  * Returns the HTML for content of the single entry page of the Media Entry
262
  */
 
 
 
 
 
 
 
263
  function get_media_single_content() {
264
  global $bp_media_default_excerpts, $bp_media;
265
 
@@ -290,13 +340,20 @@ class BPMediaHostWordpress {
290
  return false;
291
  }
292
  $content .= '</div>';
293
- $content .= '<div class="bp_media_description">' .wp_html_excerpt($this->description, $bp_media_default_excerpts['single_entry_description']) . '</div>';
294
  return $content;
295
  }
296
 
297
  /**
298
  * Returns the HTML for title of the single entry page of the Media Entry
299
  */
 
 
 
 
 
 
 
300
  function get_media_single_title() {
301
  global $bp_media_default_excerpts, $bp_media;
302
  $content = '<div class="bp_media_title">' . wp_html_excerpt($this->name, $bp_media_default_excerpts['single_entry_title']) . '</div>';
@@ -306,6 +363,12 @@ class BPMediaHostWordpress {
306
  /**
307
  * Returns the HTML for a media entry to be shown in the listing/gallery page
308
  */
 
 
 
 
 
 
309
  function get_media_gallery_content() {
310
  global $bp_media;
311
  $attachment = $this->id;
@@ -370,6 +433,12 @@ class BPMediaHostWordpress {
370
  /**
371
  * Outputs the comments and comment form in the single media entry page
372
  */
 
 
 
 
 
 
373
  function show_comment_form() {
374
  global $bp_media;
375
  $activity_id = get_post_meta($this->id, 'bp_media_child_activity', true);
@@ -388,29 +457,29 @@ class BPMediaHostWordpress {
388
  <ul id="activity-stream" class="activity-list item-list">
389
  <li class="activity activity_update" id="activity-<?php echo $activity_id; ?>">
390
  <div class="activity-content">
391
- <?php do_action('bp_activity_entry_content'); ?>
392
  <?php if (is_user_logged_in()) : ?>
393
  <div class="activity-meta no-ajax">
394
  <?php if (bp_activity_can_comment()) : ?>
395
  <a href="<?php bp_get_activity_comment_link(); ?>" class="button acomment-reply bp-primary-action" id="acomment-comment-<?php bp_activity_id(); ?>"><?php printf(__('Comment <span>%s</span>', BP_MEDIA_TXT_DOMAIN), bp_activity_get_comment_count()); ?></a>
396
- <?php endif; ?>
397
- <?php if (bp_activity_can_favorite()) : ?>
398
- <?php if (!bp_get_activity_is_favorite()) : ?>
399
  <a href="<?php bp_activity_favorite_link(); ?>" class="button fav bp-secondary-action" title="<?php esc_attr_e('Mark as Favorite', BP_MEDIA_TXT_DOMAIN); ?>"><?php _e('Favorite', BP_MEDIA_TXT_DOMAIN) ?></a>
400
- <?php else : ?>
401
  <a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e('Remove Favorite', BP_MEDIA_TXT_DOMAIN); ?>"><?php _e('Remove Favorite', BP_MEDIA_TXT_DOMAIN) ?></a>
402
- <?php endif; ?>
403
  <?php endif; ?>
404
- <?php if (bp_activity_user_can_delete()) bp_activity_delete_link(); ?>
405
- <?php do_action('bp_activity_entry_meta'); ?>
 
406
  </div>
407
- <?php endif; ?>
408
  </div>
409
- <?php do_action('bp_before_activity_entry_comments'); ?>
410
- <?php if (( is_user_logged_in() && bp_activity_can_comment() ) || bp_activity_get_comment_count()) : ?>
411
  <div class="activity-comments">
412
- <?php bp_activity_comments(); ?>
413
- <?php if (is_user_logged_in()) : ?>
414
  <form action="<?php bp_activity_comment_form_action(); ?>" method="post" id="ac-form-<?php bp_activity_id(); ?>" class="ac-form"<?php bp_activity_comment_form_nojs_display(); ?>>
415
  <div class="ac-reply-avatar"><?php bp_loggedin_user_avatar('width=' . BP_AVATAR_THUMB_WIDTH . '&height=' . BP_AVATAR_THUMB_HEIGHT); ?></div>
416
  <div class="ac-reply-content">
@@ -420,26 +489,26 @@ class BPMediaHostWordpress {
420
  <input type="submit" name="ac_form_submit" value="<?php _e('Post', BP_MEDIA_TXT_DOMAIN); ?>" /> &nbsp; <?php _e('or press esc to cancel.', BP_MEDIA_TXT_DOMAIN); ?>
421
  <input type="hidden" name="comment_form_id" value="<?php bp_activity_id(); ?>" />
422
  </div>
423
- <?php do_action('bp_activity_entry_comments'); ?>
424
- <?php wp_nonce_field('new_activity_comment', '_wpnonce_new_activity_comment'); ?>
425
  </form>
426
- <?php endif; ?>
427
  </div>
428
- <?php endif; ?>
429
  <?php do_action('bp_after_activity_entry_comments'); ?>
430
  </li>
431
  </ul>
432
  </div>
433
- <?php
434
- }
435
- }
436
- else {
437
- ?>
438
  <div class="activity">
439
  <ul id="activity-stream" class="activity-list item-list">
440
  <li class="activity activity_update" id="activity-<?php echo $activity_id; ?>">
441
  <div class="activity-content">
442
- <?php do_action('bp_activity_entry_content'); ?>
443
  <?php if (is_user_logged_in()) : ?>
444
  <div class="activity-meta no-ajax">
445
  <a href="<?php echo $this->get_delete_url(); ?>" class="button item-button bp-secondary-action delete-activity-single confirm" rel="nofollow"><?php _e("Delete", BP_MEDIA_TXT_DOMAIN); ?></a>
@@ -456,6 +525,11 @@ class BPMediaHostWordpress {
456
  /**
457
  * Returns the URL of the single media entry page
458
  */
 
 
 
 
 
459
  function get_url() {
460
  return $this->url;
461
  }
@@ -463,6 +537,11 @@ class BPMediaHostWordpress {
463
  /**
464
  * Returns the URL of the attached media file
465
  */
 
 
 
 
 
466
  function get_attachment_url() {
467
  return wp_get_attachment_url($this->id);
468
  }
@@ -477,6 +556,12 @@ class BPMediaHostWordpress {
477
  *
478
  * @return bool True when the update is successful, False when the update fails
479
  */
 
 
 
 
 
 
480
  function update_media($args = array()) {
481
  $defaults = array(
482
  'name' => $this->name,
@@ -498,6 +583,14 @@ class BPMediaHostWordpress {
498
  * Updates activity content's title and description sync with the editing of Media
499
  *
500
  */
 
 
 
 
 
 
 
 
501
  function update_media_activity() {
502
  global $wpdb, $bp, $current_user, $bp_media;
503
  $q = $wpdb->prepare("SELECT id FROM {$bp->activity->table_name} WHERE type = %s AND item_id = %d", 'media_upload', $this->id);
@@ -527,6 +620,11 @@ class BPMediaHostWordpress {
527
  /**
528
  * Deletes the Media Entry
529
  */
 
 
 
 
 
530
  function delete_media() {
531
  do_action('bp_media_before_delete_media', $this->id);
532
  global $bp_media_count;
@@ -550,6 +648,11 @@ class BPMediaHostWordpress {
550
  /**
551
  * Function to return the content to be placed in the activity of album
552
  */
 
 
 
 
 
553
  function get_album_activity_content() {
554
  $attachment = $this->id;
555
  switch ($this->type) {
@@ -587,6 +690,11 @@ class BPMediaHostWordpress {
587
  /**
588
  * Returns the description of the Media Entry
589
  */
 
 
 
 
 
590
  function get_content() {
591
  return $this->description;
592
  }
@@ -594,6 +702,11 @@ class BPMediaHostWordpress {
594
  /**
595
  * Returns the owner id of the Media Entry
596
  */
 
 
 
 
 
597
  function get_author() {
598
  return $this->owner;
599
  }
@@ -601,6 +714,11 @@ class BPMediaHostWordpress {
601
  /**
602
  * Returns the id of the Media Entry
603
  */
 
 
 
 
 
604
  function get_id() {
605
  return $this->id;
606
  }
@@ -608,6 +726,11 @@ class BPMediaHostWordpress {
608
  /**
609
  * Returns the edit url of the Media Entry
610
  */
 
 
 
 
 
611
  function get_edit_url() {
612
  return $this->edit_url;
613
  }
@@ -615,6 +738,11 @@ class BPMediaHostWordpress {
615
  /**
616
  * Returns the delete url of the Media Entry
617
  */
 
 
 
 
 
618
  function get_delete_url() {
619
  return $this->delete_url;
620
  }
@@ -622,6 +750,11 @@ class BPMediaHostWordpress {
622
  /**
623
  * Returns the type of activity
624
  */
 
 
 
 
 
625
  function get_media_activity_type() {
626
  switch ($this->type) {
627
  case 'image':
@@ -638,6 +771,11 @@ class BPMediaHostWordpress {
638
  /**
639
  * Returns the album id
640
  */
 
 
 
 
 
641
  function get_album_id() {
642
  return $this->album_id;
643
  }
@@ -645,6 +783,11 @@ class BPMediaHostWordpress {
645
  /**
646
  * Returns the title of the media
647
  */
 
 
 
 
 
648
  function get_title() {
649
  return $this->name;
650
  }
@@ -652,6 +795,11 @@ class BPMediaHostWordpress {
652
  /**
653
  * Returns the type of media
654
  */
 
 
 
 
 
655
  function get_type() {
656
  return $this->type;
657
  }
@@ -666,6 +814,11 @@ class BPMediaHostWordpress {
666
  /**
667
  * Returns the group id of the media, 0 if it does not belong to a group
668
  */
 
 
 
 
 
669
  function get_group_id() {
670
  return $this->group_id;
671
  }
@@ -674,6 +827,11 @@ class BPMediaHostWordpress {
674
  * Sets the permalinks of the media depending upon whether its in member directory
675
  * or group and acording to the media type
676
  */
 
 
 
 
 
677
  protected function set_permalinks() {
678
  if ($this->group_id > 0) {
679
  $current_group = new BP_Groups_Group($this->group_id);
@@ -716,9 +874,17 @@ class BPMediaHostWordpress {
716
  /**
717
  * Checks if the album given exists if not, creates a new one according to context
718
  */
 
 
 
 
 
 
 
 
719
  function check_and_create_album($album_id, $group) {
720
  global $wpdb;
721
- $post_wall=__( 'Wall Posts', BP_MEDIA_TXT_DOMAIN );
722
  $create_new_album_flag = false;
723
  if ($album_id != 0) {
724
  $album = get_post($album_id);
25
  * @since BuddyPress Media 2.0
26
  */
27
 
28
+ /**
29
+ *
30
+ * @param type $media_id
31
+ */
32
  function __construct($media_id = '') {
33
  if (!$media_id == '') {
34
  $this->init($media_id);
42
  *
43
  * @since BuddyPress Media 2.0
44
  */
45
+
46
+ /**
47
+ *
48
+ * @param type $media_id
49
+ * @return boolean
50
+ * @throws Exception
51
+ */
52
  function init($media_id = '') {
53
  if (is_object($media_id)) {
54
  $media = $media_id;
70
  * But for use in the class, we use group_id as positive integer even though
71
  * we use it as negative value in the bp-media-key meta key
72
  */
 
73
  $this->group_id = $meta_key < 0 ? -$meta_key : 0;
74
+ if (!'bp_media_album' == $media->post_type || !empty($media->post_mime_type))
75
  preg_match_all('/audio|video|image/i', $media->post_mime_type, $result);
76
  else
77
  $result[0][0] = 'album';
87
  *
88
  * @since BuddyPress Media 2.0
89
  */
90
+
91
+ /**
92
+ *
93
+ * @global type $bp
94
+ * @global type $wpdb
95
+ * @global type $bp_media_count
96
+ * @global type $bp_media
97
+ * @param type $name
98
+ * @param type $description
99
+ * @param type $album_id
100
+ * @param type $group
101
+ * @param type $is_multiple
102
+ * @throws Exception
103
+ */
104
  function add_media($name, $description, $album_id = 0, $group = 0, $is_multiple = false) {
105
  do_action('bp_media_before_add_media');
106
  global $bp, $wpdb, $bp_media_count, $bp_media;
229
  * Fetches the content of the activity of media upload based on its type
230
  *
231
  */
232
+
233
+ /**
234
+ *
235
+ * @global type $bp_media_counter
236
+ * @global type $bp_media_default_excerpts
237
+ * @global type $bp_media
238
+ * @return boolean|string
239
+ */
240
  function get_media_activity_content() {
241
  global $bp_media_counter, $bp_media_default_excerpts, $bp_media;
242
  $attachment_id = $this->id;
264
  return false;
265
  }
266
  $activity_content .= '</div>';
267
+ $activity_content .= '<div class="bp_media_description">' . wp_html_excerpt($this->description, $bp_media_default_excerpts['activity_entry_description']) . '</div>';
268
  return $activity_content;
269
  }
270
 
271
  /**
272
  * Returns the single media entry's URL
273
  */
274
+
275
+ /**
276
+ *
277
+ * @return boolean
278
+ */
279
  function get_media_activity_url() {
280
  if (!bp_is_activity_component())
281
  return false;
286
  /**
287
  * Returns the media activity's action text
288
  */
289
+
290
+ /**
291
+ *
292
+ * @global type $bp_media
293
+ * @return boolean
294
+ */
295
  function get_media_activity_action() {
296
  global $bp_media;
297
  if (!bp_is_activity_component())
303
  /**
304
  * Returns the HTML for content of the single entry page of the Media Entry
305
  */
306
+
307
+ /**
308
+ *
309
+ * @global type $bp_media_default_excerpts
310
+ * @global type $bp_media
311
+ * @return boolean|string
312
+ */
313
  function get_media_single_content() {
314
  global $bp_media_default_excerpts, $bp_media;
315
 
340
  return false;
341
  }
342
  $content .= '</div>';
343
+ $content .= '<div class="bp_media_description">' . wp_html_excerpt($this->description, $bp_media_default_excerpts['single_entry_description']) . '</div>';
344
  return $content;
345
  }
346
 
347
  /**
348
  * Returns the HTML for title of the single entry page of the Media Entry
349
  */
350
+
351
+ /**
352
+ *
353
+ * @global type $bp_media_default_excerpts
354
+ * @global type $bp_media
355
+ * @return string
356
+ */
357
  function get_media_single_title() {
358
  global $bp_media_default_excerpts, $bp_media;
359
  $content = '<div class="bp_media_title">' . wp_html_excerpt($this->name, $bp_media_default_excerpts['single_entry_title']) . '</div>';
363
  /**
364
  * Returns the HTML for a media entry to be shown in the listing/gallery page
365
  */
366
+
367
+ /**
368
+ *
369
+ * @global type $bp_media
370
+ * @return boolean
371
+ */
372
  function get_media_gallery_content() {
373
  global $bp_media;
374
  $attachment = $this->id;
433
  /**
434
  * Outputs the comments and comment form in the single media entry page
435
  */
436
+
437
+ /**
438
+ *
439
+ * @global type $bp_media
440
+ * @return boolean
441
+ */
442
  function show_comment_form() {
443
  global $bp_media;
444
  $activity_id = get_post_meta($this->id, 'bp_media_child_activity', true);
457
  <ul id="activity-stream" class="activity-list item-list">
458
  <li class="activity activity_update" id="activity-<?php echo $activity_id; ?>">
459
  <div class="activity-content">
460
+ <?php do_action('bp_activity_entry_content'); ?>
461
  <?php if (is_user_logged_in()) : ?>
462
  <div class="activity-meta no-ajax">
463
  <?php if (bp_activity_can_comment()) : ?>
464
  <a href="<?php bp_get_activity_comment_link(); ?>" class="button acomment-reply bp-primary-action" id="acomment-comment-<?php bp_activity_id(); ?>"><?php printf(__('Comment <span>%s</span>', BP_MEDIA_TXT_DOMAIN), bp_activity_get_comment_count()); ?></a>
465
+ <?php endif; ?>
466
+ <?php if (bp_activity_can_favorite()) : ?>
467
+ <?php if (!bp_get_activity_is_favorite()) : ?>
468
  <a href="<?php bp_activity_favorite_link(); ?>" class="button fav bp-secondary-action" title="<?php esc_attr_e('Mark as Favorite', BP_MEDIA_TXT_DOMAIN); ?>"><?php _e('Favorite', BP_MEDIA_TXT_DOMAIN) ?></a>
469
+ <?php else : ?>
470
  <a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e('Remove Favorite', BP_MEDIA_TXT_DOMAIN); ?>"><?php _e('Remove Favorite', BP_MEDIA_TXT_DOMAIN) ?></a>
 
471
  <?php endif; ?>
472
+ <?php endif; ?>
473
+ <?php if (bp_activity_user_can_delete()) bp_activity_delete_link(); ?>
474
+ <?php do_action('bp_activity_entry_meta'); ?>
475
  </div>
476
+ <?php endif; ?>
477
  </div>
478
+ <?php do_action('bp_before_activity_entry_comments'); ?>
479
+ <?php if (( is_user_logged_in() && bp_activity_can_comment() ) || bp_activity_get_comment_count()) : ?>
480
  <div class="activity-comments">
481
+ <?php bp_activity_comments(); ?>
482
+ <?php if (is_user_logged_in()) : ?>
483
  <form action="<?php bp_activity_comment_form_action(); ?>" method="post" id="ac-form-<?php bp_activity_id(); ?>" class="ac-form"<?php bp_activity_comment_form_nojs_display(); ?>>
484
  <div class="ac-reply-avatar"><?php bp_loggedin_user_avatar('width=' . BP_AVATAR_THUMB_WIDTH . '&height=' . BP_AVATAR_THUMB_HEIGHT); ?></div>
485
  <div class="ac-reply-content">
489
  <input type="submit" name="ac_form_submit" value="<?php _e('Post', BP_MEDIA_TXT_DOMAIN); ?>" /> &nbsp; <?php _e('or press esc to cancel.', BP_MEDIA_TXT_DOMAIN); ?>
490
  <input type="hidden" name="comment_form_id" value="<?php bp_activity_id(); ?>" />
491
  </div>
492
+ <?php do_action('bp_activity_entry_comments'); ?>
493
+ <?php wp_nonce_field('new_activity_comment', '_wpnonce_new_activity_comment'); ?>
494
  </form>
495
+ <?php endif; ?>
496
  </div>
497
+ <?php endif; ?>
498
  <?php do_action('bp_after_activity_entry_comments'); ?>
499
  </li>
500
  </ul>
501
  </div>
502
+ <?php
503
+ }
504
+ }
505
+ else {
506
+ ?>
507
  <div class="activity">
508
  <ul id="activity-stream" class="activity-list item-list">
509
  <li class="activity activity_update" id="activity-<?php echo $activity_id; ?>">
510
  <div class="activity-content">
511
+ <?php do_action('bp_activity_entry_content'); ?>
512
  <?php if (is_user_logged_in()) : ?>
513
  <div class="activity-meta no-ajax">
514
  <a href="<?php echo $this->get_delete_url(); ?>" class="button item-button bp-secondary-action delete-activity-single confirm" rel="nofollow"><?php _e("Delete", BP_MEDIA_TXT_DOMAIN); ?></a>
525
  /**
526
  * Returns the URL of the single media entry page
527
  */
528
+
529
+ /**
530
+ *
531
+ * @return type
532
+ */
533
  function get_url() {
534
  return $this->url;
535
  }
537
  /**
538
  * Returns the URL of the attached media file
539
  */
540
+
541
+ /**
542
+ *
543
+ * @return type
544
+ */
545
  function get_attachment_url() {
546
  return wp_get_attachment_url($this->id);
547
  }
556
  *
557
  * @return bool True when the update is successful, False when the update fails
558
  */
559
+
560
+ /**
561
+ *
562
+ * @param type $args
563
+ * @return type
564
+ */
565
  function update_media($args = array()) {
566
  $defaults = array(
567
  'name' => $this->name,
583
  * Updates activity content's title and description sync with the editing of Media
584
  *
585
  */
586
+
587
+ /**
588
+ *
589
+ * @global type $wpdb
590
+ * @global type $bp
591
+ * @global type $current_user
592
+ * @global type $bp_media
593
+ */
594
  function update_media_activity() {
595
  global $wpdb, $bp, $current_user, $bp_media;
596
  $q = $wpdb->prepare("SELECT id FROM {$bp->activity->table_name} WHERE type = %s AND item_id = %d", 'media_upload', $this->id);
620
  /**
621
  * Deletes the Media Entry
622
  */
623
+
624
+ /**
625
+ *
626
+ * @global type $bp_media_count
627
+ */
628
  function delete_media() {
629
  do_action('bp_media_before_delete_media', $this->id);
630
  global $bp_media_count;
648
  /**
649
  * Function to return the content to be placed in the activity of album
650
  */
651
+
652
+ /**
653
+ *
654
+ * @return boolean|string
655
+ */
656
  function get_album_activity_content() {
657
  $attachment = $this->id;
658
  switch ($this->type) {
690
  /**
691
  * Returns the description of the Media Entry
692
  */
693
+
694
+ /**
695
+ *
696
+ * @return type
697
+ */
698
  function get_content() {
699
  return $this->description;
700
  }
702
  /**
703
  * Returns the owner id of the Media Entry
704
  */
705
+
706
+ /**
707
+ *
708
+ * @return type
709
+ */
710
  function get_author() {
711
  return $this->owner;
712
  }
714
  /**
715
  * Returns the id of the Media Entry
716
  */
717
+
718
+ /**
719
+ *
720
+ * @return type
721
+ */
722
  function get_id() {
723
  return $this->id;
724
  }
726
  /**
727
  * Returns the edit url of the Media Entry
728
  */
729
+
730
+ /**
731
+ *
732
+ * @return type
733
+ */
734
  function get_edit_url() {
735
  return $this->edit_url;
736
  }
738
  /**
739
  * Returns the delete url of the Media Entry
740
  */
741
+
742
+ /**
743
+ *
744
+ * @return type
745
+ */
746
  function get_delete_url() {
747
  return $this->delete_url;
748
  }
750
  /**
751
  * Returns the type of activity
752
  */
753
+
754
+ /**
755
+ *
756
+ * @return string
757
+ */
758
  function get_media_activity_type() {
759
  switch ($this->type) {
760
  case 'image':
771
  /**
772
  * Returns the album id
773
  */
774
+
775
+ /**
776
+ *
777
+ * @return type
778
+ */
779
  function get_album_id() {
780
  return $this->album_id;
781
  }
783
  /**
784
  * Returns the title of the media
785
  */
786
+
787
+ /**
788
+ *
789
+ * @return type
790
+ */
791
  function get_title() {
792
  return $this->name;
793
  }
795
  /**
796
  * Returns the type of media
797
  */
798
+
799
+ /**
800
+ *
801
+ * @return type
802
+ */
803
  function get_type() {
804
  return $this->type;
805
  }
814
  /**
815
  * Returns the group id of the media, 0 if it does not belong to a group
816
  */
817
+
818
+ /**
819
+ *
820
+ * @return type
821
+ */
822
  function get_group_id() {
823
  return $this->group_id;
824
  }
827
  * Sets the permalinks of the media depending upon whether its in member directory
828
  * or group and acording to the media type
829
  */
830
+
831
+ /**
832
+ *
833
+ * @return boolean
834
+ */
835
  protected function set_permalinks() {
836
  if ($this->group_id > 0) {
837
  $current_group = new BP_Groups_Group($this->group_id);
874
  /**
875
  * Checks if the album given exists if not, creates a new one according to context
876
  */
877
+
878
+ /**
879
+ *
880
+ * @global type $wpdb
881
+ * @param type $album_id
882
+ * @param type $group
883
+ * @return type
884
+ */
885
  function check_and_create_album($album_id, $group) {
886
  global $wpdb;
887
+ $post_wall = __('Wall Posts', BP_MEDIA_TXT_DOMAIN);
888
  $create_new_album_flag = false;
889
  if ($album_id != 0) {
890
  $album = get_post($album_id);
app/main/includes/BPMediaTemplateFunctions.php CHANGED
@@ -2,6 +2,12 @@
2
 
3
  class BPMediaTemplateFunctions {
4
 
 
 
 
 
 
 
5
  function show_upload_form() {
6
  global $bp, $bp_media_default_excerpts, $bp_media_options;
7
  $allowed = array(
@@ -35,7 +41,15 @@ class BPMediaTemplateFunctions {
35
  }
36
 
37
  //------------- Function removed show_upload_form_multiple() ------------
38
-
 
 
 
 
 
 
 
 
39
  function show_pagination($type = 'top', $inner = false) {
40
  global $bp, $bp_media_paginated_links, $bp_media_query, $bp_media_albums_query;
41
  switch ($bp->current_action) {
@@ -111,15 +125,21 @@ class BPMediaTemplateFunctions {
111
  Viewing <?php echo $current_single ?> <?php echo $from_num ?> to <?php echo $to_num ?> (of <?php echo $total; ?> <?php echo $current ?>)
112
  </div>
113
  <div class="pagination-links">
114
- <?php if (is_array($bp_media_paginated_links)) : foreach ($bp_media_paginated_links as $link) : ?>
115
- <?php echo $link; ?>
116
  <?php endforeach;
117
- endif; ?>
 
118
  </div>
119
  </div>
120
  <?php
121
  }
122
 
 
 
 
 
 
123
  function get_permalink($id = 0) {
124
  if (is_object($id))
125
  $media = $id;
@@ -165,6 +185,11 @@ class BPMediaTemplateFunctions {
165
  }
166
  }
167
 
 
 
 
 
 
168
  function album_the_content($id = 0) {
169
  if (is_object($id))
170
  $album = $id;
@@ -182,6 +207,12 @@ class BPMediaTemplateFunctions {
182
  }
183
  }
184
 
 
 
 
 
 
 
185
  function display_show_more($type = 'media') {
186
  $showmore = false;
187
  switch ($type) {
@@ -198,12 +229,10 @@ class BPMediaTemplateFunctions {
198
  break;
199
  }
200
  if ($showmore) {
201
- echo '<div class="bp-media-actions"><a href="#" class="button" id="bp-media-show-more">'. __('Show More', BP_MEDIA_TXT_DOMAIN).'</a></div>';
202
  }
203
  }
204
 
205
  //----------- Function removed show_upload_form_multiple_activity() -------------
206
-
207
-
208
  }
209
  ?>
2
 
3
  class BPMediaTemplateFunctions {
4
 
5
+ /**
6
+ *
7
+ * @global type $bp
8
+ * @global type $bp_media_default_excerpts
9
+ * @global type $bp_media_options
10
+ */
11
  function show_upload_form() {
12
  global $bp, $bp_media_default_excerpts, $bp_media_options;
13
  $allowed = array(
41
  }
42
 
43
  //------------- Function removed show_upload_form_multiple() ------------
44
+ /**
45
+ *
46
+ * @global type $bp
47
+ * @global type $bp_media_paginated_links
48
+ * @global type $bp_media_query
49
+ * @global type $bp_media_albums_query
50
+ * @param type $type
51
+ * @param type $inner
52
+ */
53
  function show_pagination($type = 'top', $inner = false) {
54
  global $bp, $bp_media_paginated_links, $bp_media_query, $bp_media_albums_query;
55
  switch ($bp->current_action) {
125
  Viewing <?php echo $current_single ?> <?php echo $from_num ?> to <?php echo $to_num ?> (of <?php echo $total; ?> <?php echo $current ?>)
126
  </div>
127
  <div class="pagination-links">
128
+ <?php if (is_array($bp_media_paginated_links)) : foreach ($bp_media_paginated_links as $link) : ?>
129
+ <?php echo $link; ?>
130
  <?php endforeach;
131
+ endif;
132
+ ?>
133
  </div>
134
  </div>
135
  <?php
136
  }
137
 
138
+ /**
139
+ *
140
+ * @param type $id
141
+ * @return boolean
142
+ */
143
  function get_permalink($id = 0) {
144
  if (is_object($id))
145
  $media = $id;
185
  }
186
  }
187
 
188
+ /**
189
+ *
190
+ * @param type $id
191
+ * @return boolean
192
+ */
193
  function album_the_content($id = 0) {
194
  if (is_object($id))
195
  $album = $id;
207
  }
208
  }
209
 
210
+ /**
211
+ *
212
+ * @global type $bp_media_query
213
+ * @global type $bp_media_albums_query
214
+ * @param type $type
215
+ */
216
  function display_show_more($type = 'media') {
217
  $showmore = false;
218
  switch ($type) {
229
  break;
230
  }
231
  if ($showmore) {
232
+ echo '<div class="bp-media-actions"><a href="#" class="button" id="bp-media-show-more">' . __('Show More', BP_MEDIA_TXT_DOMAIN) . '</a></div>';
233
  }
234
  }
235
 
236
  //----------- Function removed show_upload_form_multiple_activity() -------------
 
 
237
  }
238
  ?>
app/main/includes/BPMediaUpgradeScript.php CHANGED
@@ -1,6 +1,9 @@
1
  <?php
2
  class BPMediaUpgradeScript{
3
-
 
 
 
4
  static function upgrade_from_1_0_to_2_1(){
5
  global $wpdb;
6
  $post_wall =__( 'Wall Posts', BP_MEDIA_TXT_DOMAIN );
@@ -69,12 +72,12 @@ class BPMediaUpgradeScript{
69
  add_action('admin_notices','BPMediaUpgradeScript::database_updated_notice');
70
  wp_cache_flush();
71
  }
72
-
73
  static function database_updated_notice(){
74
  echo '<div class="updated rt-success"><p>
75
  <b>BuddyPress Media</b> Database upgraded successfully.
76
  </p></div>';
77
  }
 
78
  static function upgrade_from_2_0_to_2_1(){
79
  $page = 0;
80
  while($media_entries = BPMediaUpgradeScript::return_query_posts(array(
@@ -117,7 +120,11 @@ class BPMediaUpgradeScript{
117
  add_action('admin_notices','BPMediaUpgradeScript::database_updated_notice');
118
  wp_cache_flush();
119
  }
120
-
 
 
 
 
121
  static function return_query_posts($args){
122
  $bp_media_query = new WP_Query($args);
123
  return $bp_media_query->posts;
1
  <?php
2
  class BPMediaUpgradeScript{
3
+ /**
4
+ *
5
+ * @global wpdb $wpdb
6
+ */
7
  static function upgrade_from_1_0_to_2_1(){
8
  global $wpdb;
9
  $post_wall =__( 'Wall Posts', BP_MEDIA_TXT_DOMAIN );
72
  add_action('admin_notices','BPMediaUpgradeScript::database_updated_notice');
73
  wp_cache_flush();
74
  }
 
75
  static function database_updated_notice(){
76
  echo '<div class="updated rt-success"><p>
77
  <b>BuddyPress Media</b> Database upgraded successfully.
78
  </p></div>';
79
  }
80
+
81
  static function upgrade_from_2_0_to_2_1(){
82
  $page = 0;
83
  while($media_entries = BPMediaUpgradeScript::return_query_posts(array(
120
  add_action('admin_notices','BPMediaUpgradeScript::database_updated_notice');
121
  wp_cache_flush();
122
  }
123
+ /**
124
+ *
125
+ * @param type $args
126
+ * @return type
127
+ */
128
  static function return_query_posts($args){
129
  $bp_media_query = new WP_Query($args);
130
  return $bp_media_query->posts;
app/main/profile/BPMediaAlbum.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * Adds the album screens and functionality
4
  *
@@ -9,277 +10,345 @@
9
  * @author Gagandeep Singh <gagandeep.singh@rtcamp.com>
10
  *
11
  */
12
- class BPMediaAlbum{
13
- private $id,
14
- $name,
15
- $description,
16
- $url,
17
- $owner,
18
- $delete_url,
19
- $thumbnail,
20
- $edit_url,
21
- $media_entries,
22
- $group_id;
23
 
24
- /**
25
- *
26
- * @param type $album_id
27
- */
28
- /**
29
- * Constructs a new BP_Media_Album
30
- *
31
- * @param mixed $album_id optional Album ID of the element to be initialized if not defined, returns an empty element.
32
- *
33
- * @since BuddyPress Media 2.2
34
- */
35
- function __construct($album_id = '') {
36
- if (!$album_id == '') {
37
- $this->init($album_id);
38
- }
39
- }
40
 
41
- /**
42
- *
43
- * @param type $album_id
44
- * @throws Exception
45
- */
46
- /**
47
- * Initializes the object
48
- *
49
- * @param mixed $album_id Album ID of the element to be initialized. Can be the ID or the object of the Album
50
- *
51
- * @since BuddyPress Media 2.2
52
- */
53
- function init($album_id){
54
- if (is_object($album_id)) {
55
- $album = $album_id;
56
- } else {
57
- $album = &get_post($album_id);
58
- }
59
- if (empty($album->ID))
60
- throw new Exception(__('Sorry, the requested album does not exist.', BP_MEDIA_TXT_DOMAIN));
61
- $this->id = $album->ID;
62
- $this->description = $album->post_content;
63
- $this->name = $album->post_title;
64
- $this->owner = $album->post_author;
65
- $meta_key = get_post_meta($this->id, 'bp-media-key', true);
66
- /**
67
- * We use bp-media-key to distinguish if the entry belongs to a group or not
68
- * if the value is less than 0 it means it the group id to which the media belongs
69
- * and if its greater than 0 then it means its the author id of the uploader
70
- * But for use in the class, we use group_id as positive integer even though
71
- * we use it as negative value in the bp-media-key meta key
72
- */
73
- $this->group_id = $meta_key<0?-$meta_key:0;
74
- if($this->group_id>0){
75
- $current_group = new BP_Groups_Group($this->group_id);
76
- $group_url = bp_get_group_permalink($current_group);
77
- $this->url = trailingslashit($group_url . BP_MEDIA_ALBUMS_SLUG . '/' . $this->id);
78
- $this->edit_url = trailingslashit($group_url . BP_MEDIA_ALBUMS_SLUG . '/' . BP_MEDIA_ALBUMS_EDIT_SLUG . '/' . $this->id);
79
- $this->delete_url = trailingslashit($group_url . BP_MEDIA_ALBUMS_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id);
80
- }
81
- else{
82
- $this->url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_ALBUMS_SLUG . '/' . $this->id);
83
- $this->edit_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_ALBUMS_SLUG . '/' . BP_MEDIA_ALBUMS_EDIT_SLUG . '/' . $this->id);
84
- $this->delete_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_ALBUMS_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id);
85
- }
86
- $attachments = get_children(array(
87
- 'numberposts' => 1,
88
- 'order'=> 'DESC',
89
- 'post_mime_type' => 'image',
90
- 'post_parent' => $this->id,
91
- 'post_type' => 'attachment'
92
- ));
93
- $attachments_featured = get_children(array(
94
- 'numberposts' => 1,
95
- 'meta_key' => 'featured',
96
- 'orderby' => 'meta_value',
97
- 'post_mime_type' => 'image',
98
- 'post_parent' => $this->id,
99
- 'post_type' => 'attachment',
100
- ));
101
- if($attachments_featured) {
102
- foreach($attachments_featured as $attachment) {
103
- $this->thumbnail = '<span><img src="'.wp_get_attachment_thumb_url( $attachment->ID ).'"></span>';
104
- }
105
- }elseif ($attachments) {
106
- foreach($attachments as $attachment) {
107
- $this->thumbnail = '<span><img src="'.wp_get_attachment_thumb_url( $attachment->ID ).'"></span>';
108
- }
109
- }else{
110
- $this->thumbnail = '<img src ="'.BP_MEDIA_URL.'app/assets/img/image_thumb.png">';
111
- }
112
- $this->media_entries = get_children(array(
113
- 'post_parent' => $this->id,
114
- 'post_type' => 'attachment'
115
- ));
116
- }
117
 
118
- /**
119
- * Adds a new album and initializes the object with the new album
120
- *
121
- * @param string $title The title of the album.
122
- * @param string $author_id Optional The author id, defaults to zero in which case takes the logged in user id.
123
- * @param string $group_id Optional The group id to which the album belongs, defaults to 0 meaning its not attached with a group.
124
- *
125
- * @since BuddyPress Media 2.2
126
- */
127
- function add_album($title,$author_id = 0, $group_id = 0){
128
- do_action('bp_media_before_add_album');
129
- $author_id = $author_id?$author_id:get_current_user_id();
130
- $post_vars = array(
131
- 'post_title' => $title,
132
- 'post_name' => $title,
133
- 'post_status' => 'publish',
134
- 'post_type' => 'bp_media_album',
135
- 'post_author' => $author_id
136
- );
137
- BPMediaActions::init_count($author_id);
138
- global $bp_media_count;
139
- $album_id = wp_insert_post($post_vars);
140
- if($group_id){
141
- add_post_meta($album_id, 'bp-media-key', (-$group_id));
142
- }
143
- else{
144
- add_post_meta($album_id, 'bp-media-key', $author_id);
145
- }
146
- $this->init($album_id);
147
- $bp_media_count['albums'] = intval(isset($bp_media_count['albums'])?$bp_media_count['albums']:0) + 1;
148
- bp_update_user_meta($author_id, 'bp_media_count', $bp_media_count);
149
- do_action('bp_media_after_add_album',$this);
150
- return $album_id;
151
- }
152
 
153
- /**
154
- * Deletes the album and all associated attachments
155
- *
156
- * @since BuddyPress Media 2.2
157
- */
158
- function delete_album(){
159
- do_action('bp_media_before_delete_album', $this);
160
- foreach($this->media_entries as $entry){
161
- BPMediaActions::delete_media_handler($entry->ID);
162
- //do_action('bp_media_before_delete_media',$entry->ID); //Not working for some reason so called the required function directly
163
- wp_delete_attachment($entry->ID,true);
164
- do_action('bp_media_after_delete_media',$entry->ID);
165
- }
166
- $author_id = $this->owner;
167
- BPMediaActions::init_count($author_id);
168
- wp_delete_post($this->id,true);
169
- global $bp_media_count;
170
- $bp_media_count['albums'] = intval(isset($bp_media_count['albums'])?$bp_media_count['albums']:0) - 1;
171
- bp_update_user_meta($author_id, 'bp_media_count', $bp_media_count);
172
- do_action('bp_media_after_delete_album', $this);
173
- }
174
 
175
- function edit_album($title=''){
176
- do_action('bp_media_before_edit_album',$this);
177
- if($title==''){
178
- return false;
179
- }
180
- else{
181
- $this->name = $title;
182
- $args = array(
183
- 'ID' => $this->id,
184
- 'post_title'=>$this->name
185
- );
186
- $status = wp_insert_post($args);
187
- if(get_class($status)=='WP_Error'||$status==0){
188
- return false;
189
- }
190
- else{
191
- return true;
192
- }
193
- }
194
- do_action('bp_media_after_edit_album',$this);
195
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
- /**
198
- *
199
- * @global type $bp_media
200
- */
201
- function get_album_gallery_content(){
202
- ?><li>
203
- <a href="<?php echo $this->url ?>" title="<?php _e($this->description,BP_MEDIA_TXT_DOMAIN); ?>">
204
- <?php echo $this->thumbnail; ?>
205
- </a>
206
- <h3 title="<?php echo $this->name ?>"><a href="<?php echo $this->url ?>" title="<?php _e($this->description,BP_MEDIA_TXT_DOMAIN); ?>"><?php echo ( ( strlen( $this->name ) > 14 ) ? substr( $this->name, 0, 14 ) . "&hellip;" : $this->name );?> </a><?php echo ' ('.count($this->media_entries).')'; ?></h3>
207
- </li><?php
208
- }
209
 
210
- /**
211
- * Returns the attachments linked with the albume
212
- *
213
- * @since BuddyPress Media 2.2
214
- */
215
- function get_entries(){
216
- return $this->media_entries;
217
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
 
219
- /**
220
- * Returns the title of the album
221
- *
222
- * @since BuddyPress Media 2.2
223
- */
224
- function get_title(){
225
- return $this->name;
226
- }
227
 
228
- /**
229
- * Echoes the title of the album
230
- *
231
- * @since BuddyPress Media 2.2
232
- */
233
- function the_title(){
234
- echo $this->name;
235
- }
 
 
 
 
 
 
 
 
 
 
 
 
236
 
237
- /**
238
- * Returns the id of the album
239
- *
240
- * @since BuddyPress Media 2.2
241
- */
242
- function get_id(){
243
- return $this->id;
244
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
 
246
- /**
247
- * Returns the url of the album
248
- *
249
- * @since BuddyPress Media 2.2
250
- */
251
- function get_url(){
252
- return $this->url;
253
- }
 
 
 
 
254
 
255
- /**
256
- * Returns the owner's id
257
- *
258
- * @since BuddyPress Media 2.2
259
- */
260
- function get_owner(){
261
- return $this->owner;
262
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
 
264
- /**
265
- * Returns the edit url of the album
266
- */
267
- function get_edit_url(){
268
- return $this->edit_url;
269
- }
270
-
271
- /**
272
- * Returns the delete url of the album
273
- */
274
- function get_delete_url(){
275
- return $this->delete_url;
276
- }
277
-
278
- /**
279
- * Returns the group id to which the media belongs, 0 if it does not belong to any group
280
- */
281
- function get_group_id(){
282
- return $this->group_id;
283
- }
284
  }
285
  ?>
1
  <?php
2
+
3
  /**
4
  * Adds the album screens and functionality
5
  *
10
  * @author Gagandeep Singh <gagandeep.singh@rtcamp.com>
11
  *
12
  */
13
+ class BPMediaAlbum {
 
 
 
 
 
 
 
 
 
 
14
 
15
+ private $id,
16
+ $name,
17
+ $description,
18
+ $url,
19
+ $owner,
20
+ $delete_url,
21
+ $thumbnail,
22
+ $edit_url,
23
+ $media_entries,
24
+ $group_id;
 
 
 
 
 
 
25
 
26
+ /**
27
+ *
28
+ * @param type $album_id
29
+ */
30
+ /**
31
+ * Constructs a new BP_Media_Album
32
+ *
33
+ * @param mixed $album_id optional Album ID of the element to be initialized if not defined, returns an empty element.
34
+ *
35
+ * @since BuddyPress Media 2.2
36
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
+ /**
39
+ *
40
+ * @param type $album_id
41
+ */
42
+ function __construct($album_id = '') {
43
+ if (!$album_id == '') {
44
+ $this->init($album_id);
45
+ }
46
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
+ /**
49
+ *
50
+ * @param type $album_id
51
+ * @throws Exception
52
+ */
53
+ /**
54
+ * Initializes the object
55
+ *
56
+ * @param mixed $album_id Album ID of the element to be initialized. Can be the ID or the object of the Album
57
+ *
58
+ * @since BuddyPress Media 2.2
59
+ */
 
 
 
 
 
 
 
 
 
60
 
61
+ /**
62
+ *
63
+ * @param type $album_id
64
+ * @throws Exception
65
+ */
66
+ function init($album_id) {
67
+ if (is_object($album_id)) {
68
+ $album = $album_id;
69
+ } else {
70
+ $album = &get_post($album_id);
71
+ }
72
+ if (empty($album->ID))
73
+ throw new Exception(__('Sorry, the requested album does not exist.', BP_MEDIA_TXT_DOMAIN));
74
+ $this->id = $album->ID;
75
+ $this->description = $album->post_content;
76
+ $this->name = $album->post_title;
77
+ $this->owner = $album->post_author;
78
+ $meta_key = get_post_meta($this->id, 'bp-media-key', true);
79
+ /**
80
+ * We use bp-media-key to distinguish if the entry belongs to a group or not
81
+ * if the value is less than 0 it means it the group id to which the media belongs
82
+ * and if its greater than 0 then it means its the author id of the uploader
83
+ * But for use in the class, we use group_id as positive integer even though
84
+ * we use it as negative value in the bp-media-key meta key
85
+ */
86
+ $this->group_id = $meta_key < 0 ? -$meta_key : 0;
87
+ if ($this->group_id > 0) {
88
+ $current_group = new BP_Groups_Group($this->group_id);
89
+ $group_url = bp_get_group_permalink($current_group);
90
+ $this->url = trailingslashit($group_url . BP_MEDIA_ALBUMS_SLUG . '/' . $this->id);
91
+ $this->edit_url = trailingslashit($group_url . BP_MEDIA_ALBUMS_SLUG . '/' . BP_MEDIA_ALBUMS_EDIT_SLUG . '/' . $this->id);
92
+ $this->delete_url = trailingslashit($group_url . BP_MEDIA_ALBUMS_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id);
93
+ } else {
94
+ $this->url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_ALBUMS_SLUG . '/' . $this->id);
95
+ $this->edit_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_ALBUMS_SLUG . '/' . BP_MEDIA_ALBUMS_EDIT_SLUG . '/' . $this->id);
96
+ $this->delete_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_ALBUMS_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id);
97
+ }
98
+ $attachments = get_children(array(
99
+ 'numberposts' => 1,
100
+ 'order' => 'DESC',
101
+ 'post_mime_type' => 'image',
102
+ 'post_parent' => $this->id,
103
+ 'post_type' => 'attachment'
104
+ ));
105
+ $attachments_featured = get_children(array(
106
+ 'numberposts' => 1,
107
+ 'meta_key' => 'featured',
108
+ 'orderby' => 'meta_value',
109
+ 'post_mime_type' => 'image',
110
+ 'post_parent' => $this->id,
111
+ 'post_type' => 'attachment',
112
+ ));
113
+ if ($attachments_featured) {
114
+ foreach ($attachments_featured as $attachment) {
115
+ $this->thumbnail = '<span><img src="' . wp_get_attachment_thumb_url($attachment->ID) . '"></span>';
116
+ }
117
+ } elseif ($attachments) {
118
+ foreach ($attachments as $attachment) {
119
+ $this->thumbnail = '<span><img src="' . wp_get_attachment_thumb_url($attachment->ID) . '"></span>';
120
+ }
121
+ } else {
122
+ $this->thumbnail = '<img src ="' . BP_MEDIA_URL . 'app/assets/img/image_thumb.png">';
123
+ }
124
+ $this->media_entries = get_children(array(
125
+ 'post_parent' => $this->id,
126
+ 'post_type' => 'attachment'
127
+ ));
128
+ }
129
 
130
+ /**
131
+ * Adds a new album and initializes the object with the new album
132
+ *
133
+ * @param string $title The title of the album.
134
+ * @param string $author_id Optional The author id, defaults to zero in which case takes the logged in user id.
135
+ * @param string $group_id Optional The group id to which the album belongs, defaults to 0 meaning its not attached with a group.
136
+ *
137
+ * @since BuddyPress Media 2.2
138
+ */
 
 
 
139
 
140
+ /**
141
+ *
142
+ * @global array $bp_media_count
143
+ * @param type $title
144
+ * @param type $author_id
145
+ * @param type $group_id
146
+ * @return type
147
+ */
148
+ function add_album($title, $author_id = 0, $group_id = 0) {
149
+ do_action('bp_media_before_add_album');
150
+ $author_id = $author_id ? $author_id : get_current_user_id();
151
+ $post_vars = array(
152
+ 'post_title' => $title,
153
+ 'post_name' => $title,
154
+ 'post_status' => 'publish',
155
+ 'post_type' => 'bp_media_album',
156
+ 'post_author' => $author_id
157
+ );
158
+ BPMediaActions::init_count($author_id);
159
+ global $bp_media_count;
160
+ $album_id = wp_insert_post($post_vars);
161
+ if ($group_id) {
162
+ add_post_meta($album_id, 'bp-media-key', (-$group_id));
163
+ } else {
164
+ add_post_meta($album_id, 'bp-media-key', $author_id);
165
+ }
166
+ $this->init($album_id);
167
+ $bp_media_count['albums'] = intval(isset($bp_media_count['albums']) ? $bp_media_count['albums'] : 0) + 1;
168
+ bp_update_user_meta($author_id, 'bp_media_count', $bp_media_count);
169
+ do_action('bp_media_after_add_album', $this);
170
+ return $album_id;
171
+ }
172
 
173
+ /**
174
+ * Deletes the album and all associated attachments
175
+ *
176
+ * @since BuddyPress Media 2.2
177
+ */
 
 
 
178
 
179
+ /**
180
+ *
181
+ * @global array $bp_media_count
182
+ */
183
+ function delete_album() {
184
+ do_action('bp_media_before_delete_album', $this);
185
+ foreach ($this->media_entries as $entry) {
186
+ BPMediaActions::delete_media_handler($entry->ID);
187
+ //do_action('bp_media_before_delete_media',$entry->ID); //Not working for some reason so called the required function directly
188
+ wp_delete_attachment($entry->ID, true);
189
+ do_action('bp_media_after_delete_media', $entry->ID);
190
+ }
191
+ $author_id = $this->owner;
192
+ BPMediaActions::init_count($author_id);
193
+ wp_delete_post($this->id, true);
194
+ global $bp_media_count;
195
+ $bp_media_count['albums'] = intval(isset($bp_media_count['albums']) ? $bp_media_count['albums'] : 0) - 1;
196
+ bp_update_user_meta($author_id, 'bp_media_count', $bp_media_count);
197
+ do_action('bp_media_after_delete_album', $this);
198
+ }
199
 
200
+ /**
201
+ *
202
+ * @param type $title
203
+ * @return boolean
204
+ */
205
+ function edit_album($title = '') {
206
+ do_action('bp_media_before_edit_album', $this);
207
+ if ($title == '') {
208
+ return false;
209
+ } else {
210
+ $this->name = $title;
211
+ $args = array(
212
+ 'ID' => $this->id,
213
+ 'post_title' => $this->name
214
+ );
215
+ $status = wp_insert_post($args);
216
+ if (get_class($status) == 'WP_Error' || $status == 0) {
217
+ return false;
218
+ } else {
219
+ return true;
220
+ }
221
+ }
222
+ do_action('bp_media_after_edit_album', $this);
223
+ }
224
 
225
+ /**
226
+ *
227
+ * @global type $bp_media
228
+ */
229
+ function get_album_gallery_content() {
230
+ ?><li>
231
+ <a href="<?php echo $this->url ?>" title="<?php _e($this->description, BP_MEDIA_TXT_DOMAIN); ?>">
232
+ <?php echo $this->thumbnail; ?>
233
+ </a>
234
+ <h3 title="<?php echo $this->name ?>"><a href="<?php echo $this->url ?>" title="<?php _e($this->description, BP_MEDIA_TXT_DOMAIN); ?>"><?php echo ( ( strlen($this->name) > 14 ) ? substr($this->name, 0, 14) . "&hellip;" : $this->name ); ?> </a><?php echo ' (' . count($this->media_entries) . ')'; ?></h3>
235
+ </li><?php
236
+ }
237
 
238
+ /**
239
+ * Returns the attachments linked with the albume
240
+ *
241
+ * @since BuddyPress Media 2.2
242
+ */
243
+
244
+ /**
245
+ *
246
+ * @return type
247
+ */
248
+ function get_entries() {
249
+ return $this->media_entries;
250
+ }
251
+
252
+ /**
253
+ * Returns the title of the album
254
+ *
255
+ * @since BuddyPress Media 2.2
256
+ */
257
+
258
+ /**
259
+ *
260
+ * @return type
261
+ */
262
+ function get_title() {
263
+ return $this->name;
264
+ }
265
+
266
+ /**
267
+ * Echoes the title of the album
268
+ *
269
+ * @since BuddyPress Media 2.2
270
+ */
271
+ function the_title() {
272
+ echo $this->name;
273
+ }
274
+
275
+ /**
276
+ * Returns the id of the album
277
+ *
278
+ * @since BuddyPress Media 2.2
279
+ */
280
+
281
+ /**
282
+ *
283
+ * @return type
284
+ */
285
+ function get_id() {
286
+ return $this->id;
287
+ }
288
+
289
+ /**
290
+ * Returns the url of the album
291
+ *
292
+ * @since BuddyPress Media 2.2
293
+ */
294
+
295
+ /**
296
+ *
297
+ * @return type
298
+ */
299
+ function get_url() {
300
+ return $this->url;
301
+ }
302
+
303
+ /**
304
+ * Returns the owner's id
305
+ *
306
+ * @since BuddyPress Media 2.2
307
+ */
308
+
309
+ /**
310
+ *
311
+ * @return type
312
+ */
313
+ function get_owner() {
314
+ return $this->owner;
315
+ }
316
+
317
+ /**
318
+ * Returns the edit url of the album
319
+ */
320
+
321
+ /**
322
+ *
323
+ * @return type
324
+ */
325
+ function get_edit_url() {
326
+ return $this->edit_url;
327
+ }
328
+
329
+ /**
330
+ * Returns the delete url of the album
331
+ */
332
+
333
+ /**
334
+ *
335
+ * @return type
336
+ */
337
+ function get_delete_url() {
338
+ return $this->delete_url;
339
+ }
340
+
341
+ /**
342
+ * Returns the group id to which the media belongs, 0 if it does not belong to any group
343
+ */
344
+
345
+ /**
346
+ *
347
+ * @return type
348
+ */
349
+ function get_group_id() {
350
+ return $this->group_id;
351
+ }
352
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  }
354
  ?>
app/main/profile/BPMediaAlbumScreen.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * Adds the Album Screen to the BuddyPress Profile
4
  *
@@ -11,152 +12,197 @@
11
  */
12
  class BPMediaAlbumScreen extends BPMediaScreen {
13
 
14
- public function __construct( $media_type, $slug ) {
15
- parent::__construct( $media_type, $slug );
16
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- function screen() {
19
- global $bp;
20
- if ( isset( $bp->action_variables[ 0 ] ) ) {
21
- switch ( $bp->action_variables[ 0 ] ) {
22
- case BP_MEDIA_ALBUMS_EDIT_SLUG :
23
- $this->edit_screen();
24
- break;
25
- case BP_MEDIA_ALBUMS_ENTRY_SLUG:
26
- $this->entry_screen();
27
- $this->template_actions( 'entry_screen' );
28
- break;
29
- case BP_MEDIA_DELETE_SLUG :
30
- if ( ! isset( $bp->action_variables[ 1 ] ) ) {
31
- $this->page_not_exist();
32
- }
33
- $this->entry_delete();
34
- break;
35
- default:
36
- $this->set_query();
37
- $this->template_actions( 'screen' );
38
- }
39
- } else {
40
- $this->set_query();
41
- $this->template_actions( 'screen' );
42
- }
43
- $this->template->loader();
44
- }
45
 
46
- function screen_content() {
47
- global $bp_media_albums_query;
 
 
 
 
48
 
49
- $this->hook_before();
50
 
51
- if ( $bp_media_albums_query && $bp_media_albums_query->have_posts() ):
52
- echo '<ul id="bp-media-list" class="bp-media-gallery item-list">';
53
- while ( $bp_media_albums_query->have_posts() ) : $bp_media_albums_query->the_post();
54
- $this->template->the_album_content();
55
- endwhile;
56
- echo '</ul>';
57
- $this->template->show_more();
58
- else:
59
- BPMediaFunction::show_formatted_error_message( sprintf( __( 'Sorry, no %s were found.', BP_MEDIA_TXT_DOMAIN ), $this->slug ), 'info' );
60
- endif;
61
- $this->hook_after();
62
- }
63
 
64
- function entry_screen() {
65
- global $bp, $bp_media_current_album;
66
- if ( ! $bp->action_variables[ 0 ] == BP_MEDIA_ALBUMS_ENTRY_SLUG )
67
- return false;
68
- try {
69
- $bp_media_current_album = new BPMediaAlbum( $bp->action_variables[ 1 ] );
70
- } catch ( Exception $e ) {
71
- /* Send the values to the cookie for page reload display */
72
- @setcookie( 'bp-message', $_COOKIE[ 'bp-message' ], time() + 60 * 60 * 24, COOKIEPATH );
73
- @setcookie( 'bp-message-type', $_COOKIE[ 'bp-message-type' ], time() + 60 * 60 * 24, COOKIEPATH );
74
- $this->template->redirect($this->media_const);
75
- exit;
76
- }
77
- }
 
 
 
 
 
 
78
 
79
- function entry_screen_content() {
80
- global $bp, $bp_media_current_album, $bp_media_query;
81
- if ( ! $bp->action_variables[ 0 ] == BP_MEDIA_ALBUMS_ENTRY_SLUG )
82
- return false;
83
- echo '<div class="bp_media_title">' . $bp_media_current_album->get_title() . '</div>';
84
- if ( bp_displayed_user_id() == bp_loggedin_user_id() ) {
85
- echo '<div class="activity-meta">';
86
- echo '<a href="' . $bp_media_current_album->get_edit_url() . '" class="button item-button bp-secondary-action bp-media-edit bp-media-edit-album" title="' . __('Rename Album', BP_MEDIA_TXT_DOMAIN) . '">' . __('Rename', BP_MEDIA_TXT_DOMAIN) . '</a>';
87
- echo '<a href="' . $bp_media_current_album->get_delete_url() . '" class="button item-button bp-secondary-action delete-activity-single confirm" rel="nofollow">' . __("Delete", BP_MEDIA_TXT_DOMAIN) . '</a>';
88
- echo '</div>';
89
- }
90
-
91
- $this->inner_query( $bp_media_current_album->get_id() );
92
- $this->hook_before();
93
- if ( $bp_media_current_album && $bp_media_query->have_posts() ):
94
- echo '<ul id="bp-media-list" class="bp-media-gallery item-list">';
95
- if ( bp_is_my_profile() || BPMediaGroup::can_upload() ) {
96
- echo '<li>';
97
- BPMediaUploadScreen::upload_screen_content();
98
- echo '</li>';
99
- }
100
- while ( $bp_media_query->have_posts() ) : $bp_media_query->the_post();
101
- $this->template->the_content();
102
- endwhile;
103
- echo '</ul>';
104
- $this->template->show_more();
105
- else:
106
- BPMediaFunction::show_formatted_error_message( __( 'Sorry, no media items were found in this album.', BP_MEDIA_TXT_DOMAIN ), 'info' );
107
- if ( bp_is_my_profile() || BPMediaGroup::can_upload() ) {
108
- echo '<div class="bp-media-area-allocate"></div>';
109
- BPMediaUploadScreen::upload_screen_content();
110
- }
111
- endif;
112
- $this->hook_after();
113
- }
114
 
115
- function set_query() {
116
- global $bp, $bp_media_albums_query;
117
- if ( isset( $bp->action_variables ) && is_array( $bp->action_variables ) && isset( $bp->action_variables[ 0 ] ) && $bp->action_variables[ 0 ] == 'page' && isset( $bp->action_variables[ 1 ] ) && is_numeric( $bp->action_variables[ 1 ] ) ) {
118
- $paged = $bp->action_variables[ 1 ];
119
- } else {
120
- $paged = 1;
121
- }
122
- if ( $bp->current_action == BP_MEDIA_ALBUMS_SLUG ) {
123
- $args = array(
124
- 'post_type' => 'bp_media_album',
125
- 'author' => $bp->displayed_user->id,
126
- 'paged' => $paged,
127
- 'meta_key' => 'bp-media-key',
128
- 'meta_value' => $bp->displayed_user->id,
129
- 'meta_compare' => '='
130
- );
131
- $bp_media_albums_query = new WP_Query( $args );
132
- }
133
- }
 
 
 
 
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
- function template_actions( $action ) {
137
- add_action( 'bp_template_content', array( $this, $action . '_content' ) );
138
- }
 
 
 
 
139
 
140
- function inner_query( $album_id = 0 ) {
141
- global $bp, $bp_media_query;
142
- $paged = 0;
143
- $action_variables = isset( $bp->canonical_stack[ 'action_variables' ] ) ? $bp->canonical_stack[ 'action_variables' ] : null;
144
- if ( isset( $action_variables ) && is_array( $action_variables ) && isset( $action_variables[ 0 ] ) ) {
145
- if ( $action_variables[ 0 ] == 'page' && isset( $action_variables[ 1 ] ) && is_numeric( $action_variables[ 1 ] ) )
146
- $paged = $action_variables[ 1 ];
147
- else if ( isset( $action_variables[ 1 ] ) && $action_variables[ 1 ] == 'page' && isset( $action_variables[ 2 ] ) && is_numeric( $action_variables[ 2 ] ) )
148
- $paged = $action_variables[ 2 ];
149
- }
150
- if ( ! $paged )
151
- $paged = 1;
152
- $args = array(
153
- 'post_type' => 'attachment',
154
- 'post_status' => 'any',
155
- 'post_parent' => $album_id,
156
- 'paged' => $paged
157
- );
158
- $bp_media_query = new WP_Query( $args );
159
- }
 
 
 
 
 
 
160
 
161
  }
162
 
1
  <?php
2
+
3
  /**
4
  * Adds the Album Screen to the BuddyPress Profile
5
  *
12
  */
13
  class BPMediaAlbumScreen extends BPMediaScreen {
14
 
15
+ /**
16
+ *
17
+ * @param type $media_type
18
+ * @param type $slug
19
+ */
20
+ public function __construct($media_type, $slug) {
21
+ parent::__construct($media_type, $slug);
22
+ }
23
+
24
+ /**
25
+ *
26
+ * @global type $bp
27
+ */
28
+ function screen() {
29
+ global $bp;
30
+ if (isset($bp->action_variables[0])) {
31
+ switch ($bp->action_variables[0]) {
32
+ case BP_MEDIA_ALBUMS_EDIT_SLUG :
33
+ $this->edit_screen();
34
+ break;
35
+ case BP_MEDIA_ALBUMS_ENTRY_SLUG:
36
+ $this->entry_screen();
37
+ $this->template_actions('entry_screen');
38
+ break;
39
+ case BP_MEDIA_DELETE_SLUG :
40
+ if (!isset($bp->action_variables[1])) {
41
+ $this->page_not_exist();
42
+ }
43
+ $this->entry_delete();
44
+ break;
45
+ default:
46
+ $this->set_query();
47
+ $this->template_actions('screen');
48
+ }
49
+ } else {
50
+ $this->set_query();
51
+ $this->template_actions('screen');
52
+ }
53
+ $this->template->loader();
54
+ }
55
 
56
+ /**
57
+ *
58
+ * @global type $bp_media_albums_query
59
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
+ /**
62
+ *
63
+ * @global type $bp_media_albums_query
64
+ */
65
+ function screen_content() {
66
+ global $bp_media_albums_query;
67
 
68
+ $this->hook_before();
69
 
70
+ if ($bp_media_albums_query && $bp_media_albums_query->have_posts()):
71
+ echo '<ul id="bp-media-list" class="bp-media-gallery item-list">';
72
+ while ($bp_media_albums_query->have_posts()) : $bp_media_albums_query->the_post();
73
+ $this->template->the_album_content();
74
+ endwhile;
75
+ echo '</ul>';
76
+ $this->template->show_more();
77
+ else:
78
+ BPMediaFunction::show_formatted_error_message(sprintf(__('Sorry, no %s were found.', BP_MEDIA_TXT_DOMAIN), $this->slug), 'info');
79
+ endif;
80
+ $this->hook_after();
81
+ }
82
 
83
+ /**
84
+ *
85
+ * @global type $bp
86
+ * @global BPMediaAlbum $bp_media_current_album
87
+ * @return boolean
88
+ */
89
+ function entry_screen() {
90
+ global $bp, $bp_media_current_album;
91
+ if (!$bp->action_variables[0] == BP_MEDIA_ALBUMS_ENTRY_SLUG)
92
+ return false;
93
+ try {
94
+ $bp_media_current_album = new BPMediaAlbum($bp->action_variables[1]);
95
+ } catch (Exception $e) {
96
+ /* Send the values to the cookie for page reload display */
97
+ @setcookie('bp-message', $_COOKIE['bp-message'], time() + 60 * 60 * 24, COOKIEPATH);
98
+ @setcookie('bp-message-type', $_COOKIE['bp-message-type'], time() + 60 * 60 * 24, COOKIEPATH);
99
+ $this->template->redirect($this->media_const);
100
+ exit;
101
+ }
102
+ }
103
 
104
+ /**
105
+ *
106
+ * @global type $bp
107
+ * @global BPMediaAlbum $bp_media_current_album
108
+ * @global type $bp_media_query
109
+ * @return boolean
110
+ */
111
+ function entry_screen_content() {
112
+ global $bp, $bp_media_current_album, $bp_media_query;
113
+ if (!$bp->action_variables[0] == BP_MEDIA_ALBUMS_ENTRY_SLUG)
114
+ return false;
115
+ echo '<div class="bp_media_title">' . $bp_media_current_album->get_title() . '</div>';
116
+ if (bp_displayed_user_id() == bp_loggedin_user_id()) {
117
+ echo '<div class="activity-meta">';
118
+ echo '<a href="' . $bp_media_current_album->get_edit_url() . '" class="button item-button bp-secondary-action bp-media-edit bp-media-edit-album" title="' . __('Rename Album', BP_MEDIA_TXT_DOMAIN) . '">' . __('Rename', BP_MEDIA_TXT_DOMAIN) . '</a>';
119
+ echo '<a href="' . $bp_media_current_album->get_delete_url() . '" class="button item-button bp-secondary-action delete-activity-single confirm" rel="nofollow">' . __("Delete", BP_MEDIA_TXT_DOMAIN) . '</a>';
120
+ echo '</div>';
121
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
+ $this->inner_query($bp_media_current_album->get_id());
124
+ $this->hook_before();
125
+ if ($bp_media_current_album && $bp_media_query->have_posts()):
126
+ echo '<ul id="bp-media-list" class="bp-media-gallery item-list">';
127
+ if (bp_is_my_profile() || BPMediaGroup::can_upload()) {
128
+ echo '<li>';
129
+ BPMediaUploadScreen::upload_screen_content();
130
+ echo '</li>';
131
+ }
132
+ while ($bp_media_query->have_posts()) : $bp_media_query->the_post();
133
+ $this->template->the_content();
134
+ endwhile;
135
+ echo '</ul>';
136
+ $this->template->show_more();
137
+ else:
138
+ BPMediaFunction::show_formatted_error_message(__('Sorry, no media items were found in this album.', BP_MEDIA_TXT_DOMAIN), 'info');
139
+ if (bp_is_my_profile() || BPMediaGroup::can_upload()) {
140
+ echo '<div class="bp-media-area-allocate"></div>';
141
+ BPMediaUploadScreen::upload_screen_content();
142
+ }
143
+ endif;
144
+ $this->hook_after();
145
+ }
146
 
147
+ /**
148
+ *
149
+ * @global type $bp
150
+ * @global type $bp_media_albums_query
151
+ */
152
+ function set_query() {
153
+ global $bp, $bp_media_albums_query;
154
+ if (isset($bp->action_variables) && is_array($bp->action_variables) && isset($bp->action_variables[0]) && $bp->action_variables[0] == 'page' && isset($bp->action_variables[1]) && is_numeric($bp->action_variables[1])) {
155
+ $paged = $bp->action_variables[1];
156
+ } else {
157
+ $paged = 1;
158
+ }
159
+ if ($bp->current_action == BP_MEDIA_ALBUMS_SLUG) {
160
+ $args = array(
161
+ 'post_type' => 'bp_media_album',
162
+ 'author' => $bp->displayed_user->id,
163
+ 'paged' => $paged,
164
+ 'meta_key' => 'bp-media-key',
165
+ 'meta_value' => $bp->displayed_user->id,
166
+ 'meta_compare' => '='
167
+ );
168
+ $bp_media_albums_query = new WP_Query($args);
169
+ }
170
+ }
171
 
172
+ /**
173
+ *
174
+ * @param type $action
175
+ */
176
+ function template_actions($action) {
177
+ add_action('bp_template_content', array($this, $action . '_content'));
178
+ }
179
 
180
+ /**
181
+ *
182
+ * @global type $bp
183
+ * @global type $bp_media_query
184
+ * @param type $album_id
185
+ */
186
+ function inner_query($album_id = 0) {
187
+ global $bp, $bp_media_query;
188
+ $paged = 0;
189
+ $action_variables = isset($bp->canonical_stack['action_variables']) ? $bp->canonical_stack['action_variables'] : null;
190
+ if (isset($action_variables) && is_array($action_variables) && isset($action_variables[0])) {
191
+ if ($action_variables[0] == 'page' && isset($action_variables[1]) && is_numeric($action_variables[1]))
192
+ $paged = $action_variables[1];
193
+ else if (isset($action_variables[1]) && $action_variables[1] == 'page' && isset($action_variables[2]) && is_numeric($action_variables[2]))
194
+ $paged = $action_variables[2];
195
+ }
196
+ if (!$paged)
197
+ $paged = 1;
198
+ $args = array(
199
+ 'post_type' => 'attachment',
200
+ 'post_status' => 'any',
201
+ 'post_parent' => $album_id,
202
+ 'paged' => $paged
203
+ );
204
+ $bp_media_query = new WP_Query($args);
205
+ }
206
 
207
  }
208
 
app/main/profile/BPMediaScreen.php CHANGED
@@ -11,403 +11,445 @@
11
  */
12
  class BPMediaScreen {
13
 
14
- /**
15
- *
16
- * @var string Slug to be used for the media type/screen
17
- */
18
- public $slug = NULL;
19
-
20
- /**
21
- *
22
- * @var string Media type for use in the class
23
- */
24
- public $media_type = '';
25
-
26
- /**
27
- *
28
- * @var string Media type string used to build constants
29
- */
30
- public $media_const = '';
31
-
32
- /**
33
- *
34
- * @var string Plural media type string
35
- */
36
- public $medias_type = '';
37
- public $template = '';
38
-
39
- /**
40
- * Populates all the variables of the class, $media_type, $media_const, $medias_type
41
- *
42
- * @param string $media_type The media type for which the screen is going to be created
43
- * @param string $slug The slug to use for the media type
44
- */
45
- public function __construct( $media_type, $slug ) {
46
- $this->slug = $slug;
47
- $this->media_constant( $media_type );
48
- $this->template = new BPMediaTemplate();
49
- }
50
-
51
- /**
52
- * Populates variable $media_type
53
- * @param string $media_type
54
- */
55
- private function media( $media_type ) {
56
- $this->media_type = $media_type;
57
- }
58
-
59
- /**
60
- * Creates plural
61
- * @param type $media_type
62
- */
63
- private function medias( $media_type ) {
64
- $this->media( $media_type );
65
- $media = strtolower( $this->media_type );
66
- if ( $media != 'audio' ) {
67
- $media .= 's';
68
- }
69
- $this->medias_type = $media;
70
- }
71
-
72
- /**
73
- *
74
- * @param type $media_type
75
- */
76
- private function media_constant( $media_type ) {
77
- $this->medias( $media_type );
78
- $this->media_const = strtoupper( $this->medias_type );
79
- }
80
-
81
- /**
82
- *
83
- */
84
- public function hook_before() {
85
- do_action( 'bp_media_before_content' );
86
- do_action( 'bp_media_before_' . $this->slug );
87
- }
88
-
89
- /**
90
- *
91
- */
92
- public function hook_after() {
93
- do_action( 'bp_media_after_' . $this->slug );
94
- do_action( 'bp_media_after_content' );
95
- }
96
-
97
- /**
98
- *
99
- * @global type $bp_media
100
- */
101
- private function page_not_exist() {
102
- @setcookie( 'bp-message', __( 'The requested url does not exist', BP_MEDIA_TXT_DOMAIN ), time() + 60 * 60 * 24, COOKIEPATH );
103
- @setcookie( 'bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH );
104
- $this->template->redirect( $this->media_const );
105
- exit;
106
- }
107
-
108
- /**
109
- *
110
- * @global type $bp_media
111
- */
112
- private function screen_title() {
113
- printf( __( '%s List Page', BP_MEDIA_TXT_DOMAIN ), $this->slug );
114
- }
115
-
116
- /**
117
- *
118
- * @global type $bp
119
- */
120
- public function screen() {
121
- $editslug = 'BP_MEDIA_' . $this->media_const . '_EDIT_SLUG';
122
- $entryslug = 'BP_MEDIA_' . $this->media_const . '_ENTRY_SLUG';
123
-
124
- global $bp;
125
-
126
- remove_filter( 'bp_activity_get_user_join_filter', 'BPMediaFilters::activity_query_filter', 10 );
127
- if ( isset( $bp->action_variables[ 0 ] ) ) {
128
- switch ( $bp->action_variables[ 0 ] ) {
129
- case constant( $editslug ) :
130
- $this->edit_screen();
131
- break;
132
- case constant( $entryslug ) :
133
- $this->entry_screen();
134
- break;
135
- case BP_MEDIA_DELETE_SLUG :
136
- if ( ! isset( $bp->action_variables[ 1 ] ) ) {
137
- $this->page_not_exist();
138
- }
139
- $this->entry_delete();
140
- break;
141
- default:
142
- $this->set_query();
143
- add_action( 'bp_template_content', array( $this, 'screen_content' ) );
144
- }
145
- } else {
146
- $this->set_query();
147
- add_action( 'bp_template_content', array( $this, 'screen_content' ) );
148
- }
149
- $this->template->loader();
150
- }
151
-
152
- /**
153
- *
154
- * @global type $bp_media
155
- * @global type $bp_media_query
156
- * @global type $bp_media_albums_query
157
- */
158
- function screen_content() {
159
- global $bp_media_query, $bp_media_albums_query;
160
- $this->set_query();
161
-
162
- $this->hook_before();
163
- if ( $bp_media_query && $bp_media_query->have_posts() ):
164
- echo '<ul id="bp-media-list" class="bp-media-gallery item-list">';
165
- if ( bp_is_my_profile() || BPMediaGroup::can_upload() ) {
166
- echo '<li>';
167
- BPMediaUploadScreen::upload_screen_content();
168
- echo '</li>';
169
- }
170
- while ( $bp_media_query->have_posts() ) : $bp_media_query->the_post();
171
- $this->template->the_content();
172
- endwhile;
173
- echo '</ul>';
174
- $this->template->show_more();
175
- else:
176
- BPMediaFunction::show_formatted_error_message( sprintf( __( 'Sorry, no %s were found.', BP_MEDIA_TXT_DOMAIN ), $this->slug ), 'info' );
177
- if ( bp_is_my_profile() || BPMediaGroup::can_upload() ) {
178
- echo '<div class="bp-media-area-allocate"></div>';
179
- BPMediaUploadScreen::upload_screen_content();
180
- }
181
- endif;
182
- $this->hook_after();
183
- }
184
-
185
- /**
186
- *
187
- * @global type $bp
188
- * @global BPMediaHostWordpress $bp_media_current_entry
189
- * @return boolean
190
- */
191
- function entry_screen() {
192
-
193
- global $bp, $bp_media_current_entry;
194
- $entryslug = 'BP_MEDIA_' . $this->media_const . '_ENTRY_SLUG';
195
- if ( ! $bp->action_variables[ 0 ] == constant( $entryslug ) )
196
- return false;
197
- try {
198
-
199
- $bp_media_current_entry = new BPMediaHostWordpress( $bp->action_variables[ 1 ] );
200
- } catch ( Exception $e ) {
201
- /* Send the values to the cookie for page reload display */
202
- @setcookie( 'bp-message', $_COOKIE[ 'bp-message' ], time() + 60 * 60 * 24, COOKIEPATH );
203
- @setcookie( 'bp-message-type', $_COOKIE[ 'bp-message-type' ], time() + 60 * 60 * 24, COOKIEPATH );
204
- $this->template->redirect( $this->media_const );
205
- exit;
206
- }
207
-
208
- $this->template_actions( 'entry_screen' );
209
- $this->template->loader();
210
- }
211
-
212
- /**
213
- *
214
- * @global BPMediaHostWordpress $bp_media_current_entry
215
- */
216
- function entry_screen_title() {
217
-
218
- global $bp_media_current_entry;
219
- /** @var $bp_media_current_entry BPMediaHostWordpress */
220
- if ( is_object( $bp_media_current_entry ) )
221
- echo $bp_media_current_entry->get_media_single_title();
222
- }
223
-
224
- /**
225
- *
226
- * @global type $bp
227
- * @global BPMediaHostWordpress $bp_media_current_entry
228
- * @return boolean
229
- */
230
- function entry_screen_content() {
231
- global $bp, $bp_media_current_entry;
232
- $entryslug = 'BP_MEDIA_' . $this->media_const . '_ENTRY_SLUG';
233
- $this->hook_before();
234
- if ( ! $bp->action_variables[ 0 ] == constant( $entryslug ) )
235
- return false;
236
- echo '<div class="bp-media-single bp-media-image">';
237
- echo $bp_media_current_entry->get_media_single_content();
238
- echo $bp_media_current_entry->show_comment_form();
239
- echo '</div>';
240
- $this->hook_after();
241
- }
242
-
243
- /**
244
- *
245
- * @global BPMediaHostWordpress $bp_media_current_entry
246
- * @global type $bp
247
- */
248
- function edit_screen() {
249
- global $bp_media_current_entry, $bp;
250
- if ( ! isset( $bp->action_variables[ 1 ] ) ) {
251
- $this->page_not_exist();
252
- }
253
- //Creating global bp_media_current_entry for later use
254
- try {
255
- $bp_media_current_entry = new BPMediaHostWordpress( $bp->action_variables[ 1 ] );
256
- } catch ( Exception $e ) {
257
- /* Send the values to the cookie for page reload display */
258
- @setcookie( 'bp-message', $e->getMessage(), time() + 60 * 60 * 24, COOKIEPATH );
259
- @setcookie( 'bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH );
260
- $this->template->redirect( $this->media_const );
261
- exit;
262
- }
263
- BPMediaFunction::check_user();
264
-
265
- //For saving the data if the form is submitted
266
- if ( array_key_exists( 'bp_media_title', $_POST ) ) {
267
- BPMediaFunction::update_media();
268
- }
269
- $this->template_actions( 'edit_screen' );
270
- $this->template->loader();
271
- }
272
-
273
- /**
274
- *
275
- * @global type $bp_media
276
- */
277
- function edit_screen_title() {
278
- printf( __( 'Edit %s', BP_MEDIA_TXT_DOMAIN ), $this->slug );
279
- }
280
-
281
- /**
282
- *
283
- * @global type $bp
284
- * @global BPMediaHostWordpress $bp_media_current_entry
285
- * @global type $bp_media_default_excerpts
286
- * @global type $bp_media
287
- */
288
- function edit_screen_content() {
289
- global $bp_media_current_entry, $bp_media_default_excerpts;
290
- ?>
291
- <form method="post" class="standard-form" id="bp-media-upload-form">
292
- <label for="bp-media-upload-input-title">
293
- <?php printf( __( '%s Title', BP_MEDIA_TXT_DOMAIN ), ucfirst( $this->media_type ) ); ?>
294
- </label>
295
- <input id="bp-media-upload-input-title" type="text" name="bp_media_title" class="settings-input"
296
- maxlength="<?php echo max( array( $bp_media_default_excerpts[ 'single_entry_title' ], $bp_media_default_excerpts[ 'activity_entry_title' ] ) ) ?>"
297
- value="<?php echo $bp_media_current_entry->get_title(); ?>" />
298
- <?php if ( $bp_media_current_entry->get_type() != 'album' ) { ?>
299
- <label for="bp-media-upload-input-description">
300
- <?php printf( __( '%s Description', BP_MEDIA_TXT_DOMAIN ), ucfirst( $this->media_type ) ); ?>
301
- </label>
302
- <input id="bp-media-upload-input-description" type="text" name="bp_media_description" class="settings-input"
303
- maxlength="<?php echo max( array( $bp_media_default_excerpts[ 'single_entry_description' ], $bp_media_default_excerpts[ 'activity_entry_description' ] ) ) ?>"
304
- value="<?php echo $bp_media_current_entry->get_content(); ?>" />
305
- <?php }
306
- do_action('bp_media_add_media_fields', $this->media_type); ?>
307
- <div class="submit">
308
- <input type="submit" class="auto" value="<?php _e( 'Update', BP_MEDIA_TXT_DOMAIN ); ?>" />
309
- <a href="<?php echo $bp_media_current_entry->get_url(); ?>" class="button" title="<?php _e( 'Back to Media File', BP_MEDIA_TXT_DOMAIN ); ?>">
310
- <?php _e( 'Back to Media', BP_MEDIA_TXT_DOMAIN ); ?>
311
- </a>
312
- </div>
313
- </form>
314
- <?php
315
- }
316
-
317
- /**
318
- *
319
- * @global type $bp
320
- * @global type $bp_media
321
- * @global BPMediaHostWordpress $bp_media_current_entry
322
- */
323
- function entry_delete() {
324
- global $bp;
325
- if ( bp_loggedin_user_id() != bp_displayed_user_id() ) {
326
- bp_core_no_access( array(
327
- 'message' => __( 'You do not have access to this page.', BP_MEDIA_TXT_DOMAIN ),
328
- 'root' => bp_displayed_user_domain(),
329
- 'redirect' => false
330
- ) );
331
- exit;
332
- }
333
- if ( ! isset( $bp->action_variables[ 1 ] ) ) {
334
- @setcookie( 'bp-message', __( 'The requested url does not exist', BP_MEDIA_TXT_DOMAIN ), time() + 60 * 60 * 24, COOKIEPATH );
335
- @setcookie( 'bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH );
336
- $this->template->redirect( $this->media_const );
337
- exit;
338
- }
339
- global $bp_media_current_entry;
340
- try {
341
- $bp_media_current_entry = new BPMediaHostWordpress( $bp->action_variables[ 1 ] );
342
- } catch ( Exception $e ) {
343
- /* Send the values to the cookie for page reload display */
344
- @setcookie( 'bp-message', $e->getMessage(), time() + 60 * 60 * 24, COOKIEPATH );
345
- @setcookie( 'bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH );
346
- $this->template->redirect( $this->media_const );
347
- exit;
348
- }
349
- $post_id = $bp_media_current_entry->get_id();
350
- $activity_id = get_post_meta( $post_id, 'bp_media_child_activity', true );
351
-
352
- bp_activity_delete_by_activity_id( $activity_id );
353
- $bp_media_current_entry->delete_media();
354
-
355
- @setcookie( 'bp-message', __( 'Media deleted successfully', BP_MEDIA_TXT_DOMAIN ), time() + 60 * 60 * 24, COOKIEPATH );
356
- @setcookie( 'bp-message-type', 'success', time() + 60 * 60 * 24, COOKIEPATH );
357
- $this->template->redirect( $this->media_const );
358
- exit;
359
- }
360
-
361
- /**
362
- *
363
- * @param type $action
364
- */
365
- function template_actions( $action ) {
366
- add_action( 'bp_template_title', array( $this, $action . '_title' ) );
367
- add_action( 'bp_template_content', array( $this, $action . '_content' ) );
368
- }
369
-
370
- /**
371
- *
372
- * @global type $bp
373
- * @global type $bp_media_posts_per_page
374
- * @global type $bp_media_query
375
- */
376
- public function set_query() {
377
- global $bp, $bp_media_posts_per_page, $bp_media_query;
378
- switch ( $bp->current_action ) {
379
- case BP_MEDIA_IMAGES_SLUG:
380
- $type = 'image';
381
- break;
382
- case BP_MEDIA_AUDIO_SLUG:
383
- $type = 'audio';
384
- break;
385
- case BP_MEDIA_VIDEOS_SLUG:
386
- $type = 'video';
387
- break;
388
- default :
389
- $type = null;
390
- }
391
- if ( isset( $bp->action_variables ) && is_array( $bp->action_variables ) && isset( $bp->action_variables[ 0 ] ) && $bp->action_variables[ 0 ] == 'page' && isset( $bp->action_variables[ 1 ] ) && is_numeric( $bp->action_variables[ 1 ] ) ) {
392
- $paged = $bp->action_variables[ 1 ];
393
- } else {
394
- $paged = 1;
395
- }
396
- if ( $type ) {
397
- $args = array(
398
- 'post_type' => 'attachment',
399
- 'post_status' => 'any',
400
- 'post_mime_type' => $type,
401
- 'author' => $bp->displayed_user->id,
402
- 'meta_key' => 'bp-media-key',
403
- 'meta_value' => $bp->displayed_user->id,
404
- 'meta_compare' => '=',
405
- 'paged' => $paged,
406
- 'posts_per_page' => $bp_media_posts_per_page
407
- );
408
-
409
- $bp_media_query = new WP_Query( $args );
410
- }
411
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
  }
413
  ?>
11
  */
12
  class BPMediaScreen {
13
 
14
+ /**
15
+ *
16
+ * @var string Slug to be used for the media type/screen
17
+ */
18
+ public $slug = NULL;
19
+
20
+ /**
21
+ *
22
+ * @var string Media type for use in the class
23
+ */
24
+ public $media_type = '';
25
+
26
+ /**
27
+ *
28
+ * @var string Media type string used to build constants
29
+ */
30
+ public $media_const = '';
31
+
32
+ /**
33
+ *
34
+ * @var string Plural media type string
35
+ */
36
+ public $medias_type = '';
37
+ public $template = '';
38
+
39
+ /**
40
+ * Populates all the variables of the class, $media_type, $media_const, $medias_type
41
+ *
42
+ * @param string $media_type The media type for which the screen is going to be created
43
+ * @param string $slug The slug to use for the media type
44
+ */
45
+
46
+ /**
47
+ *
48
+ * @param type $media_type
49
+ * @param type $slug
50
+ */
51
+ public function __construct($media_type, $slug) {
52
+ $this->slug = $slug;
53
+ $this->media_constant($media_type);
54
+ $this->template = new BPMediaTemplate();
55
+ }
56
+
57
+ /**
58
+ * Populates variable $media_type
59
+ * @param string $media_type
60
+ */
61
+
62
+ /**
63
+ *
64
+ * @param type $media_type
65
+ */
66
+ private function media($media_type) {
67
+ $this->media_type = $media_type;
68
+ }
69
+
70
+ /**
71
+ * Creates plural
72
+ * @param type $media_type
73
+ */
74
+
75
+ /**
76
+ *
77
+ * @param type $media_type
78
+ */
79
+ private function medias($media_type) {
80
+ $this->media($media_type);
81
+ $media = strtolower($this->media_type);
82
+ if ($media != 'audio') {
83
+ $media .= 's';
84
+ }
85
+ $this->medias_type = $media;
86
+ }
87
+
88
+ /**
89
+ *
90
+ * @param type $media_type
91
+ */
92
+ private function media_constant($media_type) {
93
+ $this->medias($media_type);
94
+ $this->media_const = strtoupper($this->medias_type);
95
+ }
96
+
97
+ public function hook_before() {
98
+ do_action('bp_media_before_content');
99
+ do_action('bp_media_before_' . $this->slug);
100
+ }
101
+
102
+ public function hook_after() {
103
+ do_action('bp_media_after_' . $this->slug);
104
+ do_action('bp_media_after_content');
105
+ }
106
+
107
+ /**
108
+ *
109
+ * @global type $bp_media
110
+ */
111
+ private function page_not_exist() {
112
+ @setcookie('bp-message', __('The requested url does not exist', BP_MEDIA_TXT_DOMAIN), time() + 60 * 60 * 24, COOKIEPATH);
113
+ @setcookie('bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH);
114
+ $this->template->redirect($this->media_const);
115
+ exit;
116
+ }
117
+
118
+ /**
119
+ *
120
+ * @global type $bp_media
121
+ */
122
+ private function screen_title() {
123
+ printf(__('%s List Page', BP_MEDIA_TXT_DOMAIN), $this->slug);
124
+ }
125
+
126
+ /**
127
+ *
128
+ * @global type $bp
129
+ */
130
+ public function screen() {
131
+ $editslug = 'BP_MEDIA_' . $this->media_const . '_EDIT_SLUG';
132
+ $entryslug = 'BP_MEDIA_' . $this->media_const . '_ENTRY_SLUG';
133
+
134
+ global $bp;
135
+
136
+ remove_filter('bp_activity_get_user_join_filter', 'BPMediaFilters::activity_query_filter', 10);
137
+ if (isset($bp->action_variables[0])) {
138
+ switch ($bp->action_variables[0]) {
139
+ case constant($editslug) :
140
+ $this->edit_screen();
141
+ break;
142
+ case constant($entryslug) :
143
+ $this->entry_screen();
144
+ break;
145
+ case BP_MEDIA_DELETE_SLUG :
146
+ if (!isset($bp->action_variables[1])) {
147
+ $this->page_not_exist();
148
+ }
149
+ $this->entry_delete();
150
+ break;
151
+ default:
152
+ $this->set_query();
153
+ add_action('bp_template_content', array($this, 'screen_content'));
154
+ }
155
+ } else {
156
+ $this->set_query();
157
+ add_action('bp_template_content', array($this, 'screen_content'));
158
+ }
159
+ $this->template->loader();
160
+ }
161
+
162
+ /**
163
+ *
164
+ * @global type $bp_media
165
+ * @global type $bp_media_query
166
+ * @global type $bp_media_albums_query
167
+ */
168
+
169
+ /**
170
+ *
171
+ * @global type $bp_media_query
172
+ * @global type $bp_media_albums_query
173
+ */
174
+ function screen_content() {
175
+ global $bp_media_query, $bp_media_albums_query;
176
+ $this->set_query();
177
+
178
+ $this->hook_before();
179
+ if ($bp_media_query && $bp_media_query->have_posts()):
180
+ echo '<ul id="bp-media-list" class="bp-media-gallery item-list">';
181
+ if (bp_is_my_profile() || BPMediaGroup::can_upload()) {
182
+ echo '<li>';
183
+ BPMediaUploadScreen::upload_screen_content();
184
+ echo '</li>';
185
+ }
186
+ while ($bp_media_query->have_posts()) : $bp_media_query->the_post();
187
+ $this->template->the_content();
188
+ endwhile;
189
+ echo '</ul>';
190
+ $this->template->show_more();
191
+ else:
192
+ BPMediaFunction::show_formatted_error_message(sprintf(__('Sorry, no %s were found.', BP_MEDIA_TXT_DOMAIN), $this->slug), 'info');
193
+ if (bp_is_my_profile() || BPMediaGroup::can_upload()) {
194
+ echo '<div class="bp-media-area-allocate"></div>';
195
+ BPMediaUploadScreen::upload_screen_content();
196
+ }
197
+ endif;
198
+ $this->hook_after();
199
+ }
200
+
201
+ /**
202
+ *
203
+ * @global type $bp
204
+ * @global BPMediaHostWordpress $bp_media_current_entry
205
+ * @return boolean
206
+ */
207
+ function entry_screen() {
208
+
209
+ global $bp, $bp_media_current_entry;
210
+ $entryslug = 'BP_MEDIA_' . $this->media_const . '_ENTRY_SLUG';
211
+ if (!$bp->action_variables[0] == constant($entryslug))
212
+ return false;
213
+ try {
214
+
215
+ $bp_media_current_entry = new BPMediaHostWordpress($bp->action_variables[1]);
216
+ } catch (Exception $e) {
217
+ /* Send the values to the cookie for page reload display */
218
+ @setcookie('bp-message', $_COOKIE['bp-message'], time() + 60 * 60 * 24, COOKIEPATH);
219
+ @setcookie('bp-message-type', $_COOKIE['bp-message-type'], time() + 60 * 60 * 24, COOKIEPATH);
220
+ $this->template->redirect($this->media_const);
221
+ exit;
222
+ }
223
+
224
+ $this->template_actions('entry_screen');
225
+ $this->template->loader();
226
+ }
227
+
228
+ /**
229
+ *
230
+ * @global BPMediaHostWordpress $bp_media_current_entry
231
+ */
232
+ function entry_screen_title() {
233
+
234
+ global $bp_media_current_entry;
235
+ /** @var $bp_media_current_entry BPMediaHostWordpress */
236
+ if (is_object($bp_media_current_entry))
237
+ echo $bp_media_current_entry->get_media_single_title();
238
+ }
239
+
240
+ /**
241
+ *
242
+ * @global type $bp
243
+ * @global BPMediaHostWordpress $bp_media_current_entry
244
+ * @return boolean
245
+ */
246
+ function entry_screen_content() {
247
+ global $bp, $bp_media_current_entry;
248
+ $entryslug = 'BP_MEDIA_' . $this->media_const . '_ENTRY_SLUG';
249
+ $this->hook_before();
250
+ if (!$bp->action_variables[0] == constant($entryslug))
251
+ return false;
252
+ echo '<div class="bp-media-single bp-media-image">';
253
+ echo $bp_media_current_entry->get_media_single_content();
254
+ echo $bp_media_current_entry->show_comment_form();
255
+ echo '</div>';
256
+ $this->hook_after();
257
+ }
258
+
259
+ /**
260
+ *
261
+ * @global BPMediaHostWordpress $bp_media_current_entry
262
+ * @global type $bp
263
+ */
264
+ function edit_screen() {
265
+ global $bp_media_current_entry, $bp;
266
+ if (!isset($bp->action_variables[1])) {
267
+ $this->page_not_exist();
268
+ }
269
+ //Creating global bp_media_current_entry for later use
270
+ try {
271
+ $bp_media_current_entry = new BPMediaHostWordpress($bp->action_variables[1]);
272
+ } catch (Exception $e) {
273
+ /* Send the values to the cookie for page reload display */
274
+ @setcookie('bp-message', $e->getMessage(), time() + 60 * 60 * 24, COOKIEPATH);
275
+ @setcookie('bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH);
276
+ $this->template->redirect($this->media_const);
277
+ exit;
278
+ }
279
+ BPMediaFunction::check_user();
280
+
281
+ //For saving the data if the form is submitted
282
+ if (array_key_exists('bp_media_title', $_POST)) {
283
+ BPMediaFunction::update_media();
284
+ }
285
+ $this->template_actions('edit_screen');
286
+ $this->template->loader();
287
+ }
288
+
289
+ /**
290
+ *
291
+ * @global type $bp_media
292
+ */
293
+ function edit_screen_title() {
294
+ printf(__('Edit %s', BP_MEDIA_TXT_DOMAIN), $this->slug);
295
+ }
296
+
297
+ /**
298
+ *
299
+ * @global type $bp
300
+ * @global BPMediaHostWordpress $bp_media_current_entry
301
+ * @global type $bp_media_default_excerpts
302
+ * @global type $bp_media
303
+ */
304
+
305
+ /**
306
+ *
307
+ * @global BPMediaHostWordpress $bp_media_current_entry
308
+ * @global type $bp_media_default_excerpts
309
+ */
310
+ function edit_screen_content() {
311
+ global $bp_media_current_entry, $bp_media_default_excerpts;
312
+ ?>
313
+ <form method="post" class="standard-form" id="bp-media-upload-form">
314
+ <label for="bp-media-upload-input-title">
315
+ <?php printf(__('%s Title', BP_MEDIA_TXT_DOMAIN), ucfirst($this->media_type)); ?>
316
+ </label>
317
+ <input id="bp-media-upload-input-title" type="text" name="bp_media_title" class="settings-input"
318
+ maxlength="<?php echo max(array($bp_media_default_excerpts['single_entry_title'], $bp_media_default_excerpts['activity_entry_title'])) ?>"
319
+ value="<?php echo $bp_media_current_entry->get_title(); ?>" />
320
+ <?php if ($bp_media_current_entry->get_type() != 'album') { ?>
321
+ <label for="bp-media-upload-input-description">
322
+ <?php printf(__('%s Description', BP_MEDIA_TXT_DOMAIN), ucfirst($this->media_type)); ?>
323
+ </label>
324
+ <input id="bp-media-upload-input-description" type="text" name="bp_media_description" class="settings-input"
325
+ maxlength="<?php echo max(array($bp_media_default_excerpts['single_entry_description'], $bp_media_default_excerpts['activity_entry_description'])) ?>"
326
+ value="<?php echo $bp_media_current_entry->get_content(); ?>" />
327
+ <?php }
328
+ do_action('bp_media_add_media_fields', $this->media_type);
329
+ ?>
330
+ <div class="submit">
331
+ <input type="submit" class="auto" value="<?php _e('Update', BP_MEDIA_TXT_DOMAIN); ?>" />
332
+ <a href="<?php echo $bp_media_current_entry->get_url(); ?>" class="button" title="<?php _e('Back to Media File', BP_MEDIA_TXT_DOMAIN); ?>">
333
+ <?php _e('Back to Media', BP_MEDIA_TXT_DOMAIN); ?>
334
+ </a>
335
+ </div>
336
+ </form>
337
+ <?php
338
+ }
339
+
340
+ /**
341
+ *
342
+ * @global type $bp
343
+ * @global type $bp_media
344
+ * @global BPMediaHostWordpress $bp_media_current_entry
345
+ */
346
+
347
+ /**
348
+ *
349
+ * @global type $bp
350
+ * @global BPMediaHostWordpress $bp_media_current_entry
351
+ */
352
+ function entry_delete() {
353
+ global $bp;
354
+ if (bp_loggedin_user_id() != bp_displayed_user_id()) {
355
+ bp_core_no_access(array(
356
+ 'message' => __('You do not have access to this page.', BP_MEDIA_TXT_DOMAIN),
357
+ 'root' => bp_displayed_user_domain(),
358
+ 'redirect' => false
359
+ ));
360
+ exit;
361
+ }
362
+ if (!isset($bp->action_variables[1])) {
363
+ @setcookie('bp-message', __('The requested url does not exist', BP_MEDIA_TXT_DOMAIN), time() + 60 * 60 * 24, COOKIEPATH);
364
+ @setcookie('bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH);
365
+ $this->template->redirect($this->media_const);
366
+ exit;
367
+ }
368
+ global $bp_media_current_entry;
369
+ try {
370
+ $bp_media_current_entry = new BPMediaHostWordpress($bp->action_variables[1]);
371
+ } catch (Exception $e) {
372
+ /* Send the values to the cookie for page reload display */
373
+ @setcookie('bp-message', $e->getMessage(), time() + 60 * 60 * 24, COOKIEPATH);
374
+ @setcookie('bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH);
375
+ $this->template->redirect($this->media_const);
376
+ exit;
377
+ }
378
+ $post_id = $bp_media_current_entry->get_id();
379
+ $activity_id = get_post_meta($post_id, 'bp_media_child_activity', true);
380
+
381
+ bp_activity_delete_by_activity_id($activity_id);
382
+ $bp_media_current_entry->delete_media();
383
+
384
+ @setcookie('bp-message', __('Media deleted successfully', BP_MEDIA_TXT_DOMAIN), time() + 60 * 60 * 24, COOKIEPATH);
385
+ @setcookie('bp-message-type', 'success', time() + 60 * 60 * 24, COOKIEPATH);
386
+ $this->template->redirect($this->media_const);
387
+ exit;
388
+ }
389
+
390
+ /**
391
+ *
392
+ * @param type $action
393
+ */
394
+
395
+ /**
396
+ *
397
+ * @param type $action
398
+ */
399
+ function template_actions($action) {
400
+ add_action('bp_template_title', array($this, $action . '_title'));
401
+ add_action('bp_template_content', array($this, $action . '_content'));
402
+ }
403
+
404
+ /**
405
+ *
406
+ * @global type $bp
407
+ * @global type $bp_media_posts_per_page
408
+ * @global type $bp_media_query
409
+ */
410
+
411
+ /**
412
+ *
413
+ * @global type $bp
414
+ * @global type $bp_media_posts_per_page
415
+ * @global type $bp_media_query
416
+ */
417
+ public function set_query() {
418
+ global $bp, $bp_media_posts_per_page, $bp_media_query;
419
+ switch ($bp->current_action) {
420
+ case BP_MEDIA_IMAGES_SLUG:
421
+ $type = 'image';
422
+ break;
423
+ case BP_MEDIA_AUDIO_SLUG:
424
+ $type = 'audio';
425
+ break;
426
+ case BP_MEDIA_VIDEOS_SLUG:
427
+ $type = 'video';
428
+ break;
429
+ default :
430
+ $type = null;
431
+ }
432
+ if (isset($bp->action_variables) && is_array($bp->action_variables) && isset($bp->action_variables[0]) && $bp->action_variables[0] == 'page' && isset($bp->action_variables[1]) && is_numeric($bp->action_variables[1])) {
433
+ $paged = $bp->action_variables[1];
434
+ } else {
435
+ $paged = 1;
436
+ }
437
+ if ($type) {
438
+ $args = array(
439
+ 'post_type' => 'attachment',
440
+ 'post_status' => 'any',
441
+ 'post_mime_type' => $type,
442
+ 'author' => $bp->displayed_user->id,
443
+ 'meta_key' => 'bp-media-key',
444
+ 'meta_value' => $bp->displayed_user->id,
445
+ 'meta_compare' => '=',
446
+ 'paged' => $paged,
447
+ 'posts_per_page' => $bp_media_posts_per_page
448
+ );
449
+
450
+ $bp_media_query = new WP_Query($args);
451
+ }
452
+ }
453
+
454
  }
455
  ?>
app/main/profile/BPMediaTemplate.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * Contains methods for template functions
4
  *
@@ -10,220 +11,254 @@
10
  */
11
  class BPMediaTemplate {
12
 
13
- function upload_form_multiple() {
14
- global $bp_media_current_album;
15
- $post_wall = __( 'Wall Posts', BP_MEDIA_TXT_DOMAIN );
16
- if ( !isset ( $bp_media_current_album ) ) { ?>
17
- <div id="bp-media-album-prompt" title="Select Album">
18
- <span><?php _e( 'Select Album', BP_MEDIA_TXT_DOMAIN ); ?></span>
19
- <div class="bp-media-album-content">
20
- <select id="bp-media-selected-album"><?php
21
- if ( bp_is_current_component( 'groups' ) ) {
22
- $albums = new WP_Query( array(
23
- 'post_type' => 'bp_media_album',
24
- 'posts_per_page' => -1,
25
- 'meta_key' => 'bp-media-key',
26
- 'meta_value' => -bp_get_current_group_id(),
27
- 'meta_compare' => '='
28
- ) );
29
- } else {
30
- $albums = new WP_Query( array(
31
- 'post_type' => 'bp_media_album',
32
- 'posts_per_page' => -1,
33
- 'author' => get_current_user_id()
34
- ) );
35
- }
36
- if ( isset( $albums->posts ) && is_array( $albums->posts ) && count( $albums->posts ) > 0 ) {
37
- foreach ( $albums->posts as $album ) {
38
- if ( $album->post_title == $post_wall )
39
- echo '<option value="' . $album->ID . '" selected="selected">' .$album->post_title. '</option>';
40
- else
41
- echo '<option value="' . $album->ID . '">' .$album->post_title. '</option>';
42
- };
43
- }else {
44
- $album = new BPMediaAlbum();
45
- if ( bp_is_current_component( 'groups' ) ) {
46
- $current_group = new BP_Groups_Group( bp_get_current_group_id() );
47
- $album->add_album( $post_wall, $current_group->creator_id, bp_get_current_group_id() );
48
- } else {
49
- $album->add_album( $post_wall, bp_loggedin_user_id() );
50
- }
51
- echo '<option value="' . $album->get_id() . '" selected="selected">' .$album->get_title() ->post_title. '</option>';
52
- }
53
- echo '<option id="create-new" value="create_new" >' . __('+ Create New Album', BP_MEDIA_TXT_DOMAIN ). '</option>';
54
- ?>
55
- </select>
56
- </div>
57
- <div class="hide">
58
- <input type="text" id="bp_media_album_new" value="" />
59
- <input type="button" class="button" id="btn-create-new" value="<?php _e( 'Create', BP_MEDIA_TXT_DOMAIN ); ?>"/>
60
- <input type="button" class="button" id="btn-create-cancel" value="<?php _e( 'Cancel', BP_MEDIA_TXT_DOMAIN ); ?>"/>
61
- </div>
62
- </div><?php
63
- } else { ?>
64
- <input type="hidden" id="bp-media-selected-album" value="<?php echo $bp_media_current_album->get_id(); ?>"/>
65
- <?php } ?>
66
- <div id="bp-media-upload-ui" class="hide-if-no-js drag-drop">
67
- <div id="drag-drop-area">
68
- <div class="drag-drop-inside">
69
- <p class="drag-drop-info"><?php _e( 'Drop files here', BP_MEDIA_TXT_DOMAIN ); ?></p>
70
- <p><?php _e( ' or ', BP_MEDIA_TXT_DOMAIN ); ?></p>
71
- <p class="drag-drop-buttons"><input id="bp-media-upload-browse-button" type="button" value="<?php _e( 'Select Files', BP_MEDIA_TXT_DOMAIN ); ?>" class="button" /></p>
72
- </div>
73
- </div>
74
- <div id="bp-media-uploaded-files"></div>
75
- </div>
76
- <?php
77
- }
 
 
 
 
 
78
 
79
- function get_permalink( $id = 0 ) {
80
- if ( is_object( $id ) )
81
- $media = $id;
82
- else
83
- $media = &get_post( $id );
84
- if ( empty( $media->ID ) )
85
- return false;
86
- if ( ! $media->post_type == 'bp_media' )
87
- return false;
88
- switch ( get_post_meta( $media->ID, 'bp_media_type', true ) ) {
89
- case 'video' :
90
- return trailingslashit( bp_displayed_user_domain() . BP_MEDIA_VIDEOS_SLUG . '/' . BP_MEDIA_VIDEOS_ENTRY_SLUG . '/' . $media->ID );
91
- break;
92
- case 'audio' :
93
- return trailingslashit( bp_displayed_user_domain() . BP_MEDIA_AUDIO_SLUG . '/' . BP_MEDIA_AUDIO_ENTRY_SLUG . '/' . $media->ID );
94
- break;
95
- case 'image' :
96
- return trailingslashit( bp_displayed_user_domain() . BP_MEDIA_IMAGES_SLUG . '/' . BP_MEDIA_IMAGES_ENTRY_SLUG . '/' . $media->ID );
97
- break;
98
- default :
99
- return false;
100
- }
101
- }
 
 
 
 
 
102
 
103
- function the_permalink() {
104
- echo apply_filters( 'the_permalink', array( $this, 'get_permalink' ) );
105
- }
106
 
107
- function the_content( $id = 0 ) {
108
- if ( is_object( $id ) )
109
- $media = $id;
110
- else
111
- $media = &get_post( $id );
112
- if ( empty( $media->ID ) )
113
- return false;
114
- if ( $media->post_type != 'attachment' )
115
- return false;
116
- try {
117
- $media = new BPMediaHostWordpress( $media->ID );
118
- echo $media->get_media_gallery_content();
119
- } catch ( Exception $e ) {
120
- echo '';
121
- }
122
- }
 
 
 
 
 
123
 
124
- function the_album_content( $id = 0 ) {
125
- if ( is_object( $id ) )
126
- $album = $id;
127
- else
128
- $album = &get_post( $id );
129
- if ( empty( $album->ID ) )
130
- return false;
131
- if ( ! $album->post_type == 'bp_media_album' )
132
- return false;
133
- try {
134
- $album = new BPMediaAlbum( $album->ID );
135
- echo $album->get_album_gallery_content();
136
- } catch ( Exception $e ) {
137
- echo '';
138
- }
139
- }
 
 
 
 
 
140
 
141
- function show_more( $type = 'media' ) {
142
- $showmore = false;
143
- switch ( $type ) {
144
- case 'media':
145
- global $bp_media_query;
146
- //found_posts
147
- if ( isset( $bp_media_query->found_posts ) && $bp_media_query->found_posts > 10 )
148
- $showmore = true;
149
- break;
150
- case 'albums':
151
- global $bp_media_albums_query;
152
- if ( isset( $bp_media_albums_query->found_posts ) && $bp_media_albums_query->found_posts > 10 )
153
- $showmore = true;
154
- break;
155
- }
156
- if ( $showmore ) {
157
- echo '<div class="bp-media-actions"><a href="#" class="button" id="bp-media-show-more">'. __('Show More', BP_MEDIA_TXT_DOMAIN).'</a></div>';
158
- }
159
- }
 
 
 
 
 
 
160
 
161
- /**
162
- *
163
- */
164
- function redirect( $mediaconst ) {
165
- bp_core_redirect( trailingslashit( bp_displayed_user_domain() . constant( 'BP_MEDIA_' . $mediaconst . '_SLUG' ) ) );
166
- }
167
 
168
- /**
169
- *
170
- */
171
- function loader() {
172
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
173
- }
 
174
 
175
- function upload_form_multiple_activity() {
176
- global $bp, $bp_media_default_excerpts;
177
- if ( $bp->current_component != 'activity' )
178
- return;
179
- ?>
180
- <div id="bp-media-album-prompt" title="Select Album">
181
- <div class="bp-media-album-title">
182
- <span><?php _e( 'Select Album', BP_MEDIA_TXT_DOMAIN ); ?></span>
183
- <span id="bp-media-close"><?php _e( 'x', BP_MEDIA_TXT_DOMAIN ); ?></span>
184
- </div>
185
- <div class="bp-media-album-content">
186
- <select id="bp-media-selected-album"><?php
187
- $albums = new WP_Query( array(
188
- 'post_type' => 'bp_media_album',
189
- 'posts_per_page' => -1,
190
- 'author' => get_current_user_id()
191
- ) );
192
- if ( isset( $albums->posts ) && is_array( $albums->posts ) && count( $albums->posts ) > 0 ) {
193
- foreach ( $albums->posts as $album ) {
194
- if ( $album->post_title == $post_wall )
195
- echo '<option value="' . $album->ID . '" selected="selected">' . $album->post_title. '</option>';
196
- else
197
- echo '<option value="' . $album->ID . '">' . $album->post_title, BP_MEDIA_TXT_DOMAIN . '</option>';
198
- };
199
- }
200
- ?></select>
201
- </div>
202
- <div class="select-btn-div">
203
- <input id="selected-btn" type="button" class="btn" value="<?php _e( 'Select', BP_MEDIA_TXT_DOMAIN ); ?>" />
204
- <input id="create-btn" type="button" class="btn" value="<?php _e( 'Create Album', BP_MEDIA_TXT_DOMAIN ); ?>" />
205
- <div style="clear: both;"></div>
206
- </div>
207
- </div>
208
- <div id="bp-media-album-new" title="Create New Album">
209
- <div class="bp-media-album-title">
210
- <span><?php _e( 'Create Album', BP_MEDIA_TXT_DOMAIN ); ?></span>
211
- <span id="bp-media-create-album-close"><?php _e( 'x', BP_MEDIA_TXT_DOMAIN ); ?></span>
212
- </div>
213
- <div class="bp-media-album-content">
214
- <label for="bp_media_album_name"><?php _e( 'Album Name', BP_MEDIA_TXT_DOMAIN ); ?></label>
215
- <input id="bp_media_album_name" type="text" name="bp_media_album_name" />
216
- </div>
217
- <div class="select-btn-div">
218
- <input id="create-album" type="button" class="btn" value="<?php _e( 'Create', BP_MEDIA_TXT_DOMAIN ); ?>" />
219
- </div>
220
- </div>
221
- <div id="bp-media-upload-ui" class="hide-if-no-js drag-drop activity-component">
222
- <p class="drag-drop-buttons"><input id="bp-media-upload-browse-button" type="button" value="<?php _e( 'Add Media', BP_MEDIA_TXT_DOMAIN ); ?>" class="button" /></p>
223
- <div id="bp-media-uploaded-files"></div>
224
- </div>
225
- <?php
226
- }
 
 
 
 
 
 
 
 
 
 
227
 
228
  }
229
  ?>
1
  <?php
2
+
3
  /**
4
  * Contains methods for template functions
5
  *
11
  */
12
  class BPMediaTemplate {
13
 
14
+ /**
15
+ *
16
+ * @global type $bp_media_current_album
17
+ */
18
+ function upload_form_multiple() {
19
+ global $bp_media_current_album;
20
+ $post_wall = __('Wall Posts', BP_MEDIA_TXT_DOMAIN);
21
+ if (!isset($bp_media_current_album)) {
22
+ ?>
23
+ <div id="bp-media-album-prompt" title="Select Album">
24
+ <span><?php _e('Select Album', BP_MEDIA_TXT_DOMAIN); ?></span>
25
+ <div class="bp-media-album-content">
26
+ <select id="bp-media-selected-album"><?php
27
+ if (bp_is_current_component('groups')) {
28
+ $albums = new WP_Query(array(
29
+ 'post_type' => 'bp_media_album',
30
+ 'posts_per_page' => -1,
31
+ 'meta_key' => 'bp-media-key',
32
+ 'meta_value' => -bp_get_current_group_id(),
33
+ 'meta_compare' => '='
34
+ ));
35
+ } else {
36
+ $albums = new WP_Query(array(
37
+ 'post_type' => 'bp_media_album',
38
+ 'posts_per_page' => -1,
39
+ 'author' => get_current_user_id()
40
+ ));
41
+ }
42
+ if (isset($albums->posts) && is_array($albums->posts) && count($albums->posts) > 0) {
43
+ foreach ($albums->posts as $album) {
44
+ if ($album->post_title == $post_wall)
45
+ echo '<option value="' . $album->ID . '" selected="selected">' . $album->post_title . '</option>';
46
+ else
47
+ echo '<option value="' . $album->ID . '">' . $album->post_title . '</option>';
48
+ };
49
+ }else {
50
+ $album = new BPMediaAlbum();
51
+ if (bp_is_current_component('groups')) {
52
+ $current_group = new BP_Groups_Group(bp_get_current_group_id());
53
+ $album->add_album($post_wall, $current_group->creator_id, bp_get_current_group_id());
54
+ } else {
55
+ $album->add_album($post_wall, bp_loggedin_user_id());
56
+ }
57
+ echo '<option value="' . $album->get_id() . '" selected="selected">' . $album->get_title()->post_title . '</option>';
58
+ }
59
+ echo '<option id="create-new" value="create_new" >' . __('+ Create New Album', BP_MEDIA_TXT_DOMAIN) . '</option>';
60
+ ?>
61
+ </select>
62
+ </div>
63
+ <div class="hide">
64
+ <input type="text" id="bp_media_album_new" value="" />
65
+ <input type="button" class="button" id="btn-create-new" value="<?php _e('Create', BP_MEDIA_TXT_DOMAIN); ?>"/>
66
+ <input type="button" class="button" id="btn-create-cancel" value="<?php _e('Cancel', BP_MEDIA_TXT_DOMAIN); ?>"/>
67
+ </div>
68
+ </div><?php } else {
69
+ ?>
70
+ <input type="hidden" id="bp-media-selected-album" value="<?php echo $bp_media_current_album->get_id(); ?>"/>
71
+ <?php } ?>
72
+ <div id="bp-media-upload-ui" class="hide-if-no-js drag-drop">
73
+ <div id="drag-drop-area">
74
+ <div class="drag-drop-inside">
75
+ <p class="drag-drop-info"><?php _e('Drop files here', BP_MEDIA_TXT_DOMAIN); ?></p>
76
+ <p><?php _e(' or ', BP_MEDIA_TXT_DOMAIN); ?></p>
77
+ <p class="drag-drop-buttons"><input id="bp-media-upload-browse-button" type="button" value="<?php _e('Select Files', BP_MEDIA_TXT_DOMAIN); ?>" class="button" /></p>
78
+ </div>
79
+ </div>
80
+ <div id="bp-media-uploaded-files"></div>
81
+ </div>
82
+ <?php
83
+ }
84
 
85
+ /**
86
+ *
87
+ * @param type $id
88
+ * @return boolean
89
+ */
90
+ function get_permalink($id = 0) {
91
+ if (is_object($id))
92
+ $media = $id;
93
+ else
94
+ $media = &get_post($id);
95
+ if (empty($media->ID))
96
+ return false;
97
+ if (!$media->post_type == 'bp_media')
98
+ return false;
99
+ switch (get_post_meta($media->ID, 'bp_media_type', true)) {
100
+ case 'video' :
101
+ return trailingslashit(bp_displayed_user_domain() . BP_MEDIA_VIDEOS_SLUG . '/' . BP_MEDIA_VIDEOS_ENTRY_SLUG . '/' . $media->ID);
102
+ break;
103
+ case 'audio' :
104
+ return trailingslashit(bp_displayed_user_domain() . BP_MEDIA_AUDIO_SLUG . '/' . BP_MEDIA_AUDIO_ENTRY_SLUG . '/' . $media->ID);
105
+ break;
106
+ case 'image' :
107
+ return trailingslashit(bp_displayed_user_domain() . BP_MEDIA_IMAGES_SLUG . '/' . BP_MEDIA_IMAGES_ENTRY_SLUG . '/' . $media->ID);
108
+ break;
109
+ default :
110
+ return false;
111
+ }
112
+ }
113
 
114
+ function the_permalink() {
115
+ echo apply_filters('the_permalink', array($this, 'get_permalink'));
116
+ }
117
 
118
+ /**
119
+ *
120
+ * @param type $id
121
+ * @return boolean
122
+ */
123
+ function the_content($id = 0) {
124
+ if (is_object($id))
125
+ $media = $id;
126
+ else
127
+ $media = &get_post($id);
128
+ if (empty($media->ID))
129
+ return false;
130
+ if ($media->post_type != 'attachment')
131
+ return false;
132
+ try {
133
+ $media = new BPMediaHostWordpress($media->ID);
134
+ echo $media->get_media_gallery_content();
135
+ } catch (Exception $e) {
136
+ echo '';
137
+ }
138
+ }
139
 
140
+ /**
141
+ *
142
+ * @param type $id
143
+ * @return boolean
144
+ */
145
+ function the_album_content($id = 0) {
146
+ if (is_object($id))
147
+ $album = $id;
148
+ else
149
+ $album = &get_post($id);
150
+ if (empty($album->ID))
151
+ return false;
152
+ if (!$album->post_type == 'bp_media_album')
153
+ return false;
154
+ try {
155
+ $album = new BPMediaAlbum($album->ID);
156
+ echo $album->get_album_gallery_content();
157
+ } catch (Exception $e) {
158
+ echo '';
159
+ }
160
+ }
161
 
162
+ /**
163
+ *
164
+ * @global type $bp_media_query
165
+ * @global type $bp_media_albums_query
166
+ * @param type $type
167
+ */
168
+ function show_more($type = 'media') {
169
+ $showmore = false;
170
+ switch ($type) {
171
+ case 'media':
172
+ global $bp_media_query;
173
+ //found_posts
174
+ if (isset($bp_media_query->found_posts) && $bp_media_query->found_posts > 10)
175
+ $showmore = true;
176
+ break;
177
+ case 'albums':
178
+ global $bp_media_albums_query;
179
+ if (isset($bp_media_albums_query->found_posts) && $bp_media_albums_query->found_posts > 10)
180
+ $showmore = true;
181
+ break;
182
+ }
183
+ if ($showmore) {
184
+ echo '<div class="bp-media-actions"><a href="#" class="button" id="bp-media-show-more">' . __('Show More', BP_MEDIA_TXT_DOMAIN) . '</a></div>';
185
+ }
186
+ }
187
 
188
+ /**
189
+ *
190
+ */
 
 
 
191
 
192
+ /**
193
+ *
194
+ * @param type $mediaconst
195
+ */
196
+ function redirect($mediaconst) {
197
+ bp_core_redirect(trailingslashit(bp_displayed_user_domain() . constant('BP_MEDIA_' . $mediaconst . '_SLUG')));
198
+ }
199
 
200
+ function loader() {
201
+ bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
202
+ }
203
+
204
+ /**
205
+ *
206
+ * @global type $bp
207
+ * @global type $bp_media_default_excerpts
208
+ * @return type
209
+ */
210
+ function upload_form_multiple_activity() {
211
+ global $bp, $bp_media_default_excerpts;
212
+ if ($bp->current_component != 'activity')
213
+ return;
214
+ ?>
215
+ <div id="bp-media-album-prompt" title="Select Album">
216
+ <div class="bp-media-album-title">
217
+ <span><?php _e('Select Album', BP_MEDIA_TXT_DOMAIN); ?></span>
218
+ <span id="bp-media-close"><?php _e('x', BP_MEDIA_TXT_DOMAIN); ?></span>
219
+ </div>
220
+ <div class="bp-media-album-content">
221
+ <select id="bp-media-selected-album"><?php
222
+ $albums = new WP_Query(array(
223
+ 'post_type' => 'bp_media_album',
224
+ 'posts_per_page' => -1,
225
+ 'author' => get_current_user_id()
226
+ ));
227
+ if (isset($albums->posts) && is_array($albums->posts) && count($albums->posts) > 0) {
228
+ foreach ($albums->posts as $album) {
229
+ if ($album->post_title == $post_wall)
230
+ echo '<option value="' . $album->ID . '" selected="selected">' . $album->post_title . '</option>';
231
+ else
232
+ echo '<option value="' . $album->ID . '">' . $album->post_title, BP_MEDIA_TXT_DOMAIN . '</option>';
233
+ };
234
+ }
235
+ ?></select>
236
+ </div>
237
+ <div class="select-btn-div">
238
+ <input id="selected-btn" type="button" class="btn" value="<?php _e('Select', BP_MEDIA_TXT_DOMAIN); ?>" />
239
+ <input id="create-btn" type="button" class="btn" value="<?php _e('Create Album', BP_MEDIA_TXT_DOMAIN); ?>" />
240
+ <div style="clear: both;"></div>
241
+ </div>
242
+ </div>
243
+ <div id="bp-media-album-new" title="Create New Album">
244
+ <div class="bp-media-album-title">
245
+ <span><?php _e('Create Album', BP_MEDIA_TXT_DOMAIN); ?></span>
246
+ <span id="bp-media-create-album-close"><?php _e('x', BP_MEDIA_TXT_DOMAIN); ?></span>
247
+ </div>
248
+ <div class="bp-media-album-content">
249
+ <label for="bp_media_album_name"><?php _e('Album Name', BP_MEDIA_TXT_DOMAIN); ?></label>
250
+ <input id="bp_media_album_name" type="text" name="bp_media_album_name" />
251
+ </div>
252
+ <div class="select-btn-div">
253
+ <input id="create-album" type="button" class="btn" value="<?php _e('Create', BP_MEDIA_TXT_DOMAIN); ?>" />
254
+ </div>
255
+ </div>
256
+ <div id="bp-media-upload-ui" class="hide-if-no-js drag-drop activity-component">
257
+ <p class="drag-drop-buttons"><input id="bp-media-upload-browse-button" type="button" value="<?php _e('Add Media', BP_MEDIA_TXT_DOMAIN); ?>" class="button" /></p>
258
+ <div id="bp-media-uploaded-files"></div>
259
+ </div>
260
+ <?php
261
+ }
262
 
263
  }
264
  ?>
app/main/profile/BPMediaUploadScreen.php CHANGED
@@ -10,131 +10,141 @@
10
  */
11
  class BPMediaUploadScreen extends BPMediaScreen {
12
 
13
- public function __construct( $media_type, $slug ) {
14
- parent::__construct( $media_type, $slug );
15
- }
 
 
 
 
 
16
 
17
- function upload_screen() {
18
- if ( bp_is_my_profile() || BPMediaGroup::can_upload() ) {
19
- add_action( 'wp_enqueue_scripts', array( $this, 'upload_enqueue' ) );
20
- add_action( 'bp_template_title', array( $this, 'upload_screen_title' ) );
21
- add_action( 'bp_template_content', array( $this, 'upload_screen_content' ) );
22
- $this->template->loader();
23
- } else
24
- bp_core_redirect( trailingslashit( bp_displayed_user_domain() . constant( 'BP_MEDIA_SLUG' ) ) );
25
- }
26
 
27
- function upload_screen_title() {
28
- _e( 'Upload Media', BP_MEDIA_TXT_DOMAIN );
29
- }
30
 
31
- function upload_screen_content() {
32
- $this->hook_before();
33
 
34
- $this->template->upload_form_multiple();
35
 
36
- $this->hook_after();
37
- }
38
 
39
- function upload_enqueue() {
40
- $params = array(
41
- 'url' => BP_MEDIA_URL . 'app/main/includes/bp-media-upload-handler.php',
42
- 'runtimes' => 'gears,html5,flash,silverlight,browserplus',
43
- 'browse_button' => 'bp-media-upload-browse-button',
44
- 'container' => 'bp-media-upload-ui',
45
- 'drop_element' => 'drag-drop-area',
46
- 'filters' => apply_filters( 'bp_media_plupload_files_filter', array( array( 'title' => "Media Files", 'extensions' => "mp4,jpg,png,jpeg,gif,mp3" ) ) ),
47
- 'max_file_size' => min( array( ini_get( 'upload_max_filesize' ), ini_get( 'post_max_size' ) ) ),
48
- 'multipart' => true,
49
- 'urlstream_upload' => true,
50
- 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
51
- 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
52
- 'file_data_name' => 'bp_media_file', // key passed to $_FILE.
53
- 'multi_selection' => true,
54
- 'multipart_params' => apply_filters( 'bp_media_multipart_params_filter', array( 'action' => 'wp_handle_upload' ) )
55
- );
56
- wp_enqueue_script( 'bp-media-uploader', BP_MEDIA_URL . 'app/assets/js/bp-media-uploader.js', array( 'plupload', 'plupload-html5', 'plupload-flash', 'plupload-silverlight', 'plupload-html4', 'plupload-handlers' ) );
57
- wp_localize_script( 'bp-media-uploader', 'bp_media_uploader_params', $params );
58
- wp_enqueue_style( 'bp-media-default', BP_MEDIA_URL . 'app/assets/css/bp-media-style.css' );
59
- //wp_enqueue_style("wp-jquery-ui-dialog"); //Its not styling the Dialog box as it should so using different styling
60
- //wp_enqueue_style( 'jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
61
- }
62
 
63
- function upload_handler() {
64
- ignore_user_abort( true );
65
 
66
- require_once(BP_MEDIA_PATH . 'lib/bootstrap.php');
67
 
68
- // Check for rights
69
- if ( ! is_user_logged_in() )
70
- wp_die( __( "You are not allowed to be here", BP_MEDIA_TXT_DOMAIN ) );
71
- }
72
 
73
- function upload_media() {
74
- global $bp, $bp_media_options;
75
- $bp_media_options = get_site_option( 'bp_media_options',
76
- array(
77
- 'videos_enabled' => true,
78
- 'audio_enabled' => true,
79
- 'images_enabled' => true,
80
- )
81
- );
82
- if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'wp_handle_upload' ) {
83
- /** This section can help in the group activity handling */
84
- if ( isset( $_POST[ 'bp_media_group_id' ] ) && intval( $_POST[ 'bp_media_group_id' ] ) ) {
85
- remove_action( 'bp_media_after_add_media', 'BPMediaActions::activity_create_after_add_media', 10, 2 );
86
- add_action( 'bp_media_after_add_media', 'BPMediaGroupAction::bp_media_groups_activity_create_after_add_media', 10, 2 );
87
- add_filter( 'bp_media_force_hide_activity', 'BPMediaGroupAction::bp_media_groups_force_hide_activity' );
88
- }
89
- /* @var $bp_media_entry BPMediaHostWordpress */
90
- if ( isset( $_FILES ) && is_array( $_FILES ) && array_key_exists( 'bp_media_file', $_FILES ) && $_FILES[ 'bp_media_file' ][ 'name' ] != '' ) {
91
- if ( ! preg_match( '/audio|video|image/i', $_FILES[ 'bp_media_file' ][ 'type' ], $result ) || ! isset( $result[ 0 ] ) ) {
92
- $bp->{BP_MEDIA_SLUG}->messages[ 'error' ][ ] = __( 'File uploaded is not supported' );
93
- return;
94
- }
95
- $type = $result[ 0 ];
96
- switch ( $result[ 0 ] ) {
97
- case 'image' :
98
- if ( $bp_media_options[ 'images_enabled' ] == false ) {
99
- $bp->{BP_MEDIA_SLUG}->messages[ 'error' ][ ] = __( 'Image uploads are disabled', BP_MEDIA_TXT_DOMAIN );
100
- return;
101
- }
102
- break;
103
- case 'video' :
104
- if ( $bp_media_options[ 'videos_enabled' ] == false ) {
105
- $bp->{BP_MEDIA_SLUG}->messages[ 'error' ][ ] = __( 'Video uploads are disabled', BP_MEDIA_TXT_DOMAIN );
106
- return;
107
- }
108
- break;
109
- case 'audio' :
110
- if ( $bp_media_options[ 'audio_enabled' ] == false ) {
111
- $bp->{BP_MEDIA_SLUG}->messages[ 'error' ][ ] = __( 'Audio uploads are disabled', BP_MEDIA_TXT_DOMAIN );
112
- return;
113
- }
114
- break;
115
- default :
116
- $bp->{BP_MEDIA_SLUG}->messages[ 'error' ][ ] = __( 'File uploaded is not supported', BP_MEDIA_TXT_DOMAIN );
117
- return;
118
- }
119
- $class_name = apply_filters( 'bp_media_transcoder', 'BPMediaHostWordpress', $type );
120
- $bp_media_entry = new $class_name();
121
- try {
122
- $title = isset( $_POST[ 'bp_media_title' ] ) ? ($_POST[ 'bp_media_title' ] != "") ? $_POST[ 'bp_media_title' ] : pathinfo( $_FILES[ 'bp_media_file' ][ 'name' ], PATHINFO_FILENAME ) : pathinfo( $_FILES[ 'bp_media_file' ][ 'name' ], PATHINFO_FILENAME );
123
- $album_id = isset( $_POST[ 'bp_media_album_id' ] ) ? intval( $_POST[ 'bp_media_album_id' ] ) : 0;
124
- $is_multiple = isset( $_POST[ 'is_multiple_upload' ] ) ? ($_POST[ 'is_multiple_upload' ] == 'true' ? true : false) : false;
125
- $description = isset( $_POST[ 'bp_media_description' ] ) ? $_POST[ 'bp_media_description' ] : '';
126
- $group_id = isset( $_POST[ 'bp_media_group_id' ] ) ? intval( $_POST[ 'bp_media_group_id' ] ) : 0;
127
- $entry = $bp_media_entry->add_media( $title, $description, $album_id, $group_id, $is_multiple );
128
- if ( ! isset( $bp->{BP_MEDIA_SLUG}->messages[ 'updated' ][ 0 ] ) )
129
- $bp->{BP_MEDIA_SLUG}->messages[ 'updated' ][ 0 ] = __( 'Upload Successful', BP_MEDIA_TXT_DOMAIN );
130
- } catch ( Exception $e ) {
131
- $bp->{BP_MEDIA_SLUG}->messages[ 'error' ][ ] = $e->getMessage();
132
- }
133
- } else {
134
- $bp->{BP_MEDIA_SLUG}->messages[ 'error' ][ ] = __( 'You did not specified a file to upload', BP_MEDIA_TXT_DOMAIN );
135
- }
136
- }
137
- }
 
 
 
 
 
138
 
139
  }
140
 
10
  */
11
  class BPMediaUploadScreen extends BPMediaScreen {
12
 
13
+ /**
14
+ *
15
+ * @param type $media_type
16
+ * @param type $slug
17
+ */
18
+ public function __construct($media_type, $slug) {
19
+ parent::__construct($media_type, $slug);
20
+ }
21
 
22
+ function upload_screen() {
23
+ if (bp_is_my_profile() || BPMediaGroup::can_upload()) {
24
+ add_action('wp_enqueue_scripts', array($this, 'upload_enqueue'));
25
+ add_action('bp_template_title', array($this, 'upload_screen_title'));
26
+ add_action('bp_template_content', array($this, 'upload_screen_content'));
27
+ $this->template->loader();
28
+ } else
29
+ bp_core_redirect(trailingslashit(bp_displayed_user_domain() . constant('BP_MEDIA_SLUG')));
30
+ }
31
 
32
+ function upload_screen_title() {
33
+ _e('Upload Media', BP_MEDIA_TXT_DOMAIN);
34
+ }
35
 
36
+ function upload_screen_content() {
37
+ $this->hook_before();
38
 
39
+ $this->template->upload_form_multiple();
40
 
41
+ $this->hook_after();
42
+ }
43
 
44
+ function upload_enqueue() {
45
+ $params = array(
46
+ 'url' => BP_MEDIA_URL . 'app/main/includes/bp-media-upload-handler.php',
47
+ 'runtimes' => 'gears,html5,flash,silverlight,browserplus',
48
+ 'browse_button' => 'bp-media-upload-browse-button',
49
+ 'container' => 'bp-media-upload-ui',
50
+ 'drop_element' => 'drag-drop-area',
51
+ 'filters' => apply_filters('bp_media_plupload_files_filter', array(array('title' => "Media Files", 'extensions' => "mp4,jpg,png,jpeg,gif,mp3"))),
52
+ 'max_file_size' => min(array(ini_get('upload_max_filesize'), ini_get('post_max_size'))),
53
+ 'multipart' => true,
54
+ 'urlstream_upload' => true,
55
+ 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
56
+ 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
57
+ 'file_data_name' => 'bp_media_file', // key passed to $_FILE.
58
+ 'multi_selection' => true,
59
+ 'multipart_params' => apply_filters('bp_media_multipart_params_filter', array('action' => 'wp_handle_upload'))
60
+ );
61
+ wp_enqueue_script('bp-media-uploader', BP_MEDIA_URL . 'app/assets/js/bp-media-uploader.js', array('plupload', 'plupload-html5', 'plupload-flash', 'plupload-silverlight', 'plupload-html4', 'plupload-handlers'));
62
+ wp_localize_script('bp-media-uploader', 'bp_media_uploader_params', $params);
63
+ wp_enqueue_style('bp-media-default', BP_MEDIA_URL . 'app/assets/css/bp-media-style.css');
64
+ //wp_enqueue_style("wp-jquery-ui-dialog"); //Its not styling the Dialog box as it should so using different styling
65
+ //wp_enqueue_style( 'jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
66
+ }
67
 
68
+ function upload_handler() {
69
+ ignore_user_abort(true);
70
 
71
+ require_once(BP_MEDIA_PATH . 'lib/bootstrap.php');
72
 
73
+ // Check for rights
74
+ if (!is_user_logged_in())
75
+ wp_die(__("You are not allowed to be here", BP_MEDIA_TXT_DOMAIN));
76
+ }
77
 
78
+ /**
79
+ *
80
+ * @global type $bp
81
+ * @global type $bp_media_options
82
+ * @return type
83
+ */
84
+ function upload_media() {
85
+ global $bp, $bp_media_options;
86
+ $bp_media_options = get_site_option('bp_media_options', array(
87
+ 'videos_enabled' => true,
88
+ 'audio_enabled' => true,
89
+ 'images_enabled' => true,
90
+ )
91
+ );
92
+ if (isset($_POST['action']) && $_POST['action'] == 'wp_handle_upload') {
93
+ /** This section can help in the group activity handling */
94
+ if (isset($_POST['bp_media_group_id']) && intval($_POST['bp_media_group_id'])) {
95
+ remove_action('bp_media_after_add_media', 'BPMediaActions::activity_create_after_add_media', 10, 2);
96
+ add_action('bp_media_after_add_media', 'BPMediaGroupAction::bp_media_groups_activity_create_after_add_media', 10, 2);
97
+ add_filter('bp_media_force_hide_activity', 'BPMediaGroupAction::bp_media_groups_force_hide_activity');
98
+ }
99
+ /* @var $bp_media_entry BPMediaHostWordpress */
100
+ if (isset($_FILES) && is_array($_FILES) && array_key_exists('bp_media_file', $_FILES) && $_FILES['bp_media_file']['name'] != '') {
101
+ if (!preg_match('/audio|video|image/i', $_FILES['bp_media_file']['type'], $result) || !isset($result[0])) {
102
+ $bp->{BP_MEDIA_SLUG}->messages['error'][] = __('File uploaded is not supported');
103
+ return;
104
+ }
105
+ $type = $result[0];
106
+ switch ($result[0]) {
107
+ case 'image' :
108
+ if ($bp_media_options['images_enabled'] == false) {
109
+ $bp->{BP_MEDIA_SLUG}->messages['error'][] = __('Image uploads are disabled', BP_MEDIA_TXT_DOMAIN);
110
+ return;
111
+ }
112
+ break;
113
+ case 'video' :
114
+ if ($bp_media_options['videos_enabled'] == false) {
115
+ $bp->{BP_MEDIA_SLUG}->messages['error'][] = __('Video uploads are disabled', BP_MEDIA_TXT_DOMAIN);
116
+ return;
117
+ }
118
+ break;
119
+ case 'audio' :
120
+ if ($bp_media_options['audio_enabled'] == false) {
121
+ $bp->{BP_MEDIA_SLUG}->messages['error'][] = __('Audio uploads are disabled', BP_MEDIA_TXT_DOMAIN);
122
+ return;
123
+ }
124
+ break;
125
+ default :
126
+ $bp->{BP_MEDIA_SLUG}->messages['error'][] = __('File uploaded is not supported', BP_MEDIA_TXT_DOMAIN);
127
+ return;
128
+ }
129
+ $class_name = apply_filters('bp_media_transcoder', 'BPMediaHostWordpress', $type);
130
+ $bp_media_entry = new $class_name();
131
+ try {
132
+ $title = isset($_POST['bp_media_title']) ? ($_POST['bp_media_title'] != "") ? $_POST['bp_media_title'] : pathinfo($_FILES['bp_media_file']['name'], PATHINFO_FILENAME) : pathinfo($_FILES['bp_media_file']['name'], PATHINFO_FILENAME);
133
+ $album_id = isset($_POST['bp_media_album_id']) ? intval($_POST['bp_media_album_id']) : 0;
134
+ $is_multiple = isset($_POST['is_multiple_upload']) ? ($_POST['is_multiple_upload'] == 'true' ? true : false) : false;
135
+ $description = isset($_POST['bp_media_description']) ? $_POST['bp_media_description'] : '';
136
+ $group_id = isset($_POST['bp_media_group_id']) ? intval($_POST['bp_media_group_id']) : 0;
137
+ $entry = $bp_media_entry->add_media($title, $description, $album_id, $group_id, $is_multiple);
138
+ if (!isset($bp->{BP_MEDIA_SLUG}->messages['updated'][0]))
139
+ $bp->{BP_MEDIA_SLUG}->messages['updated'][0] = __('Upload Successful', BP_MEDIA_TXT_DOMAIN);
140
+ } catch (Exception $e) {
141
+ $bp->{BP_MEDIA_SLUG}->messages['error'][] = $e->getMessage();
142
+ }
143
+ } else {
144
+ $bp->{BP_MEDIA_SLUG}->messages['error'][] = __('You did not specified a file to upload', BP_MEDIA_TXT_DOMAIN);
145
+ }
146
+ }
147
+ }
148
 
149
  }
150
 
app/main/widgets/BPMediaPopularMedia.php CHANGED
@@ -30,6 +30,11 @@ class BPMediaPopularMedia extends WP_Widget {
30
  }
31
  }
32
 
 
 
 
 
 
33
  function widget($args, $instance) {
34
  extract($args);
35
 
@@ -63,14 +68,14 @@ class BPMediaPopularMedia extends WP_Widget {
63
  ?>
64
 
65
  <ul class="widget-item-listing"><?php
66
- while ($bp_media_widget_query->have_posts()) {
67
- $bp_media_widget_query->the_post();
68
 
69
- $entry = new BPMediaHostWordpress(get_the_ID());
70
  ?>
71
 
72
- <?php echo $entry->get_media_gallery_content(); ?><?php }
73
- ?>
74
 
75
  </ul><!-- .widget-item-listing --><?php
76
  }
@@ -78,7 +83,7 @@ class BPMediaPopularMedia extends WP_Widget {
78
  _e('No popular media found', BP_MEDIA_TXT_DOMAIN);
79
 
80
  wp_reset_query();
81
- ?>
82
 
83
  </div><!-- #popular-media-tabs-comments -->
84
  </div>
@@ -86,6 +91,12 @@ class BPMediaPopularMedia extends WP_Widget {
86
  echo $after_widget;
87
  }
88
 
 
 
 
 
 
 
89
  function update($new_instance, $old_instance) {
90
  $instance = $old_instance;
91
  $instance['title'] = strip_tags($new_instance['title']);
@@ -93,6 +104,10 @@ class BPMediaPopularMedia extends WP_Widget {
93
  return $instance;
94
  }
95
 
 
 
 
 
96
  function form($instance) {
97
  $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
98
  $number = isset($instance['number']) ? absint($instance['number']) : 10;
30
  }
31
  }
32
 
33
+ /**
34
+ *
35
+ * @param type $args
36
+ * @param type $instance
37
+ */
38
  function widget($args, $instance) {
39
  extract($args);
40
 
68
  ?>
69
 
70
  <ul class="widget-item-listing"><?php
71
+ while ($bp_media_widget_query->have_posts()) {
72
+ $bp_media_widget_query->the_post();
73
 
74
+ $entry = new BPMediaHostWordpress(get_the_ID());
75
  ?>
76
 
77
+ <?php echo $entry->get_media_gallery_content(); ?><?php }
78
+ ?>
79
 
80
  </ul><!-- .widget-item-listing --><?php
81
  }
83
  _e('No popular media found', BP_MEDIA_TXT_DOMAIN);
84
 
85
  wp_reset_query();
86
+ ?>
87
 
88
  </div><!-- #popular-media-tabs-comments -->
89
  </div>
91
  echo $after_widget;
92
  }
93
 
94
+ /**
95
+ *
96
+ * @param type $new_instance
97
+ * @param type $old_instance
98
+ * @return type
99
+ */
100
  function update($new_instance, $old_instance) {
101
  $instance = $old_instance;
102
  $instance['title'] = strip_tags($new_instance['title']);
104
  return $instance;
105
  }
106
 
107
+ /**
108
+ *
109
+ * @param type $instance
110
+ */
111
  function form($instance) {
112
  $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
113
  $number = isset($instance['number']) ? absint($instance['number']) : 10;
app/main/widgets/BPMediaRecentMedia.php CHANGED
@@ -30,6 +30,11 @@ class BPMediaRecentMedia extends WP_Widget {
30
  }
31
  }
32
 
 
 
 
 
 
33
  function widget($args, $instance) {
34
  extract($args);
35
 
@@ -65,14 +70,14 @@ class BPMediaRecentMedia extends WP_Widget {
65
  ?>
66
 
67
  <ul class="widget-item-listing"><?php
68
- while ($bp_media_widget_query->have_posts()) {
69
- $bp_media_widget_query->the_post();
70
 
71
- $entry = new BPMediaHostWordpress(get_the_ID());
72
  ?>
73
 
74
- <?php echo $entry->get_media_gallery_content(); ?><?php }
75
- ?>
76
 
77
  </ul><!-- .widget-item-listing --><?php
78
  }
@@ -153,7 +158,7 @@ class BPMediaRecentMedia extends WP_Widget {
153
  _e('No recent audio found', BP_MEDIA_TXT_DOMAIN);
154
 
155
  wp_reset_query();
156
- ?>
157
 
158
  </div><!-- #recent-media-tabs-music -->
159
 
@@ -178,7 +183,7 @@ class BPMediaRecentMedia extends WP_Widget {
178
  $bp_media_widget_query->the_post();
179
 
180
  $entry = new BPMediaHostWordpress(get_the_ID());
181
- ?>
182
 
183
  <?php echo $entry->get_media_gallery_content(); ?><?php }
184
  ?>
@@ -189,7 +194,7 @@ class BPMediaRecentMedia extends WP_Widget {
189
  _e('No recent video found', BP_MEDIA_TXT_DOMAIN);
190
 
191
  wp_reset_query();
192
- ?>
193
 
194
  </div><!-- #media-tabs-videos -->
195
 
@@ -198,6 +203,12 @@ class BPMediaRecentMedia extends WP_Widget {
198
  echo $after_widget;
199
  }
200
 
 
 
 
 
 
 
201
  function update($new_instance, $old_instance) {
202
  $instance = $old_instance;
203
  $instance['title'] = strip_tags($new_instance['title']);
@@ -205,6 +216,10 @@ class BPMediaRecentMedia extends WP_Widget {
205
  return $instance;
206
  }
207
 
 
 
 
 
208
  function form($instance) {
209
  $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
210
  $number = isset($instance['number']) ? absint($instance['number']) : 10;
30
  }
31
  }
32
 
33
+ /**
34
+ *
35
+ * @param type $args
36
+ * @param type $instance
37
+ */
38
  function widget($args, $instance) {
39
  extract($args);
40
 
70
  ?>
71
 
72
  <ul class="widget-item-listing"><?php
73
+ while ($bp_media_widget_query->have_posts()) {
74
+ $bp_media_widget_query->the_post();
75
 
76
+ $entry = new BPMediaHostWordpress(get_the_ID());
77
  ?>
78
 
79
+ <?php echo $entry->get_media_gallery_content(); ?><?php }
80
+ ?>
81
 
82
  </ul><!-- .widget-item-listing --><?php
83
  }
158
  _e('No recent audio found', BP_MEDIA_TXT_DOMAIN);
159
 
160
  wp_reset_query();
161
+ ?>
162
 
163
  </div><!-- #recent-media-tabs-music -->
164
 
183
  $bp_media_widget_query->the_post();
184
 
185
  $entry = new BPMediaHostWordpress(get_the_ID());
186
+ ?>
187
 
188
  <?php echo $entry->get_media_gallery_content(); ?><?php }
189
  ?>
194
  _e('No recent video found', BP_MEDIA_TXT_DOMAIN);
195
 
196
  wp_reset_query();
197
+ ?>
198
 
199
  </div><!-- #media-tabs-videos -->
200
 
203
  echo $after_widget;
204
  }
205
 
206
+ /**
207
+ *
208
+ * @param type $new_instance
209
+ * @param type $old_instance
210
+ * @return type
211
+ */
212
  function update($new_instance, $old_instance) {
213
  $instance = $old_instance;
214
  $instance['title'] = strip_tags($new_instance['title']);
216
  return $instance;
217
  }
218
 
219
+ /**
220
+ *
221
+ * @param type $instance
222
+ */
223
  function form($instance) {
224
  $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
225
  $number = isset($instance['number']) ? absint($instance['number']) : 10;
app/main/widgets/BPMediaWidget.php CHANGED
@@ -12,6 +12,11 @@ class BPMediaWidget extends WP_Widget {
12
  parent::__construct('buddypress-media-wid', __('BuddyPress Media Widget', BP_MEDIA_TXT_DOMAIN), $widget_ops);
13
  }
14
 
 
 
 
 
 
15
  function widget($args, $instance) {
16
  extract($args);
17
  $title = apply_filters('widget_title', empty($instance['title']) ? __('BuddyPress Media', BP_MEDIA_TXT_DOMAIN) : $instance['title'], $instance, $this->id_base);
@@ -59,10 +64,10 @@ class BPMediaWidget extends WP_Widget {
59
  array_push($allowMimeType, "video");
60
  ?>
61
  <li><a href="#<?php echo $wdType; ?>-media-tabs-videos-<?php echo $widgetid; ?>"><?php _e('Videos', BP_MEDIA_TXT_DOMAIN); ?></a></li>
62
- <?php }
63
- ?>
64
  </ul>
65
- <?php if ($allowAll) { ?>
66
  <div id="<?php echo $wdType; ?>-media-tabs-all-<?php echo $widgetid; ?>" class="bp-media-tab-panel">
67
  <?php
68
  // All Media //'post_mime_type' => $allowMimeType,
@@ -81,14 +86,14 @@ class BPMediaWidget extends WP_Widget {
81
  ?>
82
 
83
  <ul class="widget-item-listing"><?php
84
- while ($bp_media_widget_query->have_posts()) {
85
- $bp_media_widget_query->the_post();
86
 
87
- $entry = new BPMediaHostWordpress(get_the_ID());
88
  ?>
89
 
90
- <?php echo $entry->get_media_gallery_content(); ?><?php }
91
- ?>
92
 
93
  </ul><?php
94
  }
@@ -96,7 +101,7 @@ class BPMediaWidget extends WP_Widget {
96
  _e('No ' . $wdType . ' media found', BP_MEDIA_TXT_DOMAIN);
97
 
98
  wp_reset_query();
99
- ?>
100
 
101
  </div>
102
  <?php
@@ -121,14 +126,14 @@ class BPMediaWidget extends WP_Widget {
121
  ?>
122
 
123
  <ul class="widget-item-listing"><?php
124
- while ($bp_media_widget_query->have_posts()) {
125
- $bp_media_widget_query->the_post();
126
 
127
- $entry = new BPMediaHostWordpress(get_the_ID());
128
  ?>
129
 
130
- <?php echo $entry->get_media_gallery_content(); ?><?php }
131
- ?>
132
 
133
  </ul><!-- .widget-item-listing --><?php
134
  }
@@ -136,7 +141,7 @@ class BPMediaWidget extends WP_Widget {
136
  _e('No ' . $wdType . ' photo found', BP_MEDIA_TXT_DOMAIN);
137
 
138
  wp_reset_query();
139
- ?>
140
 
141
  </div>
142
  <?php
@@ -171,11 +176,11 @@ class BPMediaWidget extends WP_Widget {
171
  ?>
172
 
173
  </ul><?php
174
- }
175
- else
176
- _e('No ' . $wdType . ' audio found', BP_MEDIA_TXT_DOMAIN);
177
 
178
- wp_reset_query();
179
  ?>
180
 
181
  </div>
@@ -201,14 +206,14 @@ class BPMediaWidget extends WP_Widget {
201
  ?>
202
 
203
  <ul class="widget-item-listing"><?php
204
- while ($bp_media_widget_query->have_posts()) {
205
- $bp_media_widget_query->the_post();
206
 
207
- $entry = new BPMediaHostWordpress(get_the_ID());
208
  ?>
209
 
210
- <?php echo $entry->get_media_gallery_content(); ?><?php }
211
- ?>
212
 
213
  </ul><?php
214
  }
@@ -216,16 +221,22 @@ class BPMediaWidget extends WP_Widget {
216
  _e('No ' . $wdType . ' video found', BP_MEDIA_TXT_DOMAIN);
217
 
218
  wp_reset_query();
219
- ?>
220
 
221
  </div>
222
- <?php } ?>
223
  </div>
224
  <?php
225
  }
226
  echo $after_widget;
227
  }
228
 
 
 
 
 
 
 
229
  function update($new_instance, $old_instance) {
230
  $instance = $old_instance;
231
  $instance['wdType'] = strip_tags($new_instance['wdType']);
@@ -239,6 +250,10 @@ class BPMediaWidget extends WP_Widget {
239
  return $instance;
240
  }
241
 
 
 
 
 
242
  function form($instance) {
243
  $wdType = isset($instance['wdType']) ? esc_attr($instance['wdType']) : '';
244
  $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
12
  parent::__construct('buddypress-media-wid', __('BuddyPress Media Widget', BP_MEDIA_TXT_DOMAIN), $widget_ops);
13
  }
14
 
15
+ /**
16
+ *
17
+ * @param type $args
18
+ * @param type $instance
19
+ */
20
  function widget($args, $instance) {
21
  extract($args);
22
  $title = apply_filters('widget_title', empty($instance['title']) ? __('BuddyPress Media', BP_MEDIA_TXT_DOMAIN) : $instance['title'], $instance, $this->id_base);
64
  array_push($allowMimeType, "video");
65
  ?>
66
  <li><a href="#<?php echo $wdType; ?>-media-tabs-videos-<?php echo $widgetid; ?>"><?php _e('Videos', BP_MEDIA_TXT_DOMAIN); ?></a></li>
67
+ <?php }
68
+ ?>
69
  </ul>
70
+ <?php if ($allowAll) { ?>
71
  <div id="<?php echo $wdType; ?>-media-tabs-all-<?php echo $widgetid; ?>" class="bp-media-tab-panel">
72
  <?php
73
  // All Media //'post_mime_type' => $allowMimeType,
86
  ?>
87
 
88
  <ul class="widget-item-listing"><?php
89
+ while ($bp_media_widget_query->have_posts()) {
90
+ $bp_media_widget_query->the_post();
91
 
92
+ $entry = new BPMediaHostWordpress(get_the_ID());
93
  ?>
94
 
95
+ <?php echo $entry->get_media_gallery_content(); ?><?php }
96
+ ?>
97
 
98
  </ul><?php
99
  }
101
  _e('No ' . $wdType . ' media found', BP_MEDIA_TXT_DOMAIN);
102
 
103
  wp_reset_query();
104
+ ?>
105
 
106
  </div>
107
  <?php
126
  ?>
127
 
128
  <ul class="widget-item-listing"><?php
129
+ while ($bp_media_widget_query->have_posts()) {
130
+ $bp_media_widget_query->the_post();
131
 
132
+ $entry = new BPMediaHostWordpress(get_the_ID());
133
  ?>
134
 
135
+ <?php echo $entry->get_media_gallery_content(); ?><?php }
136
+ ?>
137
 
138
  </ul><!-- .widget-item-listing --><?php
139
  }
141
  _e('No ' . $wdType . ' photo found', BP_MEDIA_TXT_DOMAIN);
142
 
143
  wp_reset_query();
144
+ ?>
145
 
146
  </div>
147
  <?php
176
  ?>
177
 
178
  </ul><?php
179
+ }
180
+ else
181
+ _e('No ' . $wdType . ' audio found', BP_MEDIA_TXT_DOMAIN);
182
 
183
+ wp_reset_query();
184
  ?>
185
 
186
  </div>
206
  ?>
207
 
208
  <ul class="widget-item-listing"><?php
209
+ while ($bp_media_widget_query->have_posts()) {
210
+ $bp_media_widget_query->the_post();
211
 
212
+ $entry = new BPMediaHostWordpress(get_the_ID());
213
  ?>
214
 
215
+ <?php echo $entry->get_media_gallery_content(); ?><?php }
216
+ ?>
217
 
218
  </ul><?php
219
  }
221
  _e('No ' . $wdType . ' video found', BP_MEDIA_TXT_DOMAIN);
222
 
223
  wp_reset_query();
224
+ ?>
225
 
226
  </div>
227
+ <?php } ?>
228
  </div>
229
  <?php
230
  }
231
  echo $after_widget;
232
  }
233
 
234
+ /**
235
+ *
236
+ * @param type $new_instance
237
+ * @param type $old_instance
238
+ * @return type
239
+ */
240
  function update($new_instance, $old_instance) {
241
  $instance = $old_instance;
242
  $instance['wdType'] = strip_tags($new_instance['wdType']);
250
  return $instance;
251
  }
252
 
253
+ /**
254
+ *
255
+ * @param type $instance
256
+ */
257
  function form($instance) {
258
  $wdType = isset($instance['wdType']) ? esc_attr($instance['wdType']) : '';
259
  $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: BuddyPress Media
4
  Plugin URI: http://rtcamp.com/buddypress-media/
5
  Description: This plugin adds missing media rich features like photos, videos and audios uploading to BuddyPress which are essential if you are building social network, seriously!
6
- Version: 2.5.1
7
  Author: rtCamp
8
  Text Domain: buddypress-media
9
  Author URI: http://rtcamp.com
3
  Plugin Name: BuddyPress Media
4
  Plugin URI: http://rtcamp.com/buddypress-media/
5
  Description: This plugin adds missing media rich features like photos, videos and audios uploading to BuddyPress which are essential if you are building social network, seriously!
6
+ Version: 2.5.2
7
  Author: rtCamp
8
  Text Domain: buddypress-media
9
  Author URI: http://rtcamp.com
readme.txt CHANGED
@@ -6,7 +6,7 @@ License: GPLv2 or later
6
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
7
  Requires at least: 3.5
8
  Tested up to: 3.5
9
- Stable tag: 2.5.1
10
 
11
  Adds Photos, Music, Videos & Albums to your BuddyPress. Supports mobile devices (iPhone/iPad, etc) and automatic audio/video conversion.
12
 
@@ -87,6 +87,9 @@ Please visit [BuddyPress Media's Features page](http://rtcamp.com/buddypress-med
87
  == Changelog ==
88
 
89
  Please visit [BuddyPress Media's Roadmap page](http://rtcamp.com/buddypress-media/roadmap/ "Visit BuddyPress Media's Features page") to get some details about future releases.
 
 
 
90
  = 2.5.1 =
91
  * Fixed bug where when a user visits another member's media tab when groups are inactive, they'd get an error.
92
  * Improved long album title and count display.
@@ -211,5 +214,5 @@ Please visit [BuddyPress Media's Roadmap page](http://rtcamp.com/buddypress-medi
211
  * HTML5 Video Tag Support (with fallback)
212
 
213
  == Upgrade Notice ==
214
- =2.5.1=
215
- Album title and count display fixed. Fixed bug with inactive groups.
6
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
7
  Requires at least: 3.5
8
  Tested up to: 3.5
9
+ Stable tag: 2.5.2
10
 
11
  Adds Photos, Music, Videos & Albums to your BuddyPress. Supports mobile devices (iPhone/iPad, etc) and automatic audio/video conversion.
12
 
87
  == Changelog ==
88
 
89
  Please visit [BuddyPress Media's Roadmap page](http://rtcamp.com/buddypress-media/roadmap/ "Visit BuddyPress Media's Features page") to get some details about future releases.
90
+ = 2.5.2 =
91
+ * Fixes warning on admin side.
92
+
93
  = 2.5.1 =
94
  * Fixed bug where when a user visits another member's media tab when groups are inactive, they'd get an error.
95
  * Improved long album title and count display.
214
  * HTML5 Video Tag Support (with fallback)
215
 
216
  == Upgrade Notice ==
217
+ =2.5.2=
218
+ Fixes warning shown on the admin side for some PHP versions.