/core/media/old/modules/bpm_oembed_generic/loader-disabled.php
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
- <?php
- /**
- * MEDIA MODULE - GENERIC oEMBED CONTENT
- * Handles media items from sites that embed non-media content (like flash games) or use unusual,
- * possibly broken embed code. Use this module only as a last resort.
- *
- * @version 0.1.9
- * @since 0.1.9
- * @package BP-Media Modules
- * @subpackage oEmbed Generic
- * @link http://code.google.com/p/buddypress-media/
- *
- * ========================================================================================================
- */
- class BPMM_oEmbedGeneric implements iBPM_mediaModule_Generic_oEmbed, iBPM_mediaModule {
- /**
- * // TODO: Make these configurable.
- * Returns an array of oembed types handled by this module
- *
- * @version 0.1.9
- * @since 0.1.9
- * @return array<string> handled oembed types
- */
- public static function get_oembed_types(){
- return array('rich', 'photo', 'video');
- }
- /**
- * Returns the human-readable name of the media module. This is displayed in the admin interface.
- *
- * @version 0.1.9
- * @since 0.1.9
- * @return string | Name of media module
- */
- public static function get_admin_label() {
- return __('oEmbed - Generic',"bp-media");
- }
- /**
- * Returns the url-safe name of the media module, commonly called a "slug". Must be unique from all
- * other media modules.
- *
- * @version 0.1.9
- * @since 0.1.9
- * @return string | Name of media module
- */
- public static function get_slug() {
- return 'oembed-generic';
- }
- /**
- * Returns the HTTP path to the media module's icon. Icons MUST be 64px*64px .PNG files.
- *
- * //TODO: We have experienced some problems with PNG files saved on Linux machines not
- * opening properly in widnows-based browsers (FireFox). This should be investigated.
- *
- * @version 0.1.9
- * @since 0.1.9
- * @return string | path to icon file
- */
- public static function get_icon(){
- return BPM_URL_BASE . "/core/media_modules/bpm_oembed_generic/icon.png";
- }
- /**
- * Returns a short description (approx 30 words) of what the media module does.
- *
- * @version 0.1.9
- * @since 0.1.9
- * @return string | description
- */
- public static function get_description(){
- return _e("This module displays generic embedded content from other websites, using mediaelement or wpaudioplayer
- classes. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a justo non lorem porttitor dignissim.","bp-media");
- }
- /**
- * Returns a string containing the media module's version number. Does not have to be an
- * integer number, "2.1.8.5a" and "1.5.1 (Vegas Build)" are acceptable.
- *
- * @version 0.1.9
- * @since 0.1.9
- * @return string | version number
- */
- public static function get_version(){
- return "<a href='http://code.google.com/p/buddypress-media/downloads/list'>Ver 0.1.9</a>";
- }
- /**
- * Returns a composited HTML string, including the name of the content module developer and
- * a link to their personal or company website.
- *
- * @version 0.1.9
- * @since 0.1.9
- * @return string | version number
- */
- public static function get_author(){
- return "<a href='http://code.google.com/p/buddypress-media/'>The BP-Media Team</a>";
- }
- /**
- * Returns a composited HTML string containing a link to the media module's support page, or dedicated
- * project site. Example: <a href='http://code.google.com/p/buddypress-media/'>The BP-Media Team</a>
- *
- * @version 0.1.9
- * @since 0.1.9
- * @return string | version number
- */
- public static function get_site(){
- return "<a href='http://buddypress.org/community/groups/bp-album/forum/'>Module Website</a>";
- }
- /**
- * Installs the media module database tables. Upgrades DB tables when necessary.
- *
- * @version 0.1.9
- * @since 0.1.9
- */
- public static function install() {
- global $bp, $wpdb;
- // $charset_collate = '';
- //
- // if ( ! empty($wpdb->charset) )
- // $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
- //
- // if ( ! empty($wpdb->collate) )
- // $charset_collate .= " COLLATE $wpdb->collate";
- //
- //
- // $sql[] = "CREATE TABLE {$wpdb->base_prefix}bpm_modules_picture(
- // id smallint(6) NOT NULL AUTO_INCREMENT PRIMARY KEY,
- // name varchar(255) NOT NULL,
- // x_pixels mediumint(8) NOT NULL,
- // y_pixels mediumint(8) NOT NULL,
- // format varchar(8) NOT NULL default 'JPG',
- // quality tinyint(3) NOT NULL default '100',
- // crop tinyint(1) NOT NULL default '1',
- // scale tinyint(1) NOT NULL default '0',
- // watermark varchar(16) NOT NULL,
- // cache varchar(16) NOT NULL,
- // KEY name (name)
- // ) {$charset_collate};";
- //
- // require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
- //
- // dbDelta($sql);
- $bp->bpa->options = get_option('bp_album_options');
- $settings = array();
- $settings['cover_operatingMode'] = 'default';
- $settings['cover_customDefaultImagePath'] = 'C:/test/whatever/etc';
- $name = get_class($this);
- $bp->bpa->options['media_module_settings'][$name] = $settings;
- update_option('bp_album_options', $bp->bpa->options);
- }
- /**
- * Drops all database tables for the content module, and removes all the module's stored settings.
- * DOES NOT DELETE UPLOADED CONTENT
- *
- * @version 0.1.9
- * @since 0.1.9
- */
- public static function uninstall() {
- global $bp, $wpdb;
- }
- /**
- * Adds scripts used by the media module to the page header
- *
- * @version 0.1.9
- * @since 0.1.9
- */
- public static function enqueueScripts(){
- }
- /**
- * Adds CSS styles used by the media module to the page header
- *
- * @version 0.1.9
- * @since 0.1.9
- */
- public static function enqueueStyles(){
- }
-
- /**
- * Renders the configuration page for this media module.
- *
- * @version 0.1.9
- * @since 0.1.9
- * @return string | composited HTML block
- */
- public static function config_page() {
- global $bp;
- ?>
- <input type="hidden" name="page_options"
- value="
- core_slug_base,
- core_slug_home,
- albums_slug_home
- " />
- <div class="bpa_module_sectionTitle"><?php _e('Media Player Selection',"bp-media") ?></div>
- <table class="form-table bpa_module_sectionOptions">
- <tr>
- <th scope="row"><?php _e( 'Use "Media Element"', "bp-media" ) ?></th>
- <td>
- <input type="radio" name="media_views_itemCountEnable" type="text" <?php if ($bp->bpa->options['media_views_itemCountEnable'] == true ) : ?>
- checked="checked"<?php endif; ?> value="1" /> <?php _e( 'Yes', "bp-media" ) ?>
- <input type="radio" name="media_views_itemCountEnable" type="text" <?php if ($bp->bpa->options['media_views_itemCountEnable'] == false) : ?>
- checked="checked"<?php endif; ?> value="0" /> <?php _e( 'No', "bp-media" ) ?>
- </td>
- </tr>
- <tr>
- <th scope="row"><?php _e( 'Use "WP Audio Player"', "bp-media" ) ?></th>
- <td>
- <input type="radio" name="media_views_itemCountEnable" type="text" <?php if ($bp->bpa->options['media_views_itemCountEnable'] == true ) : ?>
- checked="checked"<?php endif; ?> value="1" /> <?php _e( 'Yes', "bp-media" ) ?>
- <input type="radio" name="media_views_itemCountEnable" type="text" <?php if ($bp->bpa->options['media_views_itemCountEnable'] == false) : ?>
- checked="checked"<?php endif; ?> value="0" /> <?php _e( 'No', "bp-media" ) ?>
- </td>
- </tr>
- </table>
- <div class="bpa_module_sectionTitle"><?php _e('Base Image',"bp-media") ?></div>
- <table class="form-table bpa_module_sectionOptions">
- <tr>
- <th scope="row"><?php _e( 'Cover image source', "bp-media" ) ?></th>
- <td>
- <label>
- <input name="media_rating_itemRatingShowTo" type="radio" value="admin" <?php checked('admin', $bp->bpa->options['media_rating_itemRatingShowTo']); ?> />
- <?php _e('Use the system default cover image', "bp-media") ;?>
- </label><br />
- <label>
- <input name="media_rating_itemRatingShowTo" type="radio" value="friends" <?php checked('friends', $bp->bpa->options['media_rating_itemRatingShowTo']); ?> />
- <?php _e("Upload a custom default image", "bp-media") ;?>
- </label><br />
- <label>
- <input name="media_rating_itemRatingShowTo" type="radio" value="members" <?php checked('members', $bp->bpa->options['media_rating_itemRatingShowTo']); ?> />
- <?php _e('Let users upload their own cover images for each audio file', "bp-media") ;?>
- </label><br />
- </td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="target_uri"><?php _e( 'Custom image file URL', "bp-media" ) ?></label></th>
- <td>
- <input name="bp_album_base_url" type="text" id="bp_album_base_url" value="<?php echo attribute_escape( $bp_album_base_url ); ?>" size="60" />
- </td>
- </tr>
- </table>
- <?php
- }
- public static function init() {
- }
- /**
- * handle html generation and caching
- *
- * get_html of abstract embeddable works well with standard oembeds,
- * ovverride for customization and advanced embeds
- *
- * @see BPM_mediaModule_base::generate_html()
- * @see BPM_mediaModule_base::embed_data()
- *
- * @param stdClass $media_item media obj
- * @param array $args size args
- * @return string html to display
- */
- public static function get_html( $media_item, $args) {
- $embed_data = self::embed_data( $media_item, $args );
- $html = self::get_cached_html( $embed_data );
- if(!$html){
- $html = self::generate_html( $embed_data );
- self::set_cached_html( $embed_data, $html );
- }
- return $html;
- }
- /**
- * embed data needed to identify cached html and generate html
- *
- * for cache efficiency make this array contains all the data needed to generate
- * html and nothing more
- *
- * default data are url,width,height, override if less or more is needed.
- *
- * @param stdClass $media_item media obj
- * @param array $args size args
- * @return string embed data
- */
- protected static function embed_data( $media_item, $args ) {
- if( $media_item->width || $media_item->height ) {
- 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'] );
- } else {
- $width = $args['resize_w'];
- $height = $args['resize_h'];
- }
- return array(
- 'url' => $media_item->location,
- 'width' => $width,
- 'height' => $height
- );
- }
- /**
- * generate html
- *
- * generate_html of abstract embeddable is intended for standard oembeds,
- * ovverride for customization and advanced embeds
- *
- * @param stdClass $media_item media obj
- * @param array $embed_data data from {@link BPM_mediaModule_base::embed_data()}
- * @return string html to cache/display
- */
- protected static function generate_html( $embed_data ) {
- return BPM_Multimedia::oembed_object()->get_html( $embed_data['url'], array('width'=>$embed_data['width'], 'height'=>$embed_data['height']) );
- }
- /**
- * get html from cache
- *
- * @param array $embed_data data used to generate html and used to identify html in cache
- * @return string cached html or empty string
- */
- protected static function get_cached_html( $embed_data ){
- $cache = get_site_transient( self::cache_key($embed_data) );
- return empty($cache['html']) ? '' : $cache['html'];
- }
- /**
- * set html in cache
- *
- * @param array $embed_data data used to generate html and used to identify html in cache
- * @param string $html html to cache
- * @param null|int $expiration expiration time in sec, default 5 days
- */
- protected static function set_cached_html( $embed_data, $html, $expiration = null ){
- if( null === $expiration ){
- $expiration = /* 5 days */ 432000;
- }
- $cache = $embed_data + array( 'html' => $html );
- set_site_transient( self::cache_key($embed_data), $cache, $expiration );
- }
- /**
- * generate cache key from embed data
- *
- * cache key can be at most 40 chars long (column width is 64 but there are
- * prefixes like '_site_transient_' and '_site_transient_timeout_')
- *
- * @param array<mixed> $embed_data
- * @return string cache key
- */
- protected static function cache_key( $embed_data ){
- return substr("bpm_embed_".md5(serialize($embed_data)), 0, 40);
- }
- }
- //register the media module in BP Media
- BPM_Multimedia::register_media_module('BPMM_oEmbedGeneric');
- //BPMM_oEmbedGeneric::install();
- ?>