PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/core/media/old/modules/bpm_oembed_generic/loader-disabled.php

http://buddypress-media.googlecode.com/
PHP | 437 lines | 146 code | 97 blank | 194 comment | 13 complexity | c4313faa715b47c1b43df8f88410e598 MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0, GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * MEDIA MODULE - GENERIC oEMBED CONTENT
  4. * Handles media items from sites that embed non-media content (like flash games) or use unusual,
  5. * possibly broken embed code. Use this module only as a last resort.
  6. *
  7. * @version 0.1.9
  8. * @since 0.1.9
  9. * @package BP-Media Modules
  10. * @subpackage oEmbed Generic
  11. * @link http://code.google.com/p/buddypress-media/
  12. *
  13. * ========================================================================================================
  14. */
  15. class BPMM_oEmbedGeneric implements iBPM_mediaModule_Generic_oEmbed, iBPM_mediaModule {
  16. /**
  17. * // TODO: Make these configurable.
  18. * Returns an array of oembed types handled by this module
  19. *
  20. * @version 0.1.9
  21. * @since 0.1.9
  22. * @return array<string> handled oembed types
  23. */
  24. public static function get_oembed_types(){
  25. return array('rich', 'photo', 'video');
  26. }
  27. /**
  28. * Returns the human-readable name of the media module. This is displayed in the admin interface.
  29. *
  30. * @version 0.1.9
  31. * @since 0.1.9
  32. * @return string | Name of media module
  33. */
  34. public static function get_admin_label() {
  35. return __('oEmbed - Generic',"bp-media");
  36. }
  37. /**
  38. * Returns the url-safe name of the media module, commonly called a "slug". Must be unique from all
  39. * other media modules.
  40. *
  41. * @version 0.1.9
  42. * @since 0.1.9
  43. * @return string | Name of media module
  44. */
  45. public static function get_slug() {
  46. return 'oembed-generic';
  47. }
  48. /**
  49. * Returns the HTTP path to the media module's icon. Icons MUST be 64px*64px .PNG files.
  50. *
  51. * //TODO: We have experienced some problems with PNG files saved on Linux machines not
  52. * opening properly in widnows-based browsers (FireFox). This should be investigated.
  53. *
  54. * @version 0.1.9
  55. * @since 0.1.9
  56. * @return string | path to icon file
  57. */
  58. public static function get_icon(){
  59. return BPM_URL_BASE . "/core/media_modules/bpm_oembed_generic/icon.png";
  60. }
  61. /**
  62. * Returns a short description (approx 30 words) of what the media module does.
  63. *
  64. * @version 0.1.9
  65. * @since 0.1.9
  66. * @return string | description
  67. */
  68. public static function get_description(){
  69. return _e("This module displays generic embedded content from other websites, using mediaelement or wpaudioplayer
  70. classes. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a justo non lorem porttitor dignissim.","bp-media");
  71. }
  72. /**
  73. * Returns a string containing the media module's version number. Does not have to be an
  74. * integer number, "2.1.8.5a" and "1.5.1 (Vegas Build)" are acceptable.
  75. *
  76. * @version 0.1.9
  77. * @since 0.1.9
  78. * @return string | version number
  79. */
  80. public static function get_version(){
  81. return "<a href='http://code.google.com/p/buddypress-media/downloads/list'>Ver 0.1.9</a>";
  82. }
  83. /**
  84. * Returns a composited HTML string, including the name of the content module developer and
  85. * a link to their personal or company website.
  86. *
  87. * @version 0.1.9
  88. * @since 0.1.9
  89. * @return string | version number
  90. */
  91. public static function get_author(){
  92. return "<a href='http://code.google.com/p/buddypress-media/'>The BP-Media Team</a>";
  93. }
  94. /**
  95. * Returns a composited HTML string containing a link to the media module's support page, or dedicated
  96. * project site. Example: <a href='http://code.google.com/p/buddypress-media/'>The BP-Media Team</a>
  97. *
  98. * @version 0.1.9
  99. * @since 0.1.9
  100. * @return string | version number
  101. */
  102. public static function get_site(){
  103. return "<a href='http://buddypress.org/community/groups/bp-album/forum/'>Module Website</a>";
  104. }
  105. /**
  106. * Installs the media module database tables. Upgrades DB tables when necessary.
  107. *
  108. * @version 0.1.9
  109. * @since 0.1.9
  110. */
  111. public static function install() {
  112. global $bp, $wpdb;
  113. // $charset_collate = '';
  114. //
  115. // if ( ! empty($wpdb->charset) )
  116. // $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
  117. //
  118. // if ( ! empty($wpdb->collate) )
  119. // $charset_collate .= " COLLATE $wpdb->collate";
  120. //
  121. //
  122. // $sql[] = "CREATE TABLE {$wpdb->base_prefix}bpm_modules_picture(
  123. // id smallint(6) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  124. // name varchar(255) NOT NULL,
  125. // x_pixels mediumint(8) NOT NULL,
  126. // y_pixels mediumint(8) NOT NULL,
  127. // format varchar(8) NOT NULL default 'JPG',
  128. // quality tinyint(3) NOT NULL default '100',
  129. // crop tinyint(1) NOT NULL default '1',
  130. // scale tinyint(1) NOT NULL default '0',
  131. // watermark varchar(16) NOT NULL,
  132. // cache varchar(16) NOT NULL,
  133. // KEY name (name)
  134. // ) {$charset_collate};";
  135. //
  136. // require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
  137. //
  138. // dbDelta($sql);
  139. $bp->bpa->options = get_option('bp_album_options');
  140. $settings = array();
  141. $settings['cover_operatingMode'] = 'default';
  142. $settings['cover_customDefaultImagePath'] = 'C:/test/whatever/etc';
  143. $name = get_class($this);
  144. $bp->bpa->options['media_module_settings'][$name] = $settings;
  145. update_option('bp_album_options', $bp->bpa->options);
  146. }
  147. /**
  148. * Drops all database tables for the content module, and removes all the module's stored settings.
  149. * DOES NOT DELETE UPLOADED CONTENT
  150. *
  151. * @version 0.1.9
  152. * @since 0.1.9
  153. */
  154. public static function uninstall() {
  155. global $bp, $wpdb;
  156. }
  157. /**
  158. * Adds scripts used by the media module to the page header
  159. *
  160. * @version 0.1.9
  161. * @since 0.1.9
  162. */
  163. public static function enqueueScripts(){
  164. }
  165. /**
  166. * Adds CSS styles used by the media module to the page header
  167. *
  168. * @version 0.1.9
  169. * @since 0.1.9
  170. */
  171. public static function enqueueStyles(){
  172. }
  173. /**
  174. * Renders the configuration page for this media module.
  175. *
  176. * @version 0.1.9
  177. * @since 0.1.9
  178. * @return string | composited HTML block
  179. */
  180. public static function config_page() {
  181. global $bp;
  182. ?>
  183. <input type="hidden" name="page_options"
  184. value="
  185. core_slug_base,
  186. core_slug_home,
  187. albums_slug_home
  188. " />
  189. <div class="bpa_module_sectionTitle"><?php _e('Media Player Selection',"bp-media") ?></div>
  190. <table class="form-table bpa_module_sectionOptions">
  191. <tr>
  192. <th scope="row"><?php _e( 'Use "Media Element"', "bp-media" ) ?></th>
  193. <td>
  194. <input type="radio" name="media_views_itemCountEnable" type="text" <?php if ($bp->bpa->options['media_views_itemCountEnable'] == true ) : ?>
  195. checked="checked"<?php endif; ?> value="1" /> <?php _e( 'Yes', "bp-media" ) ?> &nbsp;
  196. <input type="radio" name="media_views_itemCountEnable" type="text" <?php if ($bp->bpa->options['media_views_itemCountEnable'] == false) : ?>
  197. checked="checked"<?php endif; ?> value="0" /> <?php _e( 'No', "bp-media" ) ?>
  198. </td>
  199. </tr>
  200. <tr>
  201. <th scope="row"><?php _e( 'Use "WP Audio Player"', "bp-media" ) ?></th>
  202. <td>
  203. <input type="radio" name="media_views_itemCountEnable" type="text" <?php if ($bp->bpa->options['media_views_itemCountEnable'] == true ) : ?>
  204. checked="checked"<?php endif; ?> value="1" /> <?php _e( 'Yes', "bp-media" ) ?> &nbsp;
  205. <input type="radio" name="media_views_itemCountEnable" type="text" <?php if ($bp->bpa->options['media_views_itemCountEnable'] == false) : ?>
  206. checked="checked"<?php endif; ?> value="0" /> <?php _e( 'No', "bp-media" ) ?>
  207. </td>
  208. </tr>
  209. </table>
  210. <div class="bpa_module_sectionTitle"><?php _e('Base Image',"bp-media") ?></div>
  211. <table class="form-table bpa_module_sectionOptions">
  212. <tr>
  213. <th scope="row"><?php _e( 'Cover image source', "bp-media" ) ?></th>
  214. <td>
  215. <label>
  216. <input name="media_rating_itemRatingShowTo" type="radio" value="admin" <?php checked('admin', $bp->bpa->options['media_rating_itemRatingShowTo']); ?> />
  217. <?php _e('Use the system default cover image', "bp-media") ;?>
  218. </label><br />
  219. <label>
  220. <input name="media_rating_itemRatingShowTo" type="radio" value="friends" <?php checked('friends', $bp->bpa->options['media_rating_itemRatingShowTo']); ?> />
  221. <?php _e("Upload a custom default image", "bp-media") ;?>
  222. </label><br />
  223. <label>
  224. <input name="media_rating_itemRatingShowTo" type="radio" value="members" <?php checked('members', $bp->bpa->options['media_rating_itemRatingShowTo']); ?> />
  225. <?php _e('Let users upload their own cover images for each audio file', "bp-media") ;?>
  226. </label><br />
  227. </td>
  228. </tr>
  229. <tr valign="top">
  230. <th scope="row"><label for="target_uri"><?php _e( 'Custom image file URL', "bp-media" ) ?></label></th>
  231. <td>
  232. <input name="bp_album_base_url" type="text" id="bp_album_base_url" value="<?php echo attribute_escape( $bp_album_base_url ); ?>" size="60" />
  233. </td>
  234. </tr>
  235. </table>
  236. <?php
  237. }
  238. public static function init() {
  239. }
  240. /**
  241. * handle html generation and caching
  242. *
  243. * get_html of abstract embeddable works well with standard oembeds,
  244. * ovverride for customization and advanced embeds
  245. *
  246. * @see BPM_mediaModule_base::generate_html()
  247. * @see BPM_mediaModule_base::embed_data()
  248. *
  249. * @param stdClass $media_item media obj
  250. * @param array $args size args
  251. * @return string html to display
  252. */
  253. public static function get_html( $media_item, $args) {
  254. $embed_data = self::embed_data( $media_item, $args );
  255. $html = self::get_cached_html( $embed_data );
  256. if(!$html){
  257. $html = self::generate_html( $embed_data );
  258. self::set_cached_html( $embed_data, $html );
  259. }
  260. return $html;
  261. }
  262. /**
  263. * embed data needed to identify cached html and generate html
  264. *
  265. * for cache efficiency make this array contains all the data needed to generate
  266. * html and nothing more
  267. *
  268. * default data are url,width,height, override if less or more is needed.
  269. *
  270. * @param stdClass $media_item media obj
  271. * @param array $args size args
  272. * @return string embed data
  273. */
  274. protected static function embed_data( $media_item, $args ) {
  275. if( $media_item->width || $media_item->height ) {
  276. list(,, $width, $height ) = BP_Album_Cache::calculate_dimensions( $media_item->width, $media_item->height, $args['resize_w'], $args['resize_h'], $args['resize_crop'], $args['resize_upscale'] );
  277. } else {
  278. $width = $args['resize_w'];
  279. $height = $args['resize_h'];
  280. }
  281. return array(
  282. 'url' => $media_item->location,
  283. 'width' => $width,
  284. 'height' => $height
  285. );
  286. }
  287. /**
  288. * generate html
  289. *
  290. * generate_html of abstract embeddable is intended for standard oembeds,
  291. * ovverride for customization and advanced embeds
  292. *
  293. * @param stdClass $media_item media obj
  294. * @param array $embed_data data from {@link BPM_mediaModule_base::embed_data()}
  295. * @return string html to cache/display
  296. */
  297. protected static function generate_html( $embed_data ) {
  298. return BPM_Multimedia::oembed_object()->get_html( $embed_data['url'], array('width'=>$embed_data['width'], 'height'=>$embed_data['height']) );
  299. }
  300. /**
  301. * get html from cache
  302. *
  303. * @param array $embed_data data used to generate html and used to identify html in cache
  304. * @return string cached html or empty string
  305. */
  306. protected static function get_cached_html( $embed_data ){
  307. $cache = get_site_transient( self::cache_key($embed_data) );
  308. return empty($cache['html']) ? '' : $cache['html'];
  309. }
  310. /**
  311. * set html in cache
  312. *
  313. * @param array $embed_data data used to generate html and used to identify html in cache
  314. * @param string $html html to cache
  315. * @param null|int $expiration expiration time in sec, default 5 days
  316. */
  317. protected static function set_cached_html( $embed_data, $html, $expiration = null ){
  318. if( null === $expiration ){
  319. $expiration = /* 5 days */ 432000;
  320. }
  321. $cache = $embed_data + array( 'html' => $html );
  322. set_site_transient( self::cache_key($embed_data), $cache, $expiration );
  323. }
  324. /**
  325. * generate cache key from embed data
  326. *
  327. * cache key can be at most 40 chars long (column width is 64 but there are
  328. * prefixes like '_site_transient_' and '_site_transient_timeout_')
  329. *
  330. * @param array<mixed> $embed_data
  331. * @return string cache key
  332. */
  333. protected static function cache_key( $embed_data ){
  334. return substr("bpm_embed_".md5(serialize($embed_data)), 0, 40);
  335. }
  336. }
  337. //register the media module in BP Media
  338. BPM_Multimedia::register_media_module('BPMM_oEmbedGeneric');
  339. //BPMM_oEmbedGeneric::install();
  340. ?>