[ Index ]

MailPress 7.2

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

title

Body

[close]

/mp-includes/class/ -> MP_Post.class.php (source)

   1  <?php
   2  class MP_Post
   3  {
   4      const meta_key = MailPress_post::meta_key;
   5      const meta_key_order =  MailPress_post::meta_key_order;
   6  
   7  	public static function exists( $mp_mail_id, $post_id ) 
   8      {
   9          return MP_Mail_meta::get( $mp_mail_id, self::meta_key, $post_id );
  10      }
  11  
  12  	public static function insert( $mp_mail_id, $post_id ) 
  13      {
  14          if ( self::exists( $mp_mail_id, $post_id ) ) return;
  15  
  16          $meta_value   = MP_Mail_meta::get( $mp_mail_id, self::meta_key_order );
  17                  
  18                  if ( !$meta_value )
  19                  {
  20                      $x[$post_id] = $post_id;
  21                  }
  22                  else
  23                  {
  24                      if ( is_array($meta_value) )
  25                      {
  26                          $x = $meta_value;
  27                          $x[$post_id] = $post_id;
  28                      }
  29                       else 
  30                       {
  31                           $x[$meta_value] = $meta_value;
  32                                                   $x[$post_id] = $post_id;
  33                       }
  34                  }
  35          if ( !MP_Mail_meta::add( $mp_mail_id, self::meta_key_order, $x, true ) )
  36               MP_Mail_meta::update( $mp_mail_id, self::meta_key_order, $x );
  37  
  38          return MP_Mail_meta::add( $mp_mail_id, self::meta_key, $post_id );
  39      }
  40  
  41  	public static function delete( $mp_mail_id, $post_id ) 
  42      {
  43          $meta_value = MP_Mail_meta::get( $mp_mail_id, self::meta_key_order );
  44  
  45          if ( $meta_value )
  46          {
  47              if ( is_array(  $meta_value  ) ) 
  48              {
  49                  unset( $meta_value[$post_id] );
  50              }
  51              if ( empty( $meta_value ) )     MP_Mail_meta::delete( $mp_mail_id, self::meta_key_order );
  52              else                         MP_Mail_meta::update( $mp_mail_id, self::meta_key_order, $meta_value );
  53          }
  54          return MP_Mail_meta::delete( $mp_mail_id, self::meta_key, $post_id );
  55      }
  56  
  57  	public static function delete_post( $post_id ) 
  58      {
  59          global $wpdb;
  60          $mails = $wpdb->get_results( $wpdb->prepare( "SELECT mp_mail_id FROM $wpdb->mp_mailmeta WHERE meta_key = %s AND meta_value = %s", self::meta_key, $post_id ) );
  61          if ( !$mails ) return true;
  62          foreach( $mails as $mail ) self::delete( $mail->mp_mail_id, $post_id );
  63          return true;
  64      }
  65  
  66  // retourne les drafts d'un post
  67  	public static function get_term_objects( $post_id )
  68      {
  69          global $wpdb;
  70          $mails = $wpdb->get_results( $wpdb->prepare( "SELECT mp_mail_id FROM $wpdb->mp_mailmeta WHERE meta_key = %s AND meta_value = %s ORDER BY mp_mail_id;", self::meta_key, $post_id ) );
  71          if ( !$mails ) return array();
  72          foreach( $mails as $mail ) $_objects[$mail->mp_mail_id] = $mail->mp_mail_id;
  73          return $_objects;
  74      }
  75  
  76  	public static function get_object_terms( $mp_mail_id )
  77      {
  78          $_terms = MP_Mail_meta::get( $mp_mail_id, self::meta_key_order );
  79          return $_terms;
  80      }
  81  
  82  	public static function object_have_relations( $mp_mail_id )
  83      {
  84          return MP_Mail_meta::get( $mp_mail_id, self::meta_key );
  85      }
  86  }


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