Merge pull request #395 from mailpoet/many_improvements
Many improvements
This commit is contained in:
@@ -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_';
|
||||
|
@@ -131,7 +131,7 @@ class Initializer {
|
||||
}
|
||||
|
||||
function setupWidget() {
|
||||
$widget = new Widget();
|
||||
$widget = new Widget($this->renderer);
|
||||
$widget->init();
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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');
|
||||
}
|
||||
|
Reference in New Issue
Block a user