<commit_before><?php

/**
 * @package SPL_Mailgun
 * @version 0.1
 */

/*
Plugin Name: SPL Mailgun
Plugin URI: http://www.spokanelibrary.org/
Description: Hooks a custom post type to a mailgun campaign.
Author: <NAME>
Author URI: http://seangirard.com
Version: 0.1
*/

require('config.php');
require('settings.php');
require('functions.php');

$config = new SPL_Mailgun_Newsletter_Config();
$newsletter = new SPL_Mailgun_Newsletter($config);

if ( is_admin() ) {
  $admin = new SPL_Mailgun_Newsletter_Settings();
}

class SPL_Mailgun_Newsletter {

  var $config;

  function __construct($config=null) {
    if ( !is_null($config) 
          && isset($config->plugin['mailgun-public-key']) 
          && isset($config->plugin['mailgun-private-key']) ) {
      $this->config = $config;
      $this->initNewsletter();
    }
  }

  static function activateNewsletter() {
    // false does not attempt to overwrite .htaccess
    flush_rewrite_rules(false);
  }

  function initNewsletter() {
    //$this->registerPostTemplates();
    
    add_action( 'init', array( $this, 'registerPostType' ) );
    add_action( 'init', array($this, 'initCmbMetaBoxes'), 9999 );

    add_action( 'save_post', array( $this, 'registerSaveHandler' ) );

    add_filter( 'template_include', array($this, 'registerPostTemplates'));
    add_filter( 'cmb_meta_boxes', array($this, 'getNewsletterCmbMetaBoxes') );
    

  } // initNewsletter()

  function registerPostTemplates($template) {
    
    $post_types = array( 'newsletter' );
    /*
    if ( is_post_type_archive( $post_types ) 
      && ! file_exists( get_stylesheet_directory() . '/archive-newsletter.php' ) ) {
      $template = plugin_dir_path(__FILE__) . 'templates/archive-newsletter.php';
    }
    */
    //if ( 'newsletter' == get_post_type( get_the_ID() ) ) {
    
    if ( is_singular( $post_types )
      && ! file_exists( get_stylesheet_directory() . '/single-newsletter.php' ) ) {
      $template = plugin_dir_path(__FILE__) . 'templates/single-newsletter.php';
    }
    
    //print_r( get_post_type( get_the_ID() ) );
    //$template = plugin_dir_path(__FILE__) . 'templates/single-newsletter.php';
    return $template;
  } // registerPostTemplates()

  function registerSaveHandler($id) {
    if ( is_admin() 
      && ( $this->config->custom->post_type == $_POST['post_type'])
      && !empty($_POST['spl-mailgun-newsletter-confirm']) ) {

      $this->processNewsletter($id, $_POST['spl-mailgun-newsletter-subject'], $_POST['spl-mailgun-newsletter-list'], $_POST['spl-mailgun-newsletter-address'], $_POST['spl-mailgun-newsletter-template']);
    }
  } // registerSaveHandler()

  function registerPostType() {
    $args = array(
      'labels'        => $this->getPostTypeLabels()
    , 'description'   => 'Newsletters'
    , 'public'        => true
    , 'menu_position' => 30
    , 'supports'      => array( 'title'
                              , 'editor'
                              , 'thumbnail'
                              //, 'excerpt'
                              //, 'comments' 
                              )
    , 'has_archive'   => true
    , 'slug'          => 'newsletter'
    , 'register_meta_box_cb' => array($this, 'initPublishControls')
    );

    register_post_type( 'newsletter', $args );  
    register_activation_hook( __FILE__, array( $this, 'activateNewsletter' ) );
  } // registerPostType()

  function getPostTypeLabels() {
    $labels = array(
      'name'               => _x( 'Newsletters', 'post type general name' )
    , 'singular_name'      => _x( 'Newsletter', 'post type singular name' )
    , 'add_new'            => _x( 'Add New', 'newsletter' )
    , 'add_new_item'       => __( 'Add a New Newsletter' )
    , 'edit_item'          => __( 'Edit Newsletter' )
    , 'new_item'           => __( 'New Newsletter' )
    , 'all_items'          => __( 'All Newsletters' )
    , 'view_item'          => __( 'View Newsletters' )
    , 'search_items'       => __( 'Search Newsletters' )
    , 'not_found'          => __( 'No newsletters found' )
    , 'not_found_in_trash' => __( 'No newsletters found in the Trash' )
    , 'parent_item_colon'  => ''
    , 'menu_name'          => 'Newsletters'
    );

    return $labels;
  } // getPostTypeLabels()

  function initPublishControls() {
    add_meta_box(
      'spl_mailgun_newsletter_publish_controls' // Unique ID
    , 'Send Newsletter'                         // Title
    , array($this, 'getPublishConrols')         // Callback function
    , 'newsletter'                              // Admin page (or post type)
    , 'side'                                    // Context<commit_msg>activate<commit_after><?php

/**
 * @package SPL_Mailgun
 * @version 0.1
 */

/*
Plugin Name: SPL Mailgun
Plugin URI: http://www.spokanelibrary.org/
Description: Hooks a custom post type to a mailgun campaign.
Author: <NAME>
Author URI: http://seangirard.com
Version: 0.1
*/

require('config.php');
require('settings.php');
require('functions.php');

function activateNewsletter() {
  flush_rewrite_rules(false);
}
register_activation_hook( __FILE__, activateNewsletter() );

$config = new SPL_Mailgun_Newsletter_Config();
$newsletter = new SPL_Mailgun_Newsletter($config);

if ( is_admin() ) {
  $admin = new SPL_Mailgun_Newsletter_Settings();
}

class SPL_Mailgun_Newsletter {

  var $config;

  function __construct($config=null) {
    if ( !is_null($config) 
          && isset($config->plugin['mailgun-public-key']) 
          && isset($config->plugin['mailgun-private-key']) ) {
      $this->config = $config;
      $this->initNewsletter();
    }
  }

  static function activateNewsletter() {
    // false does not attempt to overwrite .htaccess
    flush_rewrite_rules(false);
  }

  function initNewsletter() {
    //$this->registerPostTemplates();
    
    add_action( 'init', array( $this, 'registerPostType' ) );
    add_action( 'init', array($this, 'initCmbMetaBoxes'), 9999 );

    add_action( 'save_post', array( $this, 'registerSaveHandler' ) );

    add_filter( 'template_include', array($this, 'registerPostTemplates'));
    add_filter( 'cmb_meta_boxes', array($this, 'getNewsletterCmbMetaBoxes') );
    

  } // initNewsletter()

  function registerPostTemplates($template) {
    
    $post_types = array( 'newsletter' );
    /*
    if ( is_post_type_archive( $post_types ) 
      && ! file_exists( get_stylesheet_directory() . '/archive-newsletter.php' ) ) {
      $template = plugin_dir_path(__FILE__) . 'templates/archive-newsletter.php';
    }
    */
    //if ( 'newsletter' == get_post_type( get_the_ID() ) ) {
    
    if ( is_singular( $post_types )
      && ! file_exists( get_stylesheet_directory() . '/single-newsletter.php' ) ) {
      $template = plugin_dir_path(__FILE__) . 'templates/single-newsletter.php';
    }
    
    //print_r( get_post_type( get_the_ID() ) );
    //$template = plugin_dir_path(__FILE__) . 'templates/single-newsletter.php';
    return $template;
  } // registerPostTemplates()

  function registerSaveHandler($id) {
    if ( is_admin() 
      && ( $this->config->custom->post_type == $_POST['post_type'])
      && !empty($_POST['spl-mailgun-newsletter-confirm']) ) {

      $this->processNewsletter($id, $_POST['spl-mailgun-newsletter-subject'], $_POST['spl-mailgun-newsletter-list'], $_POST['spl-mailgun-newsletter-address'], $_POST['spl-mailgun-newsletter-template']);
    }
  } // registerSaveHandler()

  function registerPostType() {
    $args = array(
      'labels'        => $this->getPostTypeLabels()
    , 'description'   => 'Newsletters'
    , 'public'        => true
    , 'menu_position' => 30
    , 'supports'      => array( 'title'
                              , 'editor'
                              , 'thumbnail'
                              //, 'excerpt'
                              //, 'comments' 
                              )
    , 'has_archive'   => true
    , 'slug'          => 'newsletter'
    , 'register_meta_box_cb' => array($this, 'initPublishControls')
    );

    register_post_type( 'newsletter', $args );  
    //register_activation_hook( __FILE__, array( $this, 'activateNewsletter' ) );
  } // registerPostType()

  function getPostTypeLabels() {
    $labels = array(
      'name'               => _x( 'Newsletters', 'post type general name' )
    , 'singular_name'      => _x( 'Newsletter', 'post type singular name' )
    , 'add_new'            => _x( 'Add New', 'newsletter' )
    , 'add_new_item'       => __( 'Add a New Newsletter' )
    , 'edit_item'          => __( 'Edit Newsletter' )
    , 'new_item'           => __( 'New Newsletter' )
    , 'all_items'          => __( 'All Newsletters' )
    , 'view_item'          => __( 'View Newsletters' )
    , 'search_items'       => __( 'Search Newsletters' )
    , 'not_found'          => __( 'No newsletters found' )
    , 'not_found_in_trash' => __( 'No newsletters found in the Trash' )
    , 'parent_item_colon'  => ''
    , 'menu_name'          => 'Newsletters'
    );

    return $labels;
  } // getPostTypeLabels()

  function initPublishControls() {
    add_meta_box(
      'spl_mailgun_newsletter_publish_controls' // Unique ID
    , 'Send Newsletter'                         // Title
    , array($this, 'getPublishConrols')         // Callback function
    , 'newsletter'                              // Admin page (or post type)
    , 'side'                                    // Context
{'fraction_non_alphanumeric': 0.1515571672354949, 'fraction_numerical': 0.0021331058020477816, 'mean_word_length': 2.564044089699734, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '160186', 'n_tokens_mistral': 2997, 'n_tokens_neox': 2931, 'n_words': 523}