';
}
if (!empty($this->warnings)) {
foreach ((array) $this->warnings as $warning) {
echo '
';
echo $warning;
echo '
';
}
}
if (!empty($this->messages)) {
echo '
';
echo $this->messages;
echo '
';
}
}
function add_message_saved() {
if (!empty($this->messages)) {
$this->messages .= '
';
}
$this->messages .= __('Saved.', 'newsletter');
}
function add_message_deleted() {
if (!empty($this->messages)) {
$this->messages .= '
';
}
$this->messages .= __('Deleted.', 'newsletter');
}
function add_message_reset() {
if (!empty($this->messages)) {
$this->messages .= '
';
}
$this->messages .= __('Options reset.', 'newsletter');
}
function add_message_done() {
if (!empty($this->messages)) {
$this->messages .= '
';
}
$this->messages .= __('Done.', 'newsletter');
}
function add_language_warning() {
$newsletter = Newsletter::instance();
$current_language = $newsletter->get_current_language();
if (!$current_language) {
return;
}
$this->warnings[] = 'You are configuring the language ' . $newsletter->get_language_label($current_language) . '. Switch to "all languages" to see every options.';
}
function hint($text, $url = '') {
echo '
';
// Do not escape that, it can be formatted
echo $text;
if (!empty($url)) {
echo ' Read more.';
}
echo '
';
}
function yesno($name) {
$value = isset($this->data[$name]) ? (int) $this->data[$name] : 0;
echo ' ';
}
function enabled($name = 'enabled') {
$value = isset($this->data[$name]) ? (int) $this->data[$name] : 0;
echo '';
}
function disabled($name) {
$value = isset($this->data[$name]) ? (int) $this->data[$name] : 0;
echo '';
}
/**
* Creates a set of checkbox all named as $name with values and labels extracted from
* $values_labels. A checkbox will be checked if internal data under key $name is an array
* and contains the value of the current (echoing) checkbox.
*
* On submit it produces an array under the name $name IF at least one checkbox has
* been checked. Otherwise the key won't be present.
*
* @param array $values
* @param string $name
* @param array $values_labels
*/
function checkboxes_group($name, $values_labels) {
$value_array = $this->get_value_array($name);
echo "
";
foreach ($values_labels as $value => $label) {
echo "
";
echo '
";
}
echo "
";
}
/** Creates a checkbox group with all public post types.
*/
function post_types($name = 'post_types') {
$list = array();
$post_types = get_post_types(array('public' => true), 'objects', 'and');
foreach ($post_types as $post_type) {
$list[$post_type->name] = $post_type->labels->name;
}
$this->checkboxes_group($name, $list);
}
function posts_select($name, $max = 20, $args = array()) {
$args = array_merge(array(
'posts_per_page' => 5,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'author_name' => '',
'post_status' => 'publish',
'suppress_filters' => true
), $args);
$args['posts_per_page'] = $max;
$posts = get_posts($args);
$options = array();
foreach ($posts as $post) {
$options['' . $post->ID] = $post->post_title;
}
$this->select($name, $options);
}
function select_number($name, $min, $max) {
$options = array();
for ($i = $min; $i <= $max; $i++) {
$options['' . $i] = $i;
}
$this->select($name, $options);
}
function page($name = 'page', $first = null, $language = '', $show_id = false) {
$args = array(
'post_type' => 'page',
'posts_per_page' => 1000,
'offset' => 0,
'orderby' => 'post_title',
'post_status' => 'any',
'suppress_filters' => true
);
$pages = get_posts($args);
//$pages = get_pages();
$options = array();
foreach ($pages as $page) {
/* @var $page WP_Post */
$label = $page->post_title;
if ($page->post_status != 'publish') {
$label .= ' (' . $page->post_status . ')';
}
if ($show_id) {
$label .= ' [' . $page->ID . ']';
}
$options[$page->ID] = $label;
}
$this->select($name, $options, $first);
}
/** Used to create a select which is part of a group of controls identified by $name that will
* produce an array of values as $_REQUEST['name'].
* @param string $name
* @param array $options Associative array
*/
function select_group($name, $options) {
$value_array = $this->get_value_array($name);
echo '';
}
function select($name, $options, $first = null) {
$value = $this->get_value($name);
echo '';
}
function select_images($name, $options, $first = null) {
$value = $this->get_value($name);
echo '';
echo '';
}
function select2($name, $options, $first = null, $multiple = false, $style = null, $placeholder = '') {
if ($multiple) {
$option_name = "options[" . esc_attr($name) . "][]";
} else {
$option_name = "options[" . esc_attr($name) . "]";
}
if (is_null($style)) {
$style = 'width: 100%';
}
$value = $this->get_value($name);
echo '';
echo '';
}
function select_grouped($name, $groups) {
$value = $this->get_value($name);
echo '';
}
/**
* Generated a select control with all available templates. From version 3 there are
* only on kind of templates, they are no more separated by type.
*/
function themes($name, $themes, $submit_on_click = true) {
foreach ($themes as $key => $data) {
echo '';
}
echo '';
}
function value($name) {
echo htmlspecialchars($this->data[$name]);
}
function value_date($name, $show_remaining = true) {
$time = $this->get_value($name);
echo gmdate(get_option('date_format') . ' ' . get_option('time_format'), $time + get_option('gmt_offset') * 3600);
$delta = $time - time();
if ($show_remaining && $delta > 0) {
echo 'Remaining: ';
$delta = $time - time();
$days = floor($delta / (24 * 3600));
$delta = $delta - $days * 24 * 3600;
$hours = floor($delta / 3600);
$delta = $delta - $hours * 3600;
$minutes = floor($delta / 60);
if ($days > 0)
echo $days . ' days ';
echo $hours . ' hours ';
echo $minutes . ' minutes ';
}
}
function text($name, $size = 20, $placeholder = '') {
$value = $this->get_value($name);
echo '';
}
function text_email($name, $size = 40) {
$value = $this->get_value($name);
echo '';
}
function text_url($name, $size = 40) {
$value = $this->get_value($name);
echo '';
}
function hidden($name) {
$value = $this->get_value($name);
echo '';
}
function button($action, $label, $function = null) {
if ($function != null) {
echo '';
} else {
echo '';
}
}
/**
* With translated "Save" label.
*/
function button_save($function = null) {
$this->button_primary('save', ' ' . __('Save', 'newsletter'), $function);
}
function button_reset($data = '') {
echo '';
}
function button_link($url, $label) {
echo '', $label, '';
}
function button_configure($url) {
echo '', _e('Configure', 'newsletter'), '';
}
function button_back($url) {
echo ' ';
_e('Back', 'newsletter');
echo '';
}
/**
* Creates a button with "copy" action.
* @param type $data
*/
function button_copy($data = '') {
echo '';
}
/**
* Creates a button wirh "delete" action.
* @param type $data
*/
function button_delete($data = '') {
echo '';
}
function button_primary($action, $label, $function = null) {
if ($function != null) {
echo '';
} else {
echo '', $label, '';
}
}
function button_confirm($action, $label, $message = '', $data = '') {
if (empty($message)) {
$message = __('Are you sure?', 'newsletter');
}
echo '';
}
function editor($name, $rows = 5, $cols = 75) {
echo '';
}
function wp_editor($name, $settings = array()) {
$value = $this->get_value($name);
wp_editor($value, $name, array_merge(array(
'tinymce' => array('content_css' => plugins_url('newsletter') . '/css/wp-editor.css?ver=' . filemtime(NEWSLETTER_DIR . '/css/wp-editor.css')),
'textarea_name' => 'options[' . esc_attr($name) . ']',
'wpautop' => false
), $settings));
//echo '
';
}
function color($name) {
$value = $this->get_value($name);
//echo '';
}
/** Creates a set of checkbox named $name_[category id] (so they are posted with distinct names).
*/
function categories($name = 'category') {
$categories = get_categories();
echo '
';
}
/**
* Creates a set of checkbox to activate the profile preferences. Every checkbox has a DIV around to
* be formatted.
*/
function categories_group($name, $show_mode = false) {
$categories = get_categories();
if ($show_mode) {
$this->select($name . '_mode', array('include' => 'To be included', 'exclude' => 'To be excluded'));
}
echo '
';
}
/**
* Creates a set of checkboxes named $name_[preference number] (so they are
* distinct fields).
* Empty preferences are skipped.
*/
function preferences($name = 'preferences') {
$lists = Newsletter::instance()->get_lists();
echo '
';
}
}
function lists_checkboxes($name = 'lists') {
$this->preferences_group($name);
}
/**
* Creates a set of checkboxes all names $name[] and the preference number as value
* so the selected checkboxes are retrieved as an array of values ($REQUEST[$name]
* will be an array if at east one preference is checked).
*/
function preferences_group($name = 'preferences') {
$lists = Newsletter::instance()->get_lists();
echo '
';
}
/** Creates as many selects as the active preferences with the three values
* 'any', 'yes', 'no' corresponding to the values 0, 1, 2.
*/
function preferences_selects($name = 'preferences', $skip_empty = false) {
$lists = Newsletter::instance()->get_lists();
echo '
';
echo '';
echo '';
}
function media_input($option, $name, $label) {
if (!empty($label)) {
$output = '';
}
$output .= '';
$output .= '';
$output .= ' ';
echo $output;
}
function language($name = 'language', $empty_label = 'All') {
if (!class_exists('SitePress') && !function_exists('pll_default_language') && !class_exists('TRP_Translate_Press')) {
echo __('Install a multilanguage plugin.', 'newsletter');
echo ' ', __('Read more', 'newsletter'), '';
return;
}
$languages = Newsletter::instance()->get_languages();
if (!empty($empty_label)) {
$languages = array_merge(array('' => $empty_label), $languages);
}
$this->select($name, $languages);
}
function is_multilanguage() {
return Newsletter::instance()->is_multilanguage();
}
/**
* Creates a checkbox group with all active languages. Each checkbox is named
* $name[] and values with the relative language code.
*
* @param string $name
*/
function languages($name = 'languages') {
if (!$this->is_multilanguage()) {
echo __('Install WPML or Polylang for multilanguage support', 'newsletter');
return;
}
$language_options = Newsletter::instance()->get_languages();
if (empty($language_options)) {
echo __('Your multilanguage plugin is not supported or there are no languages defined', 'newsletter');
return;
}
$this->checkboxes_group($name, $language_options);
}
/**
* Prints a formatted date using the formats and timezone of WP, including the current date and time and the
* time left to the passed time.
*
* @param int $time
* @param int $now
* @param bool $left
* @return string
*/
static function print_date($time = null, $now = false, $left = false) {
if (is_null($time)) {
$time = time();
}
if ($time == false) {
$buffer = 'none';
} else {
$buffer = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time + get_option('gmt_offset') * 3600);
}
if ($now) {
$buffer .= ' (now: ' . gmdate(get_option('date_format') . ' ' .
get_option('time_format'), time() + get_option('gmt_offset') * 3600);
$buffer .= ')';
}
if ($left) {
if ($time - time() < 0) {
$buffer .= ', ' . (time() - $time) . ' seconds late';
} else {
$buffer .= ', ' . gmdate('H:i:s', $time - time()) . ' left';
}
}
return $buffer;
}
/**
* Prints the help button near a form field. The label is used as icon title.
*
* @param string $url
* @param string $label
*/
static function help($url, $label = '') {
echo '';
}
static function idea($url, $label = '') {
echo '';
}
static function field_help($url, $text = '') {
echo ' ', $text, '';
}
/**
* Prints a panel link to the documentation.
*
* @param type $url
* @param type $text
*/
static function panel_help($url, $text = '') {
if (empty($text))
$text = __('Need help?', 'newsletter');
echo '', $text, '';
}
/**
* Prints an administration page link to the documentation (just under the administration page title.
* @param type $url
* @param type $text
*/
static function page_help($url, $text = '') {
if (empty($text))
$text = __('Need help?', 'newsletter');
echo '