/**
  * 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));
 }
Beispiel #2
0
 /**
  * Get tempcode for a news adding/editing form.
  *
  * @param  ?AUTO_LINK		The primary category for the news (NULL: personal)
  * @param  ?array				A list of categories the news is in (NULL: not known)
  * @param  SHORT_TEXT		The news title
  * @param  LONG_TEXT			The news summary
  * @param  SHORT_TEXT		The name of the author
  * @param  BINARY				Whether the news is validated
  * @param  ?BINARY			Whether rating is allowed (NULL: decide statistically, based on existing choices)
  * @param  ?SHORT_INTEGER	Whether comments are allowed (0=no, 1=yes, 2=review style) (NULL: decide statistically, based on existing choices)
  * @param  ?BINARY			Whether trackbacks are allowed (NULL: decide statistically, based on existing choices)
  * @param  BINARY				Whether to show the "send trackback" field
  * @param  LONG_TEXT			Notes for the video
  * @param  URLPATH			URL to the image for the news entry (blank: use cat image)
  * @param  ?array				Scheduled go-live time (NULL: N/A)
  * @return array				A tuple of lots of info (fields, hidden fields, trailing fields)
  */
 function get_form_fields($main_news_category = NULL, $news_category = NULL, $title = '', $news = '', $author = '', $validated = 1, $allow_rating = NULL, $allow_comments = NULL, $allow_trackbacks = NULL, $send_trackbacks = 1, $notes = '', $image = '', $scheduled = NULL)
 {
     list($allow_rating, $allow_comments, $allow_trackbacks) = $this->choose_feedback_fields_statistically($allow_rating, $allow_comments, $allow_trackbacks);
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'validated';
     if (is_null($main_news_category)) {
         $NON_CANONICAL_PARAMS[] = 'cat';
         $param_cat = get_param('cat', '');
         if ($param_cat == '') {
             $news_category = array();
             $main_news_category = NULL;
         } elseif (strpos($param_cat, ',') === false) {
             $news_category = array();
             $main_news_category = intval($param_cat);
         } else {
             require_code('ocfiltering');
             $news_category = ocfilter_to_idlist_using_db($param_cat, 'id', 'news_categories', 'news_categories', NULL, 'id', 'id');
             $main_news_category = NULL;
         }
         $author = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
     }
     $cats1 = nice_get_news_categories($main_news_category, false, true, false, true);
     $cats2 = nice_get_news_categories(is_null($news_category) || count($news_category) == 0 ? array(get_param_integer('cat', NULL)) : $news_category, false, true, true, false);
     $fields = new ocp_tempcode();
     $fields2 = new ocp_tempcode();
     $hidden = new ocp_tempcode();
     require_code('form_templates');
     $fields->attach(form_input_line_comcode(do_lang_tempcode('TITLE'), do_lang_tempcode('DESCRIPTION_TITLE'), 'title', $title, true));
     if ($validated == 0) {
         $validated = get_param_integer('validated', 0);
         if ($validated == 1) {
             attach_message(do_lang_tempcode('WILL_BE_VALIDATED_WHEN_SAVING'));
         }
     }
     if (has_some_cat_specific_permission(get_member(), 'bypass_validation_' . $this->permissions_require . 'range_content', 'cms_news', $this->permissions_cat_require)) {
         if (addon_installed('unvalidated')) {
             $fields2->attach(form_input_tick(do_lang_tempcode('VALIDATED'), do_lang_tempcode('DESCRIPTION_VALIDATED'), 'validated', $validated == 1));
         }
     }
     if ($cats1->is_empty()) {
         warn_exit(do_lang_tempcode('NO_CATEGORIES'));
     }
     if (addon_installed('authors')) {
         $hidden->attach(form_input_hidden('author', $author));
     }
     $fields2->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => (is_null($news_category) || count($news_category) == 0) && $image == '' && (is_null($news_category) || $news_category == array()), 'TITLE' => do_lang_tempcode('ADVANCED'))));
     $fields2->attach(form_input_text_comcode(do_lang_tempcode('BLOG_NEWS_SUMMARY'), do_lang_tempcode('DESCRIPTION_NEWS_SUMMARY'), 'news', $news, false));
     if (get_value('disable_secondary_news') !== '1') {
         $fields2->attach(form_input_list(do_lang_tempcode('MAIN_CATEGORY'), do_lang_tempcode('DESCRIPTION_MAIN_CATEGORY'), 'main_news_category', $cats1));
     } else {
         $fields2->attach(form_input_hidden('main_news_category', is_null($main_news_category) ? 'personal' : strval($main_news_category)));
     }
     if (get_value('disable_secondary_news') !== '1') {
         $fields2->attach(form_input_multi_list(do_lang_tempcode('SECONDARY_CATEGORIES'), do_lang_tempcode('DESCRIPTION_SECONDARY_CATEGORIES'), 'news_category', $cats2));
     }
     $fields2->attach(form_input_upload(do_lang_tempcode('IMAGE'), do_lang_tempcode('DESCRIPTION_NEWS_IMAGE_OVERRIDE'), 'file', false, $image, NULL, true, str_replace(' ', '', get_option('valid_images'))));
     //handle_max_file_size($hidden,'image'); Attachments will add this
     if (addon_installed('calendar') && has_specific_permission(get_member(), 'scheduled_publication_times')) {
         $fields2->attach(form_input_date__scheduler(do_lang_tempcode('PUBLICATION_TIME'), do_lang_tempcode('DESCRIPTION_PUBLICATION_TIME'), 'schedule', true, true, true, $scheduled, intval(date('Y')) - 1970 + 2, 1970));
     }
     require_code('feedback2');
     $fields2->attach(feedback_fields($allow_rating == 1, $allow_comments == 1, $allow_trackbacks == 1, $send_trackbacks == 1, $notes, $allow_comments == 2));
     $fields2->attach(get_syndication_option_fields());
     return array($fields, $hidden, NULL, NULL, NULL, NULL, make_string_tempcode($fields2->evaluate()));
 }
