[ Index ]

MailPress 7.2

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-content/add-ons/ -> MailPress_embed.php (source)

   1  <?php
   2  if ( class_exists( 'MailPress' ) && !class_exists( 'MailPress_embed' ) )
   3  {
   4  /*
   5  Plugin Name: MailPress_embed 
   6  Plugin URI: http://blog.mailpress.org/tutorials/add-ons/embed/
   7  Description: Mail oEmbed ( equivalent of WordPress video embedding but for mails )
   8  Version: 7.2
   9  */
  10  
  11  class MailPress_embed
  12  {
  13      public static $type = null;
  14      public static $mp_oembed = null;
  15  
  16      const meta_key = '_mp_oembed_';
  17      const usecache = true;
  18      const html_filter = 'mp_embed_oembed_html';
  19      const unknown = '{{unknown}}';
  20  
  21  	function __construct()
  22      {
  23          add_action( 'save_post',                 array( __CLASS__, 'save_post' ) );
  24  
  25          add_action( 'MailPress_build_mail_content_start',    array( __CLASS__, 'build_mail_content_start' ) );
  26          add_action( 'MailPress_build_mail_content_end',        array( __CLASS__, 'build_mail_content_end' ) );
  27      }
  28  
  29  	public static function save_post( $post_ID )
  30      {
  31          $post_metas = get_post_custom_keys( $post_ID );
  32          if ( empty( $post_metas ) )    return;
  33  
  34          foreach( $post_metas as $post_meta_key )
  35              if ( self::meta_key == substr( $post_meta_key, 0, strlen( self::meta_key ) ) )
  36                  delete_post_meta( $post_ID, $post_meta_key );
  37      }
  38  
  39  	public static function build_mail_content_start( $type )
  40      {
  41          //global $wp_embed, $mp_embed;
  42          //remove_filter( 'the_content', array( $wp_embed, 'autoembed' ), 8 );
  43  
  44          global $mp_embed;
  45  
  46          self::$type = $type;
  47  
  48          if ( 'html' == $type )
  49          {
  50              $mp_embed = new MP_Embed();
  51          }
  52      }
  53  
  54  	public static function build_mail_content_end( $type )
  55      {
  56          //global $wp_embed, $mp_embed;
  57          //add_filter( 'the_content', array( $wp_embed, 'autoembed' ), 8 );
  58  
  59          global $mp_embed;
  60  
  61          if ( 'html' == $type )
  62          {
  63              remove_filter( 'MailPress_the_content', array( $mp_embed, 'autoembed' ), 8 );
  64              $mp_embed = self::$type = null;
  65          }
  66      }
  67  
  68  	public static function embed_register_handler( $id, $regex, $callback, $priority = 10 )
  69      {
  70          global $mp_embed;
  71          $mp_embed->register_handler( $id, $regex, $callback, $priority );
  72      }
  73  
  74  	public static function embed_unregister_handler( $id, $priority = 10 )
  75      {
  76          global $mp_embed;
  77          $mp_embed->unregister_handler( $id, $priority );
  78      }
  79  
  80  	public static function require_class_oembed()
  81      {
  82          $old_file = ABSPATH . WPINC . '/class-oembed.php';
  83          $new_file = ABSPATH . WPINC . '/class-wp-oembed.php';
  84  
  85          $file = ( is_file( $new_file ) ) ? $new_file : $old_file;
  86  
  87          require_once ( $file );
  88      }
  89  
  90  	public static function _oembed_get( $url, $args = '' )
  91      {
  92          self::require_class_oembed();
  93          $oembed = self::_oembed_get_object();
  94          return $oembed->get_html( $url, $args );
  95      }
  96  
  97  	public static function _oembed_get_object() 
  98      {
  99          if ( is_null( self::$mp_oembed ) ) self::$mp_oembed = new MP_oEmbed();
 100          self::$mp_oembed->providers = apply_filters( 'mp_oembed_providers', self::$mp_oembed->providers );
 101          return self::$mp_oembed;
 102      }
 103  
 104  	public static function _oembed_add_provider( $format, $provider, $regex = false )
 105      {
 106          self::require_class_oembed();
 107          $oembed = self::_oembed_get_object();
 108          $oembed->providers[$format] = array( $provider, $regex );
 109      }
 110  
 111  	public static function _embed_get( $data )
 112      {
 113          $out  = '';
 114  
 115          $out .= '<a target="_blank" href="' . esc_url( $data->url ) . '"';
 116          $out .= ' title="' . esc_attr( $data->title ) . '"';
 117          $out .= '>';
 118  
 119          $out .= '<img';
 120          $out .= ' class="mp_'. $data->provider_name . '"';
 121          $out .= ' width="' . $data->thumbnail_width . 'px"';
 122          $out .= ' height="' . $data->thumbnail_height . 'px"';
 123          $out .= ' src="' . $data->thumbnail_url . '"';
 124          $out .= ' title="' . esc_attr( $data->title ) . '" alt="' . esc_attr( $data->title ) . '"';
 125          $out .= ' />';
 126  
 127          $out .= '</a>';
 128  
 129          return $out;
 130      }
 131  }
 132  new MailPress_embed();
 133  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1