Skip to content

Commit

Permalink
Merge branch 'library-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
No3x committed Oct 1, 2015
2 parents 2fde5d3 + a87a3d2 commit ba1f837
Show file tree
Hide file tree
Showing 288 changed files with 42,012 additions and 1,078 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/vendor/
/credentials.json
/releases
/node_modules
/build
165 changes: 165 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
shell: {
composer: {
command: 'composer install --no-dev --no-scripts --prefer-dist'
},
git_checkout: {
command: 'git checkout-index -a -f --prefix=build/'
}
},
clean: {
pre_build: [
'vendor/',
'build/'
],
post_build: [
'build/'
],
pre_compress: [
'build/releases'
]
},
run: {
tool: {
cmd: 'composer'
}
},
copyto: {
vendor: {
files: [
{
src: ['vendor/**'], dest: 'build/',
expand: true
}
]
}
},
search: {
credentials: {
files: {
src: ["**/credentials.json"]
},
options: {
failOnMatch: true
}
}
},
compress: {
main: {
options: {
mode: 'zip',
archive: 'releases/<%= pkg.name %>-<%= pkg.version %>.zip'
},
expand: true,
cwd: 'build/',
src: [
'**/*',
'!build/*'
]
}
},
gitadd: {
add_zip: {
options: {
force: true
},
files: {
src: [ 'releases/<%= pkg.name %>-<%= pkg.version %>.zip' ]
}
}
},
gittag: {
addtag: {
options: {
tag: 'release/<%= pkg.version %>',
message: 'Version <%= pkg.version %>'
}
}
},
gitcommit: {
commit: {
options: {
message: 'Prepared release <%= pkg.version %>.',
noVerify: true,
noStatus: false,
allowEmpty: true
},
files: {
src: [ 'package.json', 'wp-mail-logging.php', 'composer.json', 'composer.lock' ]
}
}
},
gitpush: {
push: {
options: {
tags: true,
remote: 'origin',
branch: 'test-release'
}
}
},
replace: {
core_file: {
src: [ 'wp-mail-logging.php' ],
overwrite: true,
replacements: [
{
from: /Version:\s*(.*)/,
to: "Version: <%= pkg.version %>"
}
]
},
readme: {
src: [ 'readme.txt' ],
overwrite: true,
replacements: [
{
from: /Stable tag:\s*(.*)/,
to: "Stable tag: <%= pkg.version %>"
}
]
}
},
'github-release': {
options: {
repository: 'No3x/wp-mail-logging', // Path to repository
auth: grunt.file.readJSON('credentials.json'),
release: {
tag_name: 'release/<%= pkg.version %>',
name: 'v<%= pkg.version %>',
body: 'Description of the release',
draft: true,
prerelease: true
}
},
files: {
src: ['releases/<%= pkg.name %>-<%= pkg.version %>.zip']
}
},

});

//load modules
grunt.loadNpmTasks('grunt-search');
grunt.loadNpmTasks('grunt-copy-to');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-git');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-github-releaser');

//release tasks
grunt.registerTask('assert-valid-copy', [ 'search:credentials' ]);
grunt.registerTask('copy', [ 'shell:git_checkout' ]);
grunt.registerTask('clean_pre_build', [ 'clean:pre_build' ]);
grunt.registerTask('version_number', [ 'replace:core_file', 'replace:readme' ]);
grunt.registerTask('pre_vcs', [ 'shell:composer', 'version_number', 'copy', 'copyto:vendor', 'compress' ]);
grunt.registerTask('do_git', [ /*'gitadd',*/ 'gitcommit', 'gittag', 'gitpush' ]);

grunt.registerTask('just_build', [ 'clean_pre_build', 'shell:composer', 'copy', 'copyto:vendor', 'assert-valid-copy', 'compress' ]);
grunt.registerTask('release', [ 'clean_pre_build', 'pre_vcs', 'do_git', 'github-release', 'clean:post_build' ]);
};
38 changes: 35 additions & 3 deletions WPML_API_Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@
* @author No3x
* @since 1.0
* The Plugin provides mechanisms to extend the displayed data.
* This class is not an API class. It is just an example.
* This class is not an API class. It is just an example how to hook in.
* If you consider writing a plugin please contact me for better hook support/documentation.
*/
class WPML_API_Example {

// require_once('WPML_API_Example.php');
// $aAPI = new WPML_API_Example();
function __construct() {

public function addActionsAndFilters() {
// In this example we are going to add a column 'test' in add_column.
add_filter( WPML_Plugin::HOOK_LOGGING_COLUMNS, array( &$this, 'add_column' ) );
add_filter( WPML_Plugin::HOOK_LOGGING_COLUMNS_RENDER, array( &$this, 'render_column' ), 10, 2 );
// Change the supported formats of modal e.g. dashed:
add_filter( WPML_Plugin::HOOK_LOGGING_SUPPORTED_FORMATS, array( &$this, 'add_supported_format') );
// Change content of format dashed HOOK_LOGGING_FORMAT_CONTENT_{$your_format} e.g. dashed:
add_filter( WPML_Plugin::HOOK_LOGGING_FORMAT_CONTENT . '_dashed', array( &$this, 'supported_format_dashed') );
}

/**
Expand Down Expand Up @@ -50,4 +55,31 @@ public function render_column( $item, $column_name ) {
return '';
}
}

/**
* Is called when supported formats are collected. You can add a format here then you can provide a content function.
* @since 1.6.0
* @param array $formats supported formats
* @return array supported formats + your additional formats
* @see WPML_Plugin::HOOK_LOGGING_SUPPORTED_FORMATS
*/
public function add_supported_format( $formats ) {
$formats[] = 'dashed';
return $formats;
}

/**
* This function is called for each of your additional formats. Change the content of the modal here.
* For example I add some dashes.
* @since 1.6.0
* @param $mail
* @return string
* @see WPML_Plugin::HOOK_LOGGING_FORMAT_CONTENT
*/
public function supported_format_dashed( $mail ) {
$dashedAppend = '';
foreach( $mail as $property => $value )
$dashedAppend .= str_replace(' ', '-', $value);
return $dashedAppend;
}
}
24 changes: 24 additions & 0 deletions WPML_DI_Container.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* User: No3x
* Date: 06.09.15
* Time: 12:47
*/

namespace No3x\WPML;
use No3x\WPML\Pimple\Container;

class WPML_DI_Container extends Container {

public function addActionsAndFilters() {
foreach ( $this->keys() as $key ) {
$content = $this[ $key ];
if ( is_object( $content ) ) {
$reflection = new \ReflectionClass( $content );
if ( $reflection->hasMethod( 'addActionsAndFilters' ) ) {
$content->addActionsAndFilters();
}
}
}
}
}
91 changes: 85 additions & 6 deletions WPML_Email_Log_List.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;

require_once( ABSPATH . 'wp-admin/includes/screen.php' );
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );

if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( plugin_dir_path( __FILE__ ) . 'inc/class-wp-list-table.php' );
}
Expand All @@ -16,15 +19,27 @@
* @author No3x
* @since 1.0
*/
class Email_Logging_ListTable extends \WP_List_Table {
class WPML_Email_Log_List extends \WP_List_Table {

const NONCE_LIST_TABLE = 'wpml-list_table';

private $supported_formats = array();
/**
* Initializes the List Table
* @since 1.0
*/
function __construct() {
function __construct( $supported_formats = array() ) {
$this->supported_formats = $supported_formats;
}

function addActionsAndFilters() {
add_action( 'admin_init', array( $this, 'init') );
add_filter( WPML_Plugin::HOOK_LOGGING_SUPPORTED_FORMATS, function() {
return $this->supported_formats;
} );
add_action( 'wp_ajax_wpml_email_get', __CLASS__ . '::ajax_wpml_email_get' );
}

function init() {
global $status, $page, $hook_suffix;

parent::__construct( array(
Expand Down Expand Up @@ -198,8 +213,9 @@ function column_message( $item ) {
if ( empty( $item['message'] ) ) {
return '';
}
$content = $this->sanitize_message( $this->render_mail( $item ) );
$message = '<a class="wp-mail-logging-view-message button button-secondary" href="#" data-message="' . htmlentities( $content ) . '">View</a>';
//$content = $this->sanitize_message( $this->render_mail_html( $item ) );
$content = $item['mail_id'];
$message = '<a class="wp-mail-logging-view-message button button-secondary" href="#" data-mail-id="' . esc_attr( $content ) . '">View</a>';
return $message;
}

Expand Down Expand Up @@ -248,6 +264,32 @@ function column_attachments( $item ) {
* @return string The mail as html
*/
function render_mail( $item ) {
$mailAppend = '';
foreach ( $item as $key => $value ) {
if ( array_key_exists( $key, $this->get_columns() ) && ! in_array( $key, $this->get_hidden_columns() ) ) {
$display = $this->get_columns();
$column_name = $key;
$title = "<span class=\"title\">{$display[$key]}: </span>";
$content = '';
if ( 'message' !== $column_name && method_exists( $this, 'column_' . $column_name ) ) {
$content .= call_user_func( array( $this, 'column_' . $column_name ), $item );
} else {
$content .= $this->column_default( $item, $column_name );
}
$mailAppend .= $title . htmlentities( $content );
}
}

return $mailAppend;
}

/**
* Renders all components of the mail.
* @since 1.6.0
* @param array $item The current item.
* @return string The mail as html
*/
function render_mail_html( $item ) {
$mailAppend = '';
foreach ( $item as $key => $value ) {
if ( array_key_exists( $key, $this->get_columns() ) && ! in_array( $key, $this->get_hidden_columns() ) ) {
Expand All @@ -263,7 +305,6 @@ function render_mail( $item ) {
}
return $mailAppend;
}

/**
* Defines available bulk actions.
* @since 1.0
Expand Down Expand Up @@ -331,4 +372,42 @@ function get_sortable_columns() {
'plugin_version'=> array( 'plugin_version', true ),
);
}

/**
* Ajax function to retrieve rendered mail in certain format.
* @since 1.6.0
*/
public static function ajax_wpml_email_get() {
$formats = is_array( $additional = apply_filters( WPML_Plugin::HOOK_LOGGING_SUPPORTED_FORMATS, array() ) ) ? $additional : array();

if( ! isset( $_POST['id'] ) )
wp_die("huh?");
$id = intval( $_POST['id'] );
$format_requested = isset( $_POST['format'] ) ? $_POST['format'] : 'html';
if( ! in_array( $format_requested, $formats ) )
wp_die("Unsupported Format");

$mail = Mail::find_one($id);
$instance = apply_filters('wpml_get_di_service', 'emailLogList' );
$mailAppend = '';
switch( $format_requested ) {
case 'html': {
$mailAppend .= $instance->render_mail_html( $mail->to_array() );
break;
}
case 'raw': {
$mailAppend .= $instance->render_mail( $mail->to_array() );
break;
}
case 'json': {
$mailAppend .= json_encode( $mail->to_array() );
break;
}
default:
$mailAppend .= apply_filters( WPML_Plugin::HOOK_LOGGING_FORMAT_CONTENT . "_{$format_requested}", $mail->to_array() );
break;
}
echo $mailAppend;
wp_die(); // this is required to terminate immediately and return a proper response
}
}
Loading

0 comments on commit ba1f837

Please sign in to comment.