Beispiel #3
0
 /**
  * The UI to make a post.
  *
  * @return tempcode		The UI
  */
 function new_post()
 {
     require_code('ocf_posts2');
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'quote';
     $NON_CANONICAL_PARAMS[] = 'intended_solely_for';
     $topic_id = get_param_integer('id');
     $parent_id = either_param_integer('parent_id', NULL);
     $intended_solely_for = get_param_integer('intended_solely_for', -1);
     $post = post_param('post', NULL);
     // Copy existing post into box (from quick reply 'more options' button)
     if (is_null($post)) {
         $quotes = array();
         $quote = get_param_integer('quote', -1);
         if ($quote == -1) {
             $quotes = $this->get_markers();
         } else {
             $quotes[] = $quote;
         }
         $post = $this->attach_quotes($quotes);
     }
     $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('*'), array('id' => $topic_id), '', 1);
     if (!array_key_exists(0, $topic_info)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $forum_id = $topic_info[0]['t_forum_id'];
     $topic_title = $topic_info[0]['t_cache_first_title'];
     if ($topic_title == '') {
         $topic_title = $GLOBALS['FORUM_DB']->query_value_null_ok('f_posts', 'p_title', array('p_topic_id' => $topic_id));
     }
     if (is_null($topic_title)) {
         $topic_title = '';
     }
     if (!is_null($forum_id)) {
         if (!has_category_access(get_member(), 'forums', strval($forum_id))) {
             access_denied('CATEGORY_ACCESS');
         }
         // Can happen if trying to reply to a stated whisper made to you in a forum you don't have access to
     } else {
         // It must be a Private Topic. Do we have access?
         $from = $topic_info[0]['t_pt_from'];
         $to = $topic_info[0]['t_pt_to'];
         if ($from != get_member() && $to != get_member() && !ocf_has_special_pt_access($topic_id) && !has_specific_permission(get_member(), 'view_other_pt')) {
             access_denied('SPECIFIC_PERMISSION', 'view_other_pt');
         }
     }
     $this->handle_topic_breadcrumbs($forum_id, $topic_id, $topic_title, do_lang_tempcode('ADD_POST'));
     if ($topic_info[0]['t_is_open'] == 0) {
         $may_moderate_forum = ocf_may_moderate_forum($forum_id);
         if (!$may_moderate_forum) {
             warn_exit(do_lang_tempcode('TOPIC_IS_CLOSED'));
         }
     }
     $hidden_fields = new ocp_tempcode();
     $hidden_fields->attach(form_input_hidden('topic_id', strval($topic_id)));
     $hidden_fields->attach(form_input_hidden('from_url', get_self_url(true, false, array('type' => get_param('type', 'misc')))));
     $map = array('page' => '_SELF', 'type' => '_add_reply', 'parent_id' => $parent_id);
     $test = get_param_integer('kfs' . (is_null($forum_id) ? '' : strval($forum_id)), -1);
     if ($test != -1 && $test != 0) {
         $map['kfs' . (is_null($forum_id) ? '' : strval($forum_id))] = $test;
     }
     $test = get_param_integer('threaded', -1);
     if ($test != -1) {
         $map['threaded'] = $test;
     }
     $post_url = build_url($map, '_SELF');
     // Certain aspects relating to the posting system
     $specialisation = new ocp_tempcode();
     if (get_option('is_on_post_titles') == '1') {
         $specialisation->attach(form_input_line(do_lang_tempcode('TITLE'), '', 'title', post_param('title', ''), false, 1));
     }
     if (ocf_may_moderate_forum($forum_id, get_member())) {
         $moderation_options = array(array(do_lang_tempcode('EMPHASISED'), 'is_emphasised', false, do_lang_tempcode('DESCRIPTION_EMPHASISED')));
         if (addon_installed('unvalidated')) {
             $moderation_options[] = array(do_lang_tempcode('VALIDATED'), 'validated', true, do_lang_tempcode('DESCRIPTION_VALIDATED'));
         }
         //if ($intended_solely_for==-1) $moderation_options[]=array(do_lang_tempcode('CASCADING'),'cascading',false,do_lang_tempcode('DESCRIPTION_CASCADING'));
     } else {
         $moderation_options = array();
         $hidden_fields->attach(form_input_hidden('validated', '1'));
     }
     $options = array();
     if (!is_guest()) {
         if (get_value('disable_skip_sig') !== '1') {
             if (addon_installed('ocf_signatures')) {
                 $options[] = array(do_lang_tempcode('SKIP_SIGNATURE'), 'skip_sig', false, do_lang_tempcode('DESCRIPTION_SKIP_SIGNATURE'));
             }
         }
         if (get_option('is_on_anonymous_posts') == '1') {
             $options[] = array(do_lang_tempcode('_MAKE_ANONYMOUS_POST'), 'anonymous', false, do_lang_tempcode('MAKE_ANONYMOUS_POST_DESCRIPTION'));
         }
     }
     $specialisation2 = form_input_various_ticks($options, '');
     if (count($moderation_options) != 0) {
         $specialisation2->attach(form_input_various_ticks($moderation_options, '', NULL, do_lang_tempcode('MODERATION_OPTIONS')));
     }
     if (!is_null($forum_id)) {
         $post_templates = $this->post_templates($forum_id);
         $specialisation->attach($post_templates[0]);
         if (is_object($post) && $post->is_empty() || $post === '') {
             $post = $post_templates[1];
         }
     }
     $_intended_solely_for = '';
     if ($intended_solely_for != -1) {
         $_intended_solely_for = $GLOBALS['FORUM_DRIVER']->get_username($intended_solely_for);
         if (is_null($_intended_solely_for)) {
             $_intended_solely_for = '';
         }
     }
     if (ocf_may_make_personal_topic()) {
         if ($_intended_solely_for != '' || get_value('no_inline_pp_advertise') !== '1') {
             $specialisation->attach(form_input_username(do_lang_tempcode('WHISPER'), do_lang_tempcode('DESCRIPTION_WHISPER'), 'intended_solely_for', $_intended_solely_for, false));
         }
     }
     if (is_guest()) {
         $specialisation->attach(form_input_line(do_lang_tempcode('GUEST_NAME'), '', 'poster_name_if_guest', do_lang('GUEST'), true));
     }
     require_code('fields');
     if (has_tied_catalogue('post')) {
         append_form_custom_fields('post', NULL, $specialisation, $hidden_fields);
     }
     $text = new ocp_tempcode();
     if (addon_installed('captcha')) {
         require_code('captcha');
         if (use_captcha()) {
             $specialisation->attach(form_input_captcha());
             $text->attach(paragraph(do_lang_tempcode('FORM_TIME_SECURITY')));
         }
     }
     if (addon_installed('points')) {
         $login_url = build_url(array('page' => 'login', 'type' => 'misc', 'redirect' => get_self_url(true, true)), get_module_zone('login'));
         $_login_url = escape_html($login_url->evaluate());
         if (is_guest() && (get_forum_type() != 'ocf' || has_actual_page_access(get_member(), 'join'))) {
             $text->attach(paragraph(do_lang_tempcode('NOT_LOGGED_IN_NO_CREDIT', $_login_url)));
         }
     }
     if (!is_null($forum_id) && !has_specific_permission(get_member(), 'bypass_validation_lowrange_content', 'topics', array('forums', $forum_id))) {
         $text->attach(paragraph(do_lang_tempcode('WILL_NEED_VALIDATING')));
     }
     // Awards?
     if (addon_installed('awards')) {
         require_code('awards');
         $specialisation->attach(get_award_fields('post'));
     }
     // Moderator reply
     if (ocf_may_moderate_forum($forum_id, get_member())) {
         require_code('ocf_forums2');
         $specialisation2->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => true, 'TITLE' => do_lang_tempcode('TOPIC_MODERATION'))));
         $specialisation2->attach(form_input_line(do_lang_tempcode('TITLE'), '', 'new_title', $topic_title, false));
         $specialisation2->attach(form_input_tree_list(do_lang_tempcode('DESTINATION_FORUM'), do_lang_tempcode('DESCRIPTION_DESTINATION_FORUM'), 'to', NULL, 'choose_forum', array(), false, is_null($forum_id) ? '' : strval($forum_id)));
         $options = array(array(do_lang_tempcode('OPEN'), 'open', $topic_info[0]['t_is_open'] == 1, do_lang_tempcode('DESCRIPTION_OPEN')), array(do_lang_tempcode('PINNED'), 'pinned', $topic_info[0]['t_pinned'] == 1, do_lang_tempcode('DESCRIPTION_PINNED')));
         if (addon_installed('unvalidated')) {
             if ($topic_info[0]['t_validated'] == 0) {
                 $topic_info[0]['t_validated'] = get_param_integer('validated', 0);
                 if ($topic_info[0]['t_validated'] == 1) {
                     attach_message(do_lang_tempcode('WILL_BE_VALIDATED_WHEN_SAVING'));
                 }
             }
             $options[] = array(do_lang_tempcode('VALIDATED'), 'topic_validated', $topic_info[0]['t_validated'] == 1, do_lang_tempcode('DESCRIPTION_VALIDATED'));
         }
         if (get_value('disable_sunk') !== '1') {
             $moderation_options[] = array(do_lang_tempcode('SUNK'), 'sunk', $topic_info[0]['t_sunk'] == 1, do_lang_tempcode('DESCRIPTION_SUNK'));
         }
         if (!is_null($forum_id)) {
             $options[] = array(do_lang_tempcode('CASCADING'), 'cascading', $topic_info[0]['t_cascading'] == 1, do_lang_tempcode('DESCRIPTION_CASCADING'));
         }
         $specialisation2->attach(form_input_various_ticks($options, ''));
         if (addon_installed('calendar')) {
             $specialisation2->attach(form_input_date__scheduler(do_lang_tempcode('OCF_PUBLICATION_TIME'), do_lang_tempcode('OCF_DESCRIPTION_PUBLICATION_TIME'), 'schedule', true, true, true));
         }
     }
     $topic_posts = new ocp_tempcode();
     $posts = $GLOBALS['FORUM_DB']->query('SELECT *,p.id AS id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts p LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND t.id=p.p_post WHERE p_topic_id=' . strval($topic_id) . ' AND (p_intended_solely_for IS NULL OR p_intended_solely_for=' . strval(get_member()) . ' OR p_poster=' . strval(get_member()) . ') AND p_validated=1 ORDER BY p_time DESC,p.id DESC', 20);
     foreach ($posts as $row) {
         $topic_posts->attach(do_template('OCF_POSTING_SCREEN_POST', array('TITLE' => $row['p_title'], 'ID' => strval($row['id']), 'POSTER' => strval($row['p_poster']), 'POST' => ocf_show_isolated_post($row, true))));
     }
     if (!$topic_posts->is_empty()) {
         $topic_posts = do_template('OCF_POSTING_SCREEN_POSTS', array('_GUID' => '3d3b14cf3a48b2a16eed5b1bd92b1187', 'POSTS' => $topic_posts));
     }
     if (is_object($post)) {
         $post = $post->evaluate();
     }
     $posting_form = get_posting_form(do_lang('ADD_POST'), $post, $post_url, $hidden_fields, $specialisation, NULL, $topic_posts->evaluate(), $specialisation2, NULL, $this->_post_javascript());
     $title = get_page_title('_ADD_POST', true, array(escape_html($topic_title)));
     if (post_param_integer('add_poll', 0) == 1) {
         // Show it worked / Refresh
         $url = build_url(array('page' => '_SELF', 'type' => 'add_poll'), '_SELF');
         return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
     }
     return do_template('POSTING_SCREEN', array('_GUID' => 'ca2eab9a9ffdab267a48eb7be48ccdc0', 'TEXT' => $text, 'TITLE' => $title, 'POSTING_FORM' => $posting_form));
 }
Beispiel #4
0
 /**
  * The UI to do a backup.
  *
  * @return tempcode		The UI
  */
 function backup_interface()
 {
     $title = get_page_title('BACKUP');
     require_javascript('javascript_ajax');
     $last_backup = intval(get_value('last_backup'));
     if ($last_backup == 0) {
         $text = do_lang_tempcode('NO_LAST_BACKUP');
     } elseif (date('Y/m/d', utctime_to_usertime($last_backup)) == date('Y/m/d', utctime_to_usertime())) {
         $text = do_lang_tempcode('LAST_BACKUP_TODAY');
     } elseif (date('Y/m/d', utctime_to_usertime($last_backup)) == date('Y/m/d', utctime_to_usertime(time() - 60 * 60 * 24))) {
         $text = do_lang_tempcode('LAST_BACKUP_YESTERDAY');
     } else {
         $text = do_lang_tempcode('LAST_BACKUP', integer_format(intval(round((time() - $last_backup) / (60 * 60 * 24)))));
     }
     $url = build_url(array('page' => '_SELF', 'type' => 'make_backup'), '_SELF');
     $max_size = intval(get_value('backup_max_size'));
     if ($max_size == 0) {
         $max_size = 100;
     }
     require_code('form_templates');
     $content = new ocp_tempcode();
     $content->attach(form_input_radio_entry('b_type', 'full', true, do_lang_tempcode('FULL_BACKUP')));
     $content->attach(form_input_radio_entry('b_type', 'incremental', false, do_lang_tempcode('INCREMENTAL_BACKUP')));
     $content->attach(form_input_radio_entry('b_type', 'sql', false, do_lang_tempcode('SQL_BACKUP')));
     $fields = form_input_radio(do_lang_tempcode('TYPE'), do_lang_tempcode('BACKUP_TYPE'), 'b_type', $content);
     $fields->attach(form_input_integer(do_lang_tempcode('MAXIMUM_SIZE_INCLUSION'), do_lang_tempcode('MAX_FILE_SIZE'), 'max_size', $max_size, false));
     if (addon_installed('calendar')) {
         $fields->attach(form_input_date__scheduler(do_lang_tempcode('SCHEDULE_TIME'), do_lang_tempcode('DESCRIPTION_SCHEDULE_TIME'), 'schedule', true, true, true));
         $_recurrence_days = get_value('backup_recurrance_days');
         $recurrance_days = is_null($_recurrence_days) ? NULL : intval($_recurrence_days);
         if (cron_installed()) {
             $fields->attach(form_input_integer(do_lang_tempcode('RECURRANCE_DAYS'), do_lang_tempcode('DESCRIPTION_RECURRANCE_DAYS'), 'recurrance_days', $recurrance_days, false));
         }
     }
     $javascript = '';
     if (addon_installed('calendar')) {
         if (cron_installed()) {
             $javascript = 'var d_ob=[document.getElementById(\'schedule_day\'),document.getElementById(\'schedule_month\'),document.getElementById(\'schedule_year\'),document.getElementById(\'schedule_hour\'),document.getElementById(\'schedule_minute\')]; var hide_func=function () { document.getElementById(\'recurrance_days\').disabled=((d_ob[0].selectedIndex+d_ob[1].selectedIndex+d_ob[2].selectedIndex+d_ob[3].selectedIndex+d_ob[4].selectedIndex)>0); }; d_ob[0].onchange=hide_func; d_ob[1].onchange=hide_func; d_ob[2].onchange=hide_func; d_ob[3].onchange=hide_func; d_ob[4].onchange=hide_func; hide_func();';
         }
     }
     $form = do_template('FORM', array('_GUID' => '64ae569b2cce398e89d1b4167f116193', 'HIDDEN' => '', 'JAVASCRIPT' => $javascript, 'TEXT' => '', 'FIELDS' => $fields, 'SUBMIT_NAME' => do_lang_tempcode('BACKUP'), 'URL' => $url));
     $results = $this->get_results();
     return do_template('BACKUP_LAUNCH_SCREEN', array('_GUID' => '26a82a0627632db79b35055598de5d23', 'TITLE' => $title, 'TEXT' => $text, 'RESULTS' => $results, 'FORM' => $form));
 }