/** * Get tempcode for adding/editing form. * * @param SHORT_TEXT A name for the Welcome E-mail * @param SHORT_TEXT The subject of the Welcome E-mail * @param LONG_TEXT The message body of the Welcome E-mail * @param integer The number of hours before sending the e-mail * @param ?AUTO_LINK What newsletter to send out to instead of members (NULL: none) * @return tempcode The input fields */ function get_form_fields($name = '', $subject = '', $text = '', $send_time = 0, $newsletter = 0) { $fields = new ocp_tempcode(); $fields->attach(form_input_line(do_lang_tempcode('NAME'), do_lang_tempcode('DESCRIPTION_NAME_REFERENCE'), 'name', $name, true)); $fields->attach(form_input_line(do_lang_tempcode('SUBJECT'), do_lang_tempcode('DESCRIPTION_WELCOME_EMAIL_SUBJECT'), 'subject', $subject, true)); $fields->attach(form_input_huge_comcode(do_lang_tempcode('TEXT'), do_lang_tempcode('DESCRIPTION_WELCOME_EMAIL_TEXT'), 'text', $text, true)); $fields->attach(form_input_integer(do_lang_tempcode('SEND_TIME'), do_lang_tempcode('DESCRIPTION_SEND_TIME'), 'send_time', $send_time, true)); if (addon_installed('newsletter')) { require_lang('newsletter'); if (get_value('welcome_nw_choice') === '1') { $newsletters = new ocp_tempcode(); $rows = $GLOBALS['SITE_DB']->query_select('newsletters', array('id', 'title')); if (get_forum_type() == 'ocf') { $newsletters->attach(form_input_list_entry('', is_null($newsletter), do_lang_tempcode('NEWSLETTER_OCF'))); } foreach ($rows as $_newsletter) { $newsletters->attach(form_input_list_entry(strval($_newsletter['id']), $_newsletter['id'] === $newsletter, get_translated_text($_newsletter['title']))); } if (!$newsletters->is_empty()) { $fields->attach(form_input_list(do_lang_tempcode('NEWSLETTER'), '', 'newsletter', $newsletters, NULL, false, false)); } } else { if (get_forum_type() == 'ocf') { require_lang('newsletter'); $fields->attach(form_input_tick(do_lang_tempcode('NEWSLETTER'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_INSTEAD'), 'newsletter', $newsletter == 1)); } } } return $fields; }
/** * The UI to send a newsletter. * * @param LONG_TEXT Default newsletter to put in * @return tempcode The UI */ function send_gui($_existing = '') { // If this is a periodic newsletter, we make some changes to the regular // language strings. $periodic_action_raw = post_param('periodic_choice', ''); $periodic_subject = ''; $defaults = mixed(); switch (preg_replace('#\\_\\d+$#', '', $periodic_action_raw)) { case 'remove_existing': // Remove whatever is already set. We don't need any changes for // this, but we do need a hidden form field. $periodic_action = 'remove'; break; case 'replace_existing': // Make the current newsletter periodic. This requires language // fiddling. $periodic_action = 'replace'; $periodic_subject = do_lang('PERIODIC_SUBJECT_HELP'); $periodic_id = intval(preg_replace('#^[^\\d]+#', '', $periodic_action_raw)); $_defaults = $GLOBALS['SITE_DB']->query_select('newsletter_periodic', array('*'), array('id' => $periodic_id), '', 1); if (!array_key_exists(0, $_defaults)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $defaults = $_defaults[0]; break; case 'make_periodic': // Make the current newsletter periodic. This requires language // fiddling. $periodic_action = 'make'; $periodic_subject = do_lang('PERIODIC_SUBJECT_HELP'); break; case 'no_change': default: // The default action is to leave the current settings as-is. $periodic_action = 'none'; break; } $title = get_page_title('NEWSLETTER_SEND'); $lang = choose_language($title); if (is_object($lang)) { return $lang; } $comcode_given = $_existing != '' && strpos($_existing, '<html') !== false; $_existing = post_param('message', $_existing); if ($_existing == '') { $from_news = get_param_integer('from_news', -1); if ($from_news != -1 && addon_installed('news')) { $rows = $GLOBALS['SITE_DB']->query_select('news', array('*'), array('id' => $from_news), 'ORDER BY id DESC', 1); if (!array_key_exists(0, $rows)) { require_lang('news'); return warn_screen(get_page_title('NEWS'), do_lang_tempcode('MISSING_RESOURCE')); } $myrow = $rows[0]; $_existing = get_translated_text($myrow['news_article'], NULL, $lang); if ($_existing == '') { $_existing = get_translated_text($myrow['news'], NULL, $lang); } } $existing = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f42', 'CONTENT' => $_existing, 'LANG' => $lang)); } else { $default = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f44', 'CONTENT' => $_existing, 'LANG' => $lang)); if (strpos($default->evaluate(), '<html') !== false) { if ($comcode_given) { $default = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f46', 'CONTENT' => comcode_to_tempcode($_existing), 'LANG' => $lang)); } $existing = $default; } else { $existing = make_string_tempcode($_existing); } } $post_url = build_url(array('page' => '_SELF', 'type' => 'confirm', 'old_type' => get_param('type', '')), '_SELF'); $submit_name = do_lang_tempcode('PREVIEW'); $hidden = new ocp_tempcode(); $hidden->attach(form_input_hidden('lang', $lang)); // Build up form $fields = new ocp_tempcode(); require_code('form_templates'); $default_subject = get_option('newsletter_title'); if (!is_null($defaults)) { $default_subject = $defaults['np_subject']; } if ($periodic_action != 'make' && $periodic_action != 'replace') { $default_subject .= ' - ' . get_timezoned_date(time(), false, false, false, true); } $default_subject = post_param('subject', $default_subject); $fields->attach(form_input_line_comcode(do_lang_tempcode('SUBJECT'), do_lang_tempcode('NEWSLETTER_DESCRIPTION_TITLE', $periodic_subject), 'subject', $default_subject, true)); $in_full = post_param_integer('in_full', 0); $chosen_categories = post_param('chosen_categories', ''); if ($periodic_action == 'make' || $periodic_action == 'replace') { // We are making a periodic newsletter. This means we need to pass // through the chosen categories if (!is_null($defaults)) { $chosen_categories = $defaults['np_message']; $in_full = $defaults['np_in_full']; $fields->attach(form_input_tick(do_lang_tempcode('EMBED_FULL_ARTICLES'), do_lang_tempcode('DESCRIPTION_EMBED_FULL_ARTICLES'), 'in_full', $in_full == 1)); $fields->attach(form_input_huge(do_lang_tempcode('NEWSLETTER_CONTENT'), do_lang('NEWSLETTER_CONTENT_SELECT'), 'chosen_categories', $chosen_categories, true)); } else { $hidden->attach(form_input_hidden('chosen_categories', $chosen_categories)); $hidden->attach(form_input_hidden('in_full', strval($in_full))); } $hidden->attach(form_input_hidden('cutoff_day', post_param('cutoff_day'))); $hidden->attach(form_input_hidden('cutoff_month', post_param('cutoff_month'))); $hidden->attach(form_input_hidden('cutoff_year', post_param('cutoff_year'))); $hidden->attach(form_input_hidden('cutoff_hour', post_param('cutoff_hour'))); $hidden->attach(form_input_hidden('cutoff_minute', post_param('cutoff_minute'))); $hidden->attach(form_input_hidden('message', $existing->evaluate())); } else { $hidden->attach(form_input_hidden('in_full', strval($in_full))); if (strpos($existing->evaluate(), '<html') === false) { $fields->attach(form_input_huge_comcode(do_lang_tempcode('MESSAGE'), do_lang_tempcode('DESCRIPTION_MESSAGE_NEWSLETTER'), 'message', $existing->evaluate(), true)); } else { $fields->attach(form_input_huge(do_lang_tempcode('MESSAGE'), do_lang_tempcode('DESCRIPTION_MESSAGE_NEWSLETTER'), 'message', $existing->evaluate(), true)); } } if (addon_installed('calendar') && $periodic_action == 'none' && cron_installed()) { $fields->attach(form_input_date__scheduler(do_lang_tempcode('DEFER_TIME'), do_lang_tempcode('DESCRIPTION_DEFER_TIME'), 'schedule', true, true, true)); } $from_email = post_param('from_email', get_option('staff_address')); if (!is_null($defaults)) { $from_email = post_param('from_email', $defaults['np_from_email']); } $fields->attach(form_input_email(do_lang_tempcode('FROM_EMAIL'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_FROM_EMAIL'), 'from_email', $from_email, true)); $from_name = post_param('from_name', get_site_name()); if (!is_null($defaults)) { $from_name = post_param('from_name', $defaults['np_from_name']); } $fields->attach(form_input_line(do_lang_tempcode('FROM_NAME'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_FROM_NAME'), 'from_name', $from_name, true)); $_html_only = post_param_integer('html_only', NULL); if (is_null($_html_only)) { $html_only = strpos($existing->evaluate(), '<html') !== false; if (!is_null($defaults)) { $html_only = $defaults['np_html_only']; } } else { $html_only = $_html_only == 1; } if (get_value('force_html_only') === '1') { $hidden->attach(form_input_hidden('html_only', '1')); } else { $fields->attach(form_input_tick(do_lang_tempcode('HTML_ONLY'), do_lang_tempcode('DESCRIPTION_HTML_ONLY'), 'html_only', $html_only)); } $l = new ocp_tempcode(); $priority = post_param_integer('priority', 3); if (!is_null($defaults)) { $priority = post_param_integer('priority', $defaults['np_priority']); } for ($i = 1; $i <= 5; $i++) { $l->attach(form_input_list_entry(strval($i), $i == $priority, do_lang_tempcode('PRIORITY_' . strval($i)))); } $fields->attach(form_input_list(do_lang_tempcode('PRIORITY'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_PRIORITY'), 'priority', $l)); // Where to send to $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('CHOOSE_SEND_TO')))); $newsletters = $GLOBALS['SITE_DB']->query_select('newsletters', array('*')); foreach ($newsletters as $newsletter) { $level = post_param_integer(strval($newsletter['id']), post_param_integer('level', -1)); $c4 = $this->count_level($newsletter['id'], 4, $lang); $c3 = $this->count_level($newsletter['id'], 3, $lang); $c2 = $this->count_level($newsletter['id'], 2, $lang); $c1 = $this->count_level($newsletter['id'], 1, $lang); if ($c1 != 0) { $newsletter_title = get_translated_text($newsletter['title']); $newsletter_description = get_translated_text($newsletter['description']); if ($c1 == $c2 && $c1 == $c3 && $c1 == $c4) { $fields->attach(form_input_tick(do_lang_tempcode('NEWSLETTER_PREFIX', escape_html($newsletter_title)), do_lang_tempcode('DESCRIPTION_NOSUBSCRIPTION_LEVEL', escape_html(integer_format($c4)), escape_html($newsletter_description)), strval($newsletter['id']), $level >= 1, NULL, '4')); } else { $l = new ocp_tempcode(); $l->attach(form_input_list_entry('0', $level == 0, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_0_ALT'), do_lang_tempcode('NUM_READERS', integer_format(0))))); $l->attach(form_input_list_entry('1', $level == 1, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_1'), do_lang_tempcode('NUM_READERS', integer_format($c1))))); $l->attach(form_input_list_entry('2', $level == 2, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_2'), do_lang_tempcode('NUM_READERS', integer_format($c2))))); $l->attach(form_input_list_entry('3', $level == 3, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_3'), do_lang_tempcode('NUM_READERS', integer_format($c3))))); $l->attach(form_input_list_entry('4', $level == 4, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_4'), do_lang_tempcode('NUM_READERS', integer_format($c4))))); $fields->attach(form_input_list(do_lang_tempcode('SUBSCRIPTION_LEVEL_FOR', escape_html($newsletter_title)), do_lang_tempcode('DESCRIPTION_SUBSCRIPTION_LEVEL', escape_html($newsletter_description)), strval($newsletter['id']), $l)); } } } if (get_forum_type() == 'ocf') { $c5 = $this->count_level(-1, 5, $lang); $fields->attach(form_input_tick(do_lang_tempcode('NEWSLETTER_OCF'), do_lang_tempcode('NUM_READERS', integer_format($c5)), '-1', false)); $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(); foreach ($groups as $group_id => $group) { if ($group_id != db_get_first_id()) { $map = array(); $map['g' . strval($group_id)] = 1; $_c = newsletter_who_send_to($map, $lang, 0, 0); $c6 = $_c[6]['g' . strval($group_id)]; if ($c6 != 0) { $fields->attach(form_input_tick(do_lang_tempcode('THIS_WITH', do_lang_tempcode('GROUP'), make_string_tempcode(escape_html($group))), do_lang_tempcode('NUM_READERS', integer_format($c6)), 'g' . strval($group_id), post_param_integer('g' . strval($group_id), 0) == 1)); } } } } $fields->attach(form_input_upload(do_lang_tempcode('UPLOAD'), do_lang_tempcode('DESCRIPTION_UPLOAD_CSV'), 'file', false, NULL, NULL, true, 'csv,txt')); //if ($fields->is_empty()) inform_exit(do_lang_tempcode('NOBODY_TO_SEND_TO')); handle_max_file_size($hidden); $template_choices = new ocp_tempcode(); $dh = opendir(get_custom_file_base() . '/themes/default/templates_custom'); while (($f = readdir($dh)) !== false) { if (preg_match('#^MAIL.*\\.tpl$#', $f) != 0) { $tpl = basename($f, '.tpl'); $template_choices->attach(form_input_list_entry($tpl, post_param('template', 'MAIL') == $tpl, $tpl)); } } if (!file_exists(get_custom_file_base() . '/themes/default/templates_custom/MAIL.tpl')) { $template_choices->attach(form_input_list_entry('MAIL', true, 'MAIL')); } closedir($dh); $fields->attach(form_input_list(do_lang_tempcode('NEWSLETTER_TEMPLATE'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_TEMPLATE'), 'template', $template_choices, NULL, false, true)); // If we're making a periodic newsletter then we need to know when it // should be sent if ($periodic_action == 'make' || $periodic_action == 'replace') { $hidden->attach(form_input_hidden('make_periodic', '1')); $hidden->attach(form_input_hidden('periodic_choice', post_param('periodic_choice'))); $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang('PERIODIC_WHEN'), 'HELP' => do_lang('PERIODIC_WHEN_HELP')))); // The choices are given as radio buttons: weekly or bi-weekly or monthly? // In the labels for these radio buttons, we put a dropdown for day of // the week and day of the month. $frequency = post_param('periodic_when', 'weekly'); if (!is_null($defaults)) { $frequency = post_param('periodic_when', $defaults['np_frequency']); } $current_day_weekly = post_param_integer('periodic_weekly', 5); if (!is_null($defaults)) { $current_day_weekly = post_param_integer('periodic_weekly', $defaults['np_day']); } $current_day_biweekly = post_param_integer('periodic_biweekly', 5); if (!is_null($defaults)) { $current_day_biweekly = post_param_integer('periodic_biweekly', $defaults['np_day']); } $current_day_of_month = post_param_integer('periodic_monthly', 1); if (!is_null($defaults)) { $current_day_of_month = post_param_integer('periodic_monthly', $defaults['np_day']); } $radios = new ocp_tempcode(); $week_days_weekly = new ocp_tempcode(); $week_days_biweekly = new ocp_tempcode(); require_lang('dates'); $week_days = array(1 => do_lang('MONDAY'), 2 => do_lang('TUESDAY'), 3 => do_lang('WEDNESDAY'), 4 => do_lang('THURSDAY'), 5 => do_lang('FRIDAY'), 6 => do_lang('SATURDAY'), 7 => do_lang('SUNDAY')); foreach ($week_days as $i => $this_day) { $week_days_weekly->attach(form_input_list_entry(strval($i), $i == $current_day_weekly, $this_day, false, false)); $week_days_biweekly->attach(form_input_list_entry(strval($i), $i == $current_day_biweekly, $this_day, false, false)); } $weekly_desc = new ocp_tempcode(); $weekly_desc->attach(do_lang('PERIODIC_WEEKLY_ON')); $weekly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_weekday_weekly', 'CONTENT' => $week_days_weekly, 'INLINE_LIST' => '0'))); $radios->attach(form_input_radio_entry('periodic_when', 'weekly', $frequency == 'weekly', $weekly_desc, NULL, '')); $weekly_desc = new ocp_tempcode(); $weekly_desc->attach(do_lang('PERIODIC_BIWEEKLY_ON')); $weekly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_weekday_biweekly', 'CONTENT' => $week_days_biweekly, 'INLINE_LIST' => '0'))); $radios->attach(form_input_radio_entry('periodic_when', 'biweekly', $frequency == 'biweekly', $weekly_desc, NULL, '')); $month_days = new ocp_tempcode(); foreach (range(1, 28) as $this_day) { $suffix = gmdate('S', gmmktime(0, 0, 0, 1, $this_day, 1990)); $month_days->attach(form_input_list_entry(strval($this_day), $this_day == 1, strval($this_day) . $suffix, $current_day_of_month == $this_day)); } $monthly_desc = new ocp_tempcode(); $monthly_desc->attach(do_lang('PERIODIC_MONTHLY_ON')); $monthly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_monthly', 'CONTENT' => $month_days, 'INLINE_LIST' => '0'))); $radios->attach(form_input_radio_entry('periodic_when', 'monthly', $frequency == 'monthly', $monthly_desc, NULL, '')); $fields->attach(form_input_radio(do_lang('PERIODIC_WHEN_CHOICE'), '', 'periodic_when', $radios, true)); $radios = new ocp_tempcode(); $radios->attach(form_input_radio_entry('periodic_for', 'all', false, do_lang_tempcode('CREATE_PERIODIC_FOR_ALL'), NULL, '')); $radios->attach(form_input_radio_entry('periodic_for', 'future', true, do_lang_tempcode('CREATE_PERIODIC_FOR_FUTURE'), NULL, '')); $fields->attach(form_input_radio(do_lang('CREATE_PERIODIC_FOR'), '', 'periodic_for', $radios, true)); } return do_template('FORM_SCREEN', array('_GUID' => '0b2a4825ec586d9ff557026d9a1e0cca', 'TITLE' => $title, 'TEXT' => $periodic_action == 'make' || $periodic_action == 'replace' ? do_lang_tempcode('PERIODIC_NO_EDIT') : do_lang_tempcode('NEWSLETTER_SEND_TEXT'), 'HIDDEN' => $hidden, 'FIELDS' => $fields->evaluate(), 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url)); }
/** * Get the tempcode for a comcode-enabled text input (textarea). * * @param mixed A human intelligible name for this input field * @param mixed A description for this input field * @param ID_TEXT The name which this input field is for * @param string The default value for this input field * @param boolean Whether this is a required input field * @param ?integer The tab index of the field (NULL: not specified) * @param boolean Force non-WYSIWYG and non default-Comcode parsing * @param mixed A secondary side description for this input field * @param ?tempcode The parsed Comcode. (NULL: calculate) * @param boolean Whether the field scrolls * @return tempcode The input field */ function form_input_text_comcode($pretty_name, $description, $name, $default, $required, $tabindex = NULL, $force_non_wysiwyg = false, $description_side = '', $default_parsed = NULL, $scrolls = false) { if (browser_matches('wysiwyg') && !$force_non_wysiwyg && strpos($default, '{$,page hint: no_wysiwyg}') === false) { return form_input_huge_comcode($pretty_name, $description, $name, $default, $required, $tabindex, 10, $description_side, $default_parsed, $scrolls); } require_lang('comcode'); require_javascript('javascript_editing'); require_javascript('javascript_ajax'); $tabindex = get_form_field_tabindex($tabindex); $_required = $required ? '_required' : ''; $default_parsed = new ocp_tempcode(); $default = filter_form_field_default($name, $default); if (!$force_non_wysiwyg) { global $JAVASCRIPT, $WYSIWYG_ATTACHED; if (!$WYSIWYG_ATTACHED) { $JAVASCRIPT->attach(do_template('HTML_EDIT')); } $WYSIWYG_ATTACHED = true; @header('Content-type: text/html; charset=' . get_charset()); $w = browser_matches('wysiwyg') && !browser_matches('no_multi_wysiwyg') && has_js() && strpos($default, '{$,page hint: no_wysiwyg}') === false; if ($w) { $_required .= ' wysiwyg'; } global $LAX_COMCODE; $temp = $LAX_COMCODE; $LAX_COMCODE = true; $GLOBALS['COMCODE_PARSE_URLS_CHECKED'] = 100; // Little hack to stop it checking any URLs /*if (is_null($default_parsed)) */ $default_parsed = @comcode_to_tempcode($default, NULL, false, 60, NULL, NULL, true); $LAX_COMCODE = $temp; } else { $w = false; $default_parsed = new ocp_tempcode(); } $input = do_template('FORM_SCREEN_INPUT_TEXT', array('_GUID' => 'ff53196e943e7b19bc72fc3bbb3238b5', 'SCROLLS' => $scrolls, 'ROWS' => is_object($description_side) || $description_side != '' ? '16' : '8', 'TABINDEX' => strval($tabindex), 'REQUIRED' => $_required, 'NAME' => $name, 'DEFAULT' => $default, 'DEFAULT_PARSED' => $default_parsed)); return _form_input($name, $pretty_name, $description, $input, $required, true, $tabindex, $w, false, $description_side); }