Merge pull request #395 from mailpoet/many_improvements

Many improvements
This commit is contained in:
Tautvidas Sipavičius
2016-03-23 13:38:40 +02:00
18 changed files with 376 additions and 188 deletions

View File

@@ -13,7 +13,7 @@ class Env {
static $assets_path;
static $assets_url;
static $temp_path;
static $temp_URL;
static $temp_url;
static $languages_path;
static $lib_path;
static $plugin_prefix;
@@ -39,7 +39,7 @@ class Env {
self::$assets_url = plugins_url('/assets', $file);
$wp_upload_dir = wp_upload_dir();
self::$temp_path = $wp_upload_dir['path'];
self::$temp_URL = $wp_upload_dir['url'];
self::$temp_url = $wp_upload_dir['url'];
self::$languages_path = self::$path . '/lang';
self::$lib_path = self::$path . '/lib';
self::$plugin_prefix = 'mailpoet_';

View File

@@ -131,7 +131,7 @@ class Initializer {
}
function setupWidget() {
$widget = new Widget();
$widget = new Widget($this->renderer);
$widget->init();
}

View File

@@ -59,7 +59,7 @@ class Renderer {
}
function detectCache() {
$cache_path = Env::$views_path . '/cache';
$cache_path = Env::$temp_path . '/cache';
if(WP_DEBUG === false) {
return $cache_path;
}

View File

@@ -1,11 +1,17 @@
<?php
namespace MailPoet\Config;
use \MailPoet\Util\Security;
use \MailPoet\Models\Form;
if(!defined('ABSPATH')) exit;
class Widget {
function __construct() {
private $renderer = null;
function __construct($renderer = null) {
if($renderer !== null) {
$this->renderer = $renderer;
}
}
function init() {
@@ -13,11 +19,67 @@ class Widget {
if(!is_admin()) {
$this->setupDependencies();
$this->setupIframe();
} else {
$this->setupAdminDependencies();
}
}
function setupIframe() {
$form_id = (isset($_GET['mailpoet_form_iframe']) ? (int)$_GET['mailpoet_form_iframe'] : 0);
if($form_id > 0) {
$form = Form::findOne($form_id);
if($form !== false) {
$form_widget = new \MailPoet\Form\Widget();
$form_html = $form_widget->widget(array(
'form' => $form_id,
'form_type' => 'iframe'
));
// capture javascripts
ob_start();
wp_print_scripts('jquery');
wp_print_scripts('mailpoet_vendor');
wp_print_scripts('mailpoet_public');
$scripts = ob_get_contents();
ob_end_clean();
// language attributes
$language_attributes = array();
$is_rtl = (bool)(function_exists('is_rtl') && is_rtl());
if($is_rtl) {
$language_attributes[] = 'dir="rtl"';
}
if($lang = get_bloginfo('language')) {
if(get_option('html_type') === 'text/html') {
$language_attributes[] = "lang=\"$lang\"";
}
}
$language_attributes = apply_filters(
'language_attributes', implode(' ', $language_attributes)
);
$data = array(
'language_attributes' => $language_attributes,
'scripts' => $scripts,
'form' => $form_html,
'mailpoet_form' => array(
'ajax_url' => admin_url('admin-ajax.php', 'absolute'),
'is_rtl' => $is_rtl,
'token' => Security::generateToken()
)
);
echo $this->renderer->render('form/iframe.html', $data);
exit();
}
}
}
function registerWidget() {
register_widget('\MailPoet\Form\Widget');
}

View File

@@ -17,8 +17,7 @@ class Export {
case 'iframe':
// generate url to load iframe's content
$iframe_url = add_query_arg(array(
'mailpoet_page' => 'mailpoet_form_iframe',
'mailpoet_form' => $form['id']
'mailpoet_form_iframe' => $form['id']
), site_url());
// generate iframe
@@ -31,7 +30,7 @@ class Export {
'class="mailpoet_form_iframe"',
'vspace="0"',
'tabindex="0"',
'onload="javascript:(this.style.height = this.contentWindow.document.body.scrollHeight + \'px\');"',
'onload="MailPoet.Iframe.autoSize(this);"',
'marginwidth="0"',
'marginheight="0"',
'hspace="0"',

View File

@@ -154,7 +154,7 @@ class Widget extends \WP_Widget {
$output = '';
if(!empty($body)) {
$form_id = $this->id_base.'_'.$this->number;
$form_id = $this->id_base.'_'.$form['id'];
$data = array(
'form_id' => $form_id,

View File

@@ -226,7 +226,7 @@ class Export {
function getExportFileURL($file) {
return sprintf(
'%s/%s',
Env::$temp_URL,
Env::$temp_url,
basename($file)
);
}

View File

@@ -19,7 +19,8 @@ class Pages {
function init() {
$action = $this->getAction();
if($action !== null) {
add_filter('document_title_parts', array($this,'setWindowTitle'), 10, 1);
add_filter('wp_title', array($this,'setWindowTitle'), 10, 1);
add_filter('document_title_parts', array($this,'setWindowTitleParts'), 10, 1);
add_filter('the_title', array($this,'setPageTitle'), 10, 1);
add_filter('the_content', array($this,'setPageContent'), 10, 1);
}
@@ -59,7 +60,11 @@ class Pages {
return (array_key_exists('mailpoet_preview', $_GET));
}
function setWindowTitle($meta = array()) {
function setWindowTitle($title) {
return $this->setPageTitle($title);
}
function setWindowTitleParts($meta = array()) {
$meta['title'] = $this->setPageTitle($meta['title']);
return $meta;
}