archives page
This commit is contained in:
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
|
use \MailPoet\Models\Newsletter;
|
||||||
|
use \MailPoet\Models\Subscriber;
|
||||||
|
use \MailPoet\Models\SubscriberSegment;
|
||||||
|
|
||||||
class Shortcodes {
|
class Shortcodes {
|
||||||
function __construct() {
|
function __construct() {
|
||||||
@ -9,6 +12,26 @@ class Shortcodes {
|
|||||||
// form widget shortcode
|
// form widget shortcode
|
||||||
add_shortcode('mailpoet_form', array($this, 'formWidget'));
|
add_shortcode('mailpoet_form', array($this, 'formWidget'));
|
||||||
add_shortcode('wysija_form', array($this, 'formWidget'));
|
add_shortcode('wysija_form', array($this, 'formWidget'));
|
||||||
|
|
||||||
|
// subscribers count shortcode
|
||||||
|
add_shortcode('mailpoet_subscribers_count', array(
|
||||||
|
$this, 'getSubscribersCount'
|
||||||
|
));
|
||||||
|
add_shortcode('wysija_subscribers_count', array(
|
||||||
|
$this, 'getSubscribersCount'
|
||||||
|
));
|
||||||
|
|
||||||
|
// archives page
|
||||||
|
add_shortcode('mailpoet_archive', array(
|
||||||
|
$this, 'getArchive'
|
||||||
|
));
|
||||||
|
|
||||||
|
add_filter('mailpoet_archive_date', array(
|
||||||
|
$this, 'renderArchiveDate'
|
||||||
|
), 2);
|
||||||
|
add_filter('mailpoet_archive_subject', array(
|
||||||
|
$this, 'renderArchiveSubject'
|
||||||
|
), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formWidget($params = array()) {
|
function formWidget($params = array()) {
|
||||||
@ -23,4 +46,76 @@ class Shortcodes {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSubscribersCount($params) {
|
||||||
|
if(!empty($params['segments'])) {
|
||||||
|
$segment_ids = array_map(function($segment_id) {
|
||||||
|
return (int)trim($segment_id);
|
||||||
|
},explode(',', $params['segments']));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(empty($segment_ids)) {
|
||||||
|
return Subscriber::filter('subscribed')->count();
|
||||||
|
} else {
|
||||||
|
return SubscriberSegment::whereIn('segment_id', $segment_ids)
|
||||||
|
->select('subscriber_id')->distinct()
|
||||||
|
->filter('subscribed')
|
||||||
|
->findResultSet()->count();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getArchive($params) {
|
||||||
|
if(!empty($params['segments'])) {
|
||||||
|
$segment_ids = array_map(function($segment_id) {
|
||||||
|
return (int)trim($segment_id);
|
||||||
|
},explode(',', $params['segments']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$newsletters = array();
|
||||||
|
$html = '';
|
||||||
|
|
||||||
|
// TODO: needs more advanced newsletters in order to finish
|
||||||
|
$newsletters = Newsletter::limit(10)->orderByDesc('created_at')->findMany();
|
||||||
|
|
||||||
|
if(empty($newsletters)) {
|
||||||
|
return apply_filters(
|
||||||
|
'mailpoet_archive_no_newsletters',
|
||||||
|
__('Oops! There are no newsletters to display.')
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$title = apply_filters('mailpoet_archive_title', '');
|
||||||
|
if(!empty($title)) {
|
||||||
|
$html .= '<h3 class="mailpoet_archive_title">'.$title.'</h3>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$html .= '<ul class="mailpoet_archive">';
|
||||||
|
foreach($newsletters as $newsletter) {
|
||||||
|
$html .= '<li>'.
|
||||||
|
'<span class="mailpoet_archive_date">'.
|
||||||
|
apply_filters('mailpoet_archive_date', $newsletter).
|
||||||
|
'</span>
|
||||||
|
<span class="mailpoet_archive_subject">'.
|
||||||
|
apply_filters('mailpoet_archive_subject', $newsletter).
|
||||||
|
'</span>
|
||||||
|
</li>';
|
||||||
|
}
|
||||||
|
$html .= '</ul>';
|
||||||
|
}
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderArchiveDate($newsletter) {
|
||||||
|
return date_i18n(
|
||||||
|
get_option('date_format'),
|
||||||
|
strtotime($newsletter->created_at)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderArchiveSubject($newsletter) {
|
||||||
|
return '<a href="TODO" target="_blank" title="'
|
||||||
|
.esc_attr(__('Preview in new tab')).'">'
|
||||||
|
.esc_attr($newsletter->subject).
|
||||||
|
'</a>';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
use \MailPoet\Models\Subscriber;
|
|
||||||
use \MailPoet\Util\Security;
|
use \MailPoet\Util\Security;
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
@ -22,18 +21,6 @@ class Widget {
|
|||||||
|
|
||||||
function registerWidget() {
|
function registerWidget() {
|
||||||
register_widget('\MailPoet\Form\Widget');
|
register_widget('\MailPoet\Form\Widget');
|
||||||
|
|
||||||
// subscribers count shortcode
|
|
||||||
add_shortcode('mailpoet_subscribers_count', array(
|
|
||||||
$this, 'getSubscribersCount'
|
|
||||||
));
|
|
||||||
add_shortcode('wysija_subscribers_count', array(
|
|
||||||
$this, 'getSubscribersCount'
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSubscribersCount($params) {
|
|
||||||
return Subscriber::filter('subscribed')->count();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupDependencies() {
|
function setupDependencies() {
|
||||||
|
@ -33,6 +33,10 @@ class SubscriberSegment extends Model {
|
|||||||
return $orm;
|
return $orm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function subscribed($orm) {
|
||||||
|
return $orm->where('status', 'subscribed');
|
||||||
|
}
|
||||||
|
|
||||||
static function createMultiple($segmnets, $subscribers) {
|
static function createMultiple($segmnets, $subscribers) {
|
||||||
$values = Helpers::flattenArray(
|
$values = Helpers::flattenArray(
|
||||||
array_map(function ($segment) use ($subscribers) {
|
array_map(function ($segment) use ($subscribers) {
|
||||||
|
@ -347,7 +347,7 @@
|
|||||||
values = $(this).val() || [];
|
values = $(this).val() || [];
|
||||||
|
|
||||||
if (values.length > 0) {
|
if (values.length > 0) {
|
||||||
shortcode += ' list_id="';
|
shortcode += ' segments="';
|
||||||
shortcode += values.join(',');
|
shortcode += values.join(',');
|
||||||
shortcode += '"';
|
shortcode += '"';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user