Esempio n. 1
0
 /**
  * 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));
 }
Esempio n. 2
0
/**
 * Find whether a particular kind of notification is available.
 *
 * @param  integer		The notification setting
 * @param  ?MEMBER		Member to check for (NULL: just check globally)
 * @return boolean		Whether it is available
 */
function _notification_setting_available($setting, $member_id = NULL)
{
    static $nsa_cache = array();
    if (isset($nsa_cache[$setting][$member_id])) {
        return $nsa_cache[$setting][$member_id];
    }
    $system_wide = false;
    $for_member = false;
    switch ($setting) {
        case A_INSTANT_EMAIL:
            $system_wide = true;
            if ($system_wide && !is_null($member_id)) {
                $for_member = $GLOBALS['FORUM_DRIVER']->get_member_email_address($member_id) != '';
            }
            break;
        case A_DAILY_EMAIL_DIGEST:
        case A_WEEKLY_EMAIL_DIGEST:
        case A_MONTHLY_EMAIL_DIGEST:
            $system_wide = cron_installed();
            if ($system_wide && !is_null($member_id)) {
                $for_member = $GLOBALS['FORUM_DRIVER']->get_member_email_address($member_id) != '';
            }
            break;
        case A_INSTANT_SMS:
            $system_wide = addon_installed('sms') && get_option('sms_api_id') != '';
            if ($system_wide && !is_null($member_id)) {
                require_code('permissions');
                if (has_specific_permission($member_id, 'use_sms')) {
                    require_code('sms');
                    $cpf_values = $GLOBALS['FORUM_DRIVER']->get_custom_fields($member_id);
                    if (!is_null($cpf_values)) {
                        if (array_key_exists('mobile_phone_number', $cpf_values)) {
                            $for_member = cleanup_mobile_number($cpf_values['mobile_phone_number']) != '';
                        }
                    }
                }
            }
            break;
        case A_INSTANT_PT:
            $system_wide = get_forum_type() == 'ocf' && addon_installed('ocf_forum');
            if ($system_wide && !is_null($member_id)) {
                require_code('permissions');
                $for_member = has_specific_permission($member_id, 'use_pt');
            }
            break;
    }
    $ret = $system_wide && (is_null($member_id) || $for_member);
    $nsa_cache[$setting][$member_id] = $ret;
    return $ret;
}
Esempio n. 3
0
/**
 * Attempt to send an e-mail to the specified recipient. The mail will be forwarding to the CC address specified in the options (if there is one, and if not specified not to cc).
 * The mail will be sent in dual HTML/text format, where the text is the unconverted comcode source: if a member does not read HTML mail, they may wish to fallback to reading that.
 *
 * @param  string			The subject of the mail in plain text
 * @param  LONG_TEXT		The message, as Comcode
 * @param  ?array			The destination (recipient) e-mail addresses [array of strings] (NULL: site staff address)
 * @param  ?mixed			The recipient name. Array or string. (NULL: site name)
 * @param  EMAIL			The from address (blank: site staff address)
 * @param  string			The from name (blank: site name)
 * @param  integer		The message priority (1=urgent, 3=normal, 5=low)
 * @range  1 5
 * @param  ?array			An list of attachments (each attachment being a map, path=>filename) (NULL: none)
 * @param  boolean		Whether to NOT CC to the CC address
 * @param  ?MEMBER		Convert comcode->tempcode as this member (a privilege thing: we don't want people being able to use admin rights by default!) (NULL: guest)
 * @param  boolean		Replace above with arbitrary admin
 * @param  boolean		HTML-only
 * @param  boolean		Whether to bypass queueing, because this code is running as a part of the queue management tools
 * @param  ID_TEXT		The template used to show the email
 * @param  boolean		Whether to bypass queueing
 * @return ?tempcode		A full page (not complete XHTML) piece of tempcode to output (NULL: it worked so no tempcode message)
 */
function mail_wrap($subject_tag, $message_raw, $to_email = NULL, $to_name = NULL, $from_email = '', $from_name = '', $priority = 3, $attachments = NULL, $no_cc = false, $as = NULL, $as_admin = false, $in_html = false, $coming_out_of_queue = false, $mail_template = 'MAIL', $bypass_queue = false)
{
    if (get_option('smtp_sockets_use') == '0') {
        return non_overrided__mail_wrap($subject_tag, $message_raw, $to_email, $to_name, $from_email, $from_name, $priority, $attachments, $no_cc, $as, $as_admin, $in_html, $coming_out_of_queue);
    }
    if (running_script('stress_test_loader')) {
        return NULL;
    }
    if (is_null($bypass_queue)) {
        $bypass_queue = $priority < 3 || strpos(serialize($attachments), 'tmpfile') !== false;
    }
    global $EMAIL_ATTACHMENTS;
    $EMAIL_ATTACHMENTS = array();
    require_code('site');
    require_code('mime_types');
    if (is_null($as)) {
        $as = $GLOBALS['FORUM_DRIVER']->get_guest_id();
    }
    if (!$coming_out_of_queue) {
        $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'logged_mail_messages WHERE m_date_and_time<' . strval(time() - 60 * 60 * 24 * 14) . ' AND m_queued=0');
        // Log it all for 2 weeks, then delete
        $through_queue = !$bypass_queue && (get_option('mail_queue_debug') === '1' || get_option('mail_queue') === '1' && cron_installed());
        $GLOBALS['SITE_DB']->query_insert('logged_mail_messages', array('m_subject' => $subject_tag, 'm_message' => $message_raw, 'm_to_email' => serialize($to_email), 'm_to_name' => serialize($to_name), 'm_from_email' => $from_email, 'm_from_name' => $from_name, 'm_priority' => 3, 'm_attachments' => serialize($attachments), 'm_no_cc' => $no_cc ? 1 : 0, 'm_as' => $as, 'm_as_admin' => $as_admin ? 1 : 0, 'm_in_html' => $in_html ? 1 : 0, 'm_date_and_time' => time(), 'm_member_id' => get_member(), 'm_url' => get_self_url(true), 'm_queued' => $through_queue ? 1 : 0, 'm_template' => $mail_template));
        if ($through_queue) {
            return NULL;
        }
    }
    if (count($attachments) == 0) {
        $attachments = NULL;
    }
    global $SENDING_MAIL;
    if ($SENDING_MAIL) {
        return NULL;
    }
    $SENDING_MAIL = true;
    // To and from, and language
    $staff_address = get_option('staff_address');
    if (is_null($to_email)) {
        $to_email = array($staff_address);
    }
    $to_email_new = array();
    foreach ($to_email as $test_address) {
        if ($test_address != '') {
            $to_email_new[] = $test_address;
        }
    }
    $to_email = $to_email_new;
    if ($to_email == array()) {
        $SENDING_MAIL = false;
        return NULL;
    }
    if ($to_email[0] == $staff_address) {
        $lang = get_site_default_lang();
    } else {
        $lang = user_lang();
        if (method_exists($GLOBALS['FORUM_DRIVER'], 'get_member_from_email_address')) {
            $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_email_address($to_email[0]);
            if (!is_null($member_id)) {
                $lang = get_lang($member_id);
            }
        }
    }
    if (is_null($to_name)) {
        if ($to_email[0] == $staff_address) {
            $to_name = get_site_name();
        } else {
            $to_name = '';
        }
    }
    if ($from_email == '') {
        $from_email = get_option('staff_address');
    }
    if ($from_name == '') {
        $from_name = get_site_name();
    }
    $theme = method_exists($GLOBALS['FORUM_DRIVER'], 'get_theme') ? $GLOBALS['FORUM_DRIVER']->get_theme() : 'default';
    if ($theme == 'default') {
        $theme = $GLOBALS['FORUM_DRIVER']->get_theme('');
        // ... So get theme of welcome zone
    }
    // Our subject
    $_subject = do_template('MAIL_SUBJECT', array('_GUID' => '44a57c666bb00f96723256e26aade9e5', 'SUBJECT_TAG' => $subject_tag), $lang, false, NULL, '.tpl', 'templates', $theme);
    $subject = $_subject->evaluate($lang);
    // Note that this is slightly against spec, because characters aren't forced to be printable us-ascii. But it's better we allow this (which works in practice) than risk incompatibility via charset-base64 encoding.
    // Evaluate message. Needs doing early so we know if we have any headers
    // Misc settings
    $website_email = get_option('website_email');
    if ($website_email == '') {
        $website_email = $from_email;
    }
    $cc_address = $no_cc ? '' : get_option("cc_address");
    global $CID_IMG_ATTACHMENT;
    $CID_IMG_ATTACHMENT = array();
    // Decide message
    $GLOBALS['NO_LINK_TITLES'] = true;
    global $LAX_COMCODE;
    $temp = $LAX_COMCODE;
    $LAX_COMCODE = true;
    $html_content = comcode_to_tempcode($message_raw, $as, $as_admin);
    $LAX_COMCODE = $temp;
    $GLOBALS['NO_LINK_TITLES'] = false;
    if (!$in_html) {
        $_html_content = $html_content->evaluate($lang);
        $_html_content = preg_replace('#(keep|for)_session=[\\d\\w]*#', 'filtered=1', $_html_content);
        $message_html = strpos($_html_content, '<html') !== false ? make_string_tempcode($_html_content) : do_template($mail_template, array('_GUID' => 'b23069c20202aa59b7450ebf8d49cde1', 'CSS' => '{CSS}', 'LOGOURL' => get_logo_url(''), 'LANG' => $lang, 'TITLE' => $subject, 'CONTENT' => $_html_content), $lang, false, NULL, '.tpl', 'templates', $theme);
        $css = css_tempcode(true, true, $message_html->evaluate($lang), $theme);
        $_css = $css->evaluate($lang);
        if (get_option('allow_ext_images') != '1') {
            $_css = preg_replace_callback('#url\\(["\']?(http://[^"]*)["\']?\\)#U', '_mail_css_rep_callback', $_css);
        }
        $html_evaluated = $message_html->evaluate($lang);
        $html_evaluated = str_replace('{CSS}', $_css, $html_evaluated);
        // Cleanup the Comcode a bit
        $message_plain = comcode_to_clean_text($message_raw);
    } else {
        $html_evaluated = $message_raw;
    }
    // Character set
    $regexp = '#^[\\x' . dechex(32) . '-\\x' . dechex(126) . ']*$#';
    $charset = preg_match($regexp, $html_evaluated) == 0 ? do_lang('charset', NULL, NULL, NULL, $lang) : 'us-ascii';
    // CID attachments
    if (get_option('allow_ext_images') != '1') {
        $html_evaluated = preg_replace_callback('#<img\\s([^>]*)src="(http://[^"]*)"#U', '_mail_img_rep_callback', $html_evaluated);
        $matches = array();
        foreach (array('#<([^"<>]*\\s)style="([^"]*)"#', '#<style( [^<>]*)?' . '>(.*)</style>#Us') as $over) {
            $num_matches = preg_match_all($over, $html_evaluated, $matches);
            for ($i = 0; $i < $num_matches; $i++) {
                $altered_inner = preg_replace_callback('#url\\(["\']?(http://[^"]*)["\']?\\)#U', '_mail_css_rep_callback', $matches[2][$i]);
                if ($matches[2][$i] != $altered_inner) {
                    $altered_outer = str_replace($matches[2][$i], $altered_inner, $matches[0][$i]);
                    $html_evaluated = str_replace($matches[0][$i], $altered_outer, $html_evaluated);
                }
            }
        }
    }
    $cid_attachments = array();
    foreach ($CID_IMG_ATTACHMENT as $id => $img) {
        $file_path_stub = convert_url_to_path($img);
        $mime_type = get_mime_type(get_file_extension($img));
        $filename = basename($img);
        if (!is_null($file_path_stub)) {
            $cid_attachment = array('mime' => $mime_type, 'filename' => $filename, 'path' => $file_path_stub, 'temp' => false, 'cid' => $id);
        } else {
            $myfile = ocp_tempnam('email_attachment');
            http_download_file($img, NULL, false, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $myfile);
            if (!is_null($GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'])) {
                $mime_type = $GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'];
            }
            if (!is_null($GLOBALS['HTTP_FILENAME'])) {
                $filename = $GLOBALS['HTTP_FILENAME'];
            }
            $cid_attachment = array('mime' => $mime_type, 'filename' => $filename, 'path' => $myfile, 'temp' => true, 'cid' => $id);
        }
        $cid_attachments[] = $cid_attachment;
    }
    // Attachments
    $real_attachments = array();
    $attachments = array_merge(is_null($attachments) ? array() : $attachments, $EMAIL_ATTACHMENTS);
    if (!is_null($attachments)) {
        foreach ($attachments as $path => $filename) {
            $mime_type = get_mime_type(get_file_extension($filename));
            if (strpos($path, '://') === false) {
                $real_attachment = array('mime' => $mime_type, 'filename' => $filename, 'path' => $path, 'temp' => false);
            } else {
                $myfile = ocp_tempnam('email_attachment');
                http_download_file($path, NULL, false, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $myfile);
                if (!is_null($GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'])) {
                    $mime_type = $GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'];
                }
                if (!is_null($GLOBALS['HTTP_FILENAME'])) {
                    $filename = $GLOBALS['HTTP_FILENAME'];
                }
                $real_attachment = array('mime' => $mime_type, 'filename' => $filename, 'path' => $myfile, 'temp' => true);
            }
            $real_attachments[] = $real_attachment;
        }
    }
    // ==========================
    // Interface with SwiftMailer
    // ==========================
    require_code('Swift-4.1.1/lib/swift_required');
    // Read in SMTP settings
    $host = get_option('smtp_sockets_host');
    $port = intval(get_option('smtp_sockets_port'));
    $username = get_option('smtp_sockets_username');
    $password = get_option('smtp_sockets_password');
    $smtp_from_address = get_option('smtp_from_address');
    if ($smtp_from_address != '') {
        $from_email = $smtp_from_address;
    }
    // Create the Transport
    $transport = Swift_SmtpTransport::newInstance($host, $port)->setUsername($username)->setPassword($password);
    if ($port == 419 || $port == 465 || $port == 587) {
        $transport->setEncryption('tls');
    }
    // Create the Mailer using your created Transport
    $mailer = Swift_Mailer::newInstance($transport);
    // Create a message
    $to_array = array();
    if ($to_name === '') {
        foreach ($to_email as $_to_email) {
            $to_array[] = $_to_email;
        }
    } else {
        foreach ($to_email as $i => $_to_email) {
            $to_array[$_to_email] = is_array($to_name) ? $to_name[$i] : $to_name;
        }
    }
    $message = Swift_Message::newInstance($subject)->setFrom(array($website_email => $from_name))->setReplyTo(array($from_email => $from_name))->setTo($to_array)->setPriority($priority)->setCharset($charset)->setBody($html_evaluated, 'text/html', $charset)->addPart($message_plain, 'text/plain', $charset);
    if ($cc_address != '') {
        $message->setCc($cc_address);
    }
    // Attachments
    foreach ($real_attachments as $r) {
        $attachment = Swift_Attachment::fromPath($r['path'], $r['mime'])->setFilename($r['filename'])->setDisposition('attachment');
        $message->attach($attachment);
    }
    foreach ($cid_attachments as $r) {
        $attachment = Swift_Attachment::fromPath($r['path'], $r['mime'])->setFilename($r['filename'])->setDisposition('attachment')->setId($r['cid']);
        $message->attach($attachment);
    }
    // Send the message, and error collection
    $error = '';
    try {
        $result = $mailer->send($message);
    } catch (Exception $e) {
        $error = $e->getMessage();
    }
    if ($error == '' && !$result) {
        $error = 'Unknown error';
    }
    // Attachment cleanup
    foreach ($real_attachments as $r) {
        if ($r['temp']) {
            @unlink($r['path']);
        }
    }
    foreach ($cid_attachments as $r) {
        if ($r['temp']) {
            @unlink($r['path']);
        }
    }
    // Return / Error handling
    $SENDING_MAIL = false;
    if ($error != '') {
        if (get_param_integer('keep_hide_mail_failure', 0) == 0) {
            require_code('site');
            attach_message(!is_null($error) ? make_string_tempcode($error) : do_lang_tempcode('MAIL_FAIL', escape_html(get_option('staff_address'))), 'warn');
        } else {
            return warn_screen(get_page_title('ERROR_OCCURRED'), do_lang_tempcode('MAIL_FAIL', escape_html(get_option('staff_address'))));
        }
    }
    return NULL;
}
 /**
  * The do-next manager for before content management.
  *
  * @return tempcode		The UI
  */
 function misc()
 {
     if (!cron_installed()) {
         attach_message(do_lang_tempcode('CRON_NEEDED_TO_WORK', escape_html(brand_base_url() . '/docs' . strval(ocp_version()) . '/pg/tut_configuration')), 'warn');
     }
     require_code('templates_donext');
     return do_next_manager(get_page_title('WELCOME_EMAILS'), comcode_lang_string('DOC_WELCOME_EMAILS'), array(array('add_one', array('_SELF', array('type' => 'ad'), '_SELF'), do_lang('ADD_WELCOME_EMAIL')), array('edit_one', array('_SELF', array('type' => 'ed'), '_SELF'), do_lang('EDIT_WELCOME_EMAIL'))), do_lang('WELCOME_EMAILS'));
 }
Esempio n. 5
0
/**
 * Attempt to send an e-mail to the specified recipient. The mail will be forwarding to the CC address specified in the options (if there is one, and if not specified not to cc).
 * The mail will be sent in dual HTML/text format, where the text is the unconverted comcode source: if a member does not read HTML mail, they may wish to fallback to reading that.
 *
 * @param  string			The subject of the mail in plain text
 * @param  LONG_TEXT		The message, as Comcode
 * @param  ?array			The destination (recipient) e-mail addresses [array of strings] (NULL: site staff address)
 * @param  ?mixed			The recipient name. Array or string. (NULL: site name)
 * @param  EMAIL			The from address (blank: site staff address)
 * @param  string			The from name (blank: site name)
 * @param  integer		The message priority (1=urgent, 3=normal, 5=low)
 * @range  1 5
 * @param  ?array			An list of attachments (each attachment being a map, path=>filename) (NULL: none)
 * @param  boolean		Whether to NOT CC to the CC address
 * @param  ?MEMBER		Convert comcode->tempcode as this member (a privilege thing: we don't want people being able to use admin rights by default!) (NULL: guest)
 * @param  boolean		Replace above with arbitrary admin
 * @param  boolean		HTML-only
 * @param  boolean		Whether to bypass queueing, because this code is running as a part of the queue management tools
 * @param  ID_TEXT		The template used to show the email
 * @param  boolean		Whether to bypass queueing
 * @return ?tempcode		A full page (not complete XHTML) piece of tempcode to output (NULL: it worked so no tempcode message)
 */
function mail_wrap($subject_tag, $message_raw, $to_email = NULL, $to_name = NULL, $from_email = '', $from_name = '', $priority = 3, $attachments = NULL, $no_cc = false, $as = NULL, $as_admin = false, $in_html = false, $coming_out_of_queue = false, $mail_template = 'MAIL', $bypass_queue = false)
{
    if (running_script('stress_test_loader')) {
        return NULL;
    }
    global $EMAIL_ATTACHMENTS;
    $EMAIL_ATTACHMENTS = array();
    require_code('site');
    require_code('mime_types');
    $bypass_queue = $bypass_queue || $priority < 3 || strpos(serialize($attachments), 'tmpfile') !== false;
    if (is_null($as)) {
        $as = $GLOBALS['FORUM_DRIVER']->get_guest_id();
    }
    if (!$coming_out_of_queue) {
        $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'logged_mail_messages WHERE m_date_and_time<' . strval(time() - 60 * 60 * 24 * 14) . ' AND m_queued=0');
        // Log it all for 2 weeks, then delete
        $through_queue = !$bypass_queue && (get_option('mail_queue_debug') === '1' || get_option('mail_queue') === '1' && cron_installed());
        $GLOBALS['SITE_DB']->query_insert('logged_mail_messages', array('m_subject' => substr($subject_tag, 0, 255), 'm_message' => $message_raw, 'm_to_email' => serialize($to_email), 'm_to_name' => serialize($to_name), 'm_from_email' => $from_email, 'm_from_name' => $from_name, 'm_priority' => $priority, 'm_attachments' => serialize($attachments), 'm_no_cc' => $no_cc ? 1 : 0, 'm_as' => $as, 'm_as_admin' => $as_admin ? 1 : 0, 'm_in_html' => $in_html ? 1 : 0, 'm_date_and_time' => time(), 'm_member_id' => get_member(), 'm_url' => get_self_url(true), 'm_queued' => $through_queue ? 1 : 0, 'm_template' => $mail_template), false, !$through_queue);
        // No errors if we don't NEED this to work
        if ($through_queue) {
            return NULL;
        }
    }
    if (count($attachments) == 0) {
        $attachments = NULL;
    }
    global $SENDING_MAIL;
    if ($SENDING_MAIL) {
        return NULL;
    }
    $SENDING_MAIL = true;
    // To and from, and language
    $staff_address = get_option('staff_address');
    if (is_null($to_email)) {
        $to_email = array($staff_address);
    }
    $to_email_new = array();
    foreach ($to_email as $test_address) {
        if ($test_address != '') {
            $to_email_new[] = $test_address;
        }
    }
    $to_email = $to_email_new;
    if ($to_email == array()) {
        $SENDING_MAIL = false;
        return NULL;
    }
    if ($to_email[0] == $staff_address) {
        $lang = get_site_default_lang();
    } else {
        $lang = user_lang();
        if (method_exists($GLOBALS['FORUM_DRIVER'], 'get_member_from_email_address')) {
            $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_email_address($to_email[0]);
            if (!is_null($member_id)) {
                $lang = get_lang($member_id);
            }
        }
    }
    if (is_null($to_name)) {
        if ($to_email[0] == $staff_address) {
            $to_name = get_site_name();
        } else {
            $to_name = '';
        }
    }
    if ($from_email == '') {
        $from_email = get_option('staff_address');
    }
    if ($from_name == '') {
        $from_name = get_site_name();
    }
    $from_email = str_replace("\r", '', $from_email);
    $from_email = str_replace("\n", '', $from_email);
    $from_name = str_replace("\r", '', $from_name);
    $from_name = str_replace("\n", '', $from_name);
    $theme = method_exists($GLOBALS['FORUM_DRIVER'], 'get_theme') ? $GLOBALS['FORUM_DRIVER']->get_theme() : 'default';
    if ($theme == 'default') {
        $theme = $GLOBALS['FORUM_DRIVER']->get_theme('');
        // ... So get theme of welcome zone
    }
    // Line termination is fiddly. It is safer to rely on sendmail supporting \n than undetectable-qmail/postfix-masquerading-as-sendmail not supporting the correct \r\n
    /*$sendmail_path=ini_get('sendmail_path');
    	if ((strpos($sendmail_path,'qmail')!==false) || (strpos($sendmail_path,'sendmail')!==false))
    		$line_term="\n";
    	else
    		$line_term="\r\n";
    	*/
    if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' || get_option('smtp_sockets_use') == '1') {
        $line_term = "\r\n";
        /*} elseif (strtoupper(substr(PHP_OS,0,3))=='MAC')
        	{
        		$line_term="\r";*/
    } else {
        $line_term = "\n";
    }
    // We use the boundary to seperate message parts
    $_boundary = uniqid('ocPortal', true);
    $boundary = $_boundary . '_1';
    $boundary2 = $_boundary . '_2';
    $boundary3 = $_boundary . '_3';
    // Our subject
    $subject = do_template('MAIL_SUBJECT', array('_GUID' => '44a57c666bb00f96723256e26aade9e5', 'SUBJECT_TAG' => $subject_tag), $lang, false, NULL, '.tpl', 'templates', $theme);
    $tightened_subject = $subject->evaluate($lang);
    // Note that this is slightly against spec, because characters aren't forced to be printable us-ascii. But it's better we allow this (which works in practice) than risk incompatibility via charset-base64 encoding.
    $tightened_subject = str_replace(chr(10), '', $tightened_subject);
    $tightened_subject = str_replace(chr(13), '', $tightened_subject);
    $regexp = '#^[\\x' . dechex(32) . '-\\x' . dechex(126) . ']*$#';
    if (preg_match($regexp, $tightened_subject) == 0) {
        $tightened_subject = '=?' . do_lang('charset', NULL, NULL, NULL, $lang) . '?B?' . base64_encode($tightened_subject) . "?=";
    }
    if (preg_match($regexp, $from_name) == 0) {
        $from_name = '=?' . do_lang('charset', NULL, NULL, NULL, $lang) . '?B?' . base64_encode($from_name) . "?=";
    }
    if (is_array($to_name)) {
        foreach ($to_name as $i => $_to_name) {
            if (preg_match($regexp, $_to_name) == 0) {
                $to_name[$i] = '=?' . do_lang('charset', NULL, NULL, NULL, $lang) . '?B?' . base64_encode($_to_name) . "?=";
            }
        }
    } else {
        if (preg_match($regexp, $to_name) == 0) {
            $to_name = '=?' . do_lang('charset', NULL, NULL, NULL, $lang) . '?B?' . base64_encode($to_name) . "?=";
        }
    }
    $simplify_when_can = true;
    // Used for testing. Not actually needed
    // Evaluate message. Needs doing early so we know if we have any headers
    $GLOBALS['NO_LINK_TITLES'] = true;
    global $LAX_COMCODE;
    $temp = $LAX_COMCODE;
    $LAX_COMCODE = true;
    $html_content = comcode_to_tempcode($message_raw, $as, $as_admin);
    $LAX_COMCODE = $temp;
    $GLOBALS['NO_LINK_TITLES'] = false;
    $attachments = array_merge(is_null($attachments) ? array() : $attachments, $EMAIL_ATTACHMENTS);
    // Headers
    $website_email = get_option('website_email');
    if ($website_email == '') {
        $website_email = $from_email;
    }
    if (get_value('use_true_from') !== '1') {
        $headers = 'From: "' . $from_name . '" <' . $website_email . '>' . $line_term;
    } else {
        $headers = 'From: <' . $from_email . '>' . $line_term;
    }
    $headers .= 'Reply-To: <' . $from_email . '>' . $line_term;
    $headers .= 'Return-Path: <' . $website_email . '>' . $line_term;
    $headers .= 'X-Sender: <' . $website_email . '>' . $line_term;
    $cc_address = $no_cc ? '' : get_option('cc_address');
    if ($cc_address != '' && !in_array($cc_address, $to_email)) {
        $headers .= (get_option('bcc') == '1' ? 'Bcc: <' : 'Cc: <') . $cc_address . '>' . $line_term;
    }
    $headers .= 'Message-ID: <' . $_boundary . '@' . get_domain() . '>' . $line_term;
    $headers .= 'X-Priority: ' . strval($priority) . $line_term;
    $brand_name = get_value('rebrand_name');
    if (is_null($brand_name)) {
        $brand_name = 'ocPortal';
    }
    $headers .= 'X-Mailer: ' . $brand_name . $line_term;
    $headers .= 'MIME-Version: 1.0' . $line_term;
    if (!is_null($attachments) || !$simplify_when_can) {
        $headers .= 'Content-Type: multipart/mixed;' . "\n\t" . 'boundary="' . $boundary . '"';
    } else {
        $headers .= 'Content-Type: multipart/alternative;' . "\n\t" . 'boundary="' . $boundary2 . '"';
    }
    $sending_message = '';
    $sending_message .= 'This is a multi-part message in MIME format.' . $line_term . $line_term;
    if (!is_null($attachments) || !$simplify_when_can) {
        $sending_message .= '--' . $boundary . $line_term;
        $sending_message .= 'Content-Type: multipart/alternative;' . "\n\t" . 'boundary="' . $boundary2 . '"' . $line_term . $line_term . $line_term;
    }
    global $CID_IMG_ATTACHMENT;
    $CID_IMG_ATTACHMENT = array();
    // Message starts (actually: it is kind of in header form also as it uses mime multi-part)
    if (!$in_html) {
        $_html_content = $html_content->evaluate($lang);
        $_html_content = preg_replace('#(keep|for)_session=[\\d\\w]*#', 'filtered=1', $_html_content);
        $message_html = strpos($_html_content, '<html') !== false ? make_string_tempcode($_html_content) : do_template($mail_template, array('_GUID' => 'b23069c20202aa59b7450ebf8d49cde1', 'CSS' => '{CSS}', 'LOGOURL' => get_logo_url(''), 'LANG' => $lang, 'TITLE' => $subject, 'CONTENT' => $_html_content), $lang, false, NULL, '.tpl', 'templates', $theme);
        $css = css_tempcode(true, true, $message_html->evaluate($lang), $theme);
        $_css = $css->evaluate($lang);
        if (get_option('allow_ext_images') != '1') {
            $_css = preg_replace_callback('#url\\(["\']?(http://[^"]*)["\']?\\)#U', '_mail_css_rep_callback', $_css);
        }
        $html_evaluated = $message_html->evaluate($lang);
        $html_evaluated = str_replace('{CSS}', $_css, $html_evaluated);
        // Cleanup the Comcode a bit
        $message_plain = comcode_to_clean_text($message_raw);
    } else {
        $html_evaluated = $message_raw;
    }
    $base64_encode = get_value('base64_emails') === '1';
    // More robust, but more likely to be spam-blocked, and some servers can scramble it.
    // Plain version
    if (!$in_html) {
        $sending_message .= '--' . $boundary2 . $line_term;
        $sending_message .= 'Content-Type: text/plain; charset=' . (preg_match($regexp, $message_plain) == 0 ? do_lang('charset', NULL, NULL, NULL, $lang) : 'us-ascii') . $line_term;
        // '; name="message.txt"'.	Outlook doesn't like: makes it think it's an attachment
        if ($base64_encode) {
            $sending_message .= 'Content-Transfer-Encoding: base64' . $line_term . $line_term;
            $sending_message .= chunk_split(base64_encode(unixify_line_format($message_plain)) . $line_term, 76, $line_term);
        } else {
            $sending_message .= 'Content-Transfer-Encoding: 8bit' . $line_term . $line_term;
            $sending_message .= wordwrap(str_replace(chr(10), $line_term, unixify_line_format($message_plain)) . $line_term, 998, $line_term);
        }
    }
    // HTML version
    $sending_message .= '--' . $boundary2 . $line_term;
    $sending_message .= 'Content-Type: multipart/related;' . "\n\t" . 'type="text/html";' . "\n\t" . 'boundary="' . $boundary3 . '"' . $line_term . $line_term . $line_term;
    $sending_message .= '--' . $boundary3 . $line_term;
    $sending_message .= 'Content-Type: text/html; charset=' . (preg_match($regexp, $html_evaluated) == 0 ? do_lang('charset', NULL, NULL, NULL, $lang) : 'us-ascii') . $line_term;
    // .'; name="message.html"'.	Outlook doesn't like: makes it think it's an attachment
    if (get_option('allow_ext_images') != '1') {
        $html_evaluated = preg_replace_callback('#<img\\s([^>]*)src="(http://[^"]*)"#U', '_mail_img_rep_callback', $html_evaluated);
        $matches = array();
        foreach (array('#<([^"<>]*\\s)style="([^"]*)"#', '#<style( [^<>]*)?' . '>(.*)</style>#Us') as $over) {
            $num_matches = preg_match_all($over, $html_evaluated, $matches);
            for ($i = 0; $i < $num_matches; $i++) {
                $altered_inner = preg_replace_callback('#url\\(["\']?(http://[^"]*)["\']?\\)#U', '_mail_css_rep_callback', $matches[2][$i]);
                if ($matches[2][$i] != $altered_inner) {
                    $altered_outer = str_replace($matches[2][$i], $altered_inner, $matches[0][$i]);
                    $html_evaluated = str_replace($matches[0][$i], $altered_outer, $html_evaluated);
                }
            }
        }
    }
    if ($base64_encode) {
        $sending_message .= 'Content-Transfer-Encoding: base64' . $line_term . $line_term;
        $sending_message .= chunk_split(base64_encode(unixify_line_format($html_evaluated)) . $line_term, 76, $line_term);
    } else {
        $sending_message .= 'Content-Transfer-Encoding: 8bit' . $line_term . $line_term;
        // Requires RFC 1652
        $sending_message .= wordwrap(str_replace(chr(10), $line_term, unixify_line_format($html_evaluated)) . $line_term, 998, $line_term);
    }
    $total_filesize = 0;
    foreach ($CID_IMG_ATTACHMENT as $id => $img) {
        $sending_message .= '--' . $boundary3 . $line_term;
        $file_path_stub = convert_url_to_path($img);
        $mime_type = get_mime_type(get_file_extension($img));
        $filename = basename($img);
        if (!is_null($file_path_stub)) {
            $total_filesize += @filesize($file_path_stub);
            if ($total_filesize > 1024 * 1024 * 5) {
                continue;
            }
            // Too large to process into an email
            $file_contents = @file_get_contents($file_path_stub);
        } else {
            $file_contents = http_download_file($img, NULL, false);
            $total_filesize += strlen($file_contents);
            if ($total_filesize >= 1024 * 1024 * 5) {
                continue;
            }
            // Too large to process into an email
            if (!is_null($GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'])) {
                $mime_type = $GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'];
            }
            if (!is_null($GLOBALS['HTTP_FILENAME'])) {
                $filename = $GLOBALS['HTTP_FILENAME'];
            }
        }
        $sending_message .= 'Content-Type: ' . str_replace("\r", '', str_replace("\n", '', $mime_type)) . $line_term;
        $sending_message .= 'Content-ID: <' . $id . '>' . $line_term;
        $sending_message .= 'Content-Disposition: inline; filename="' . str_replace("\r", '', str_replace("\n", '', $filename)) . '"' . $line_term;
        $sending_message .= 'Content-Transfer-Encoding: base64' . $line_term . $line_term;
        if (is_string($file_contents)) {
            $sending_message .= chunk_split(base64_encode($file_contents), 76, $line_term);
        }
    }
    $sending_message .= $line_term . '--' . $boundary3 . '--' . $line_term . $line_term;
    $sending_message .= $line_term . '--' . $boundary2 . '--' . $line_term . $line_term;
    // Attachments
    if (!is_null($attachments)) {
        foreach ($attachments as $path => $filename) {
            $sending_message .= '--' . $boundary . $line_term;
            $sending_message .= 'Content-Type: ' . get_mime_type(get_file_extension($filename)) . $line_term;
            // .'; name="'.str_replace("\r",'',str_replace("\n",'',$filename)).'"'   http://www.imc.org/ietf-822/old-archive2/msg02121.html
            $sending_message .= 'Content-Transfer-Encoding: base64' . $line_term;
            $sending_message .= 'Content-Disposition: attachment; filename="' . str_replace("\r", '', str_replace("\n", '', $filename)) . '"' . $line_term . $line_term;
            if (strpos($path, '://') === false) {
                $sending_message .= chunk_split(base64_encode(file_get_contents($path)), 76, $line_term);
            } else {
                require_code('files');
                $sending_message .= chunk_split(base64_encode(http_download_file($path)), 76, $line_term);
            }
        }
        $sending_message .= $line_term . '--' . $boundary . '--' . $line_term;
    }
    // Support for SMTP sockets rather than PHP mail()
    $error = NULL;
    if (get_option('smtp_sockets_use') == '1') {
        $worked = false;
        $host = get_option('smtp_sockets_host');
        $port = intval(get_option('smtp_sockets_port'));
        $errno = 0;
        $errstr = '';
        foreach ($to_email as $i => $to) {
            $socket = @fsockopen($host, $port, $errno, $errstr, 30.0);
            if ($socket !== false) {
                $rcv = fread($socket, 1024);
                $base_url = parse_url(get_base_url());
                $domain = $base_url['host'];
                // Login if necessary
                $username = get_option('smtp_sockets_username');
                $password = get_option('smtp_sockets_password');
                if ($username != '') {
                    fwrite($socket, 'EHLO ' . $domain . "\r\n");
                    $rcv = fread($socket, 1024);
                    fwrite($socket, "AUTH LOGIN\r\n");
                    $rcv = fread($socket, 1024);
                    if (strtolower(substr($rcv, 0, 3)) == '334') {
                        fwrite($socket, base64_encode($username) . "\r\n");
                        $rcv = fread($socket, 1024);
                        if (strtolower(substr($rcv, 0, 3)) == '235' || strtolower(substr($rcv, 0, 3)) == '334') {
                            fwrite($socket, base64_encode($password) . "\r\n");
                            $rcv = fread($socket, 1024);
                            if (strtolower(substr($rcv, 0, 3)) == '235') {
                            } else {
                                $error = do_lang('MAIL_ERROR_CONNECT_PASSWORD') . ' (' . str_replace($password, '*', $rcv) . ')';
                            }
                        } else {
                            $error = do_lang('MAIL_ERROR_CONNECT_USERNAME') . ' (' . $rcv . ')';
                        }
                    } else {
                        $error = do_lang('MAIL_ERROR_CONNECT_AUTH') . ' (' . $rcv . ')';
                    }
                } else {
                    fwrite($socket, 'HELO ' . $domain . "\r\n");
                    $rcv = fread($socket, 1024);
                }
                if (is_null($error)) {
                    $smtp_from_address = get_option('smtp_from_address');
                    if ($smtp_from_address == '') {
                        $smtp_from_address = $from_email;
                    }
                    fwrite($socket, 'MAIL FROM:<' . $website_email . ">\r\n");
                    $rcv = fread($socket, 1024);
                    if (strtolower(substr($rcv, 0, 3)) == '250' || strtolower(substr($rcv, 0, 3)) == '251') {
                        $sent_one = false;
                        fwrite($socket, "RCPT TO:<" . $to_email[$i] . ">\r\n");
                        $rcv = fread($socket, 1024);
                        if (strtolower(substr($rcv, 0, 3)) != '250' && strtolower(substr($rcv, 0, 3)) != '251') {
                            $error = do_lang('MAIL_ERROR_TO') . ' (' . $rcv . ')' . ' ' . $to_email[$i];
                        } else {
                            $sent_one = true;
                        }
                        if ($sent_one) {
                            fwrite($socket, "DATA\r\n");
                            $rcv = fread($socket, 1024);
                            if (strtolower(substr($rcv, 0, 3)) == '354') {
                                $attractive_date = strftime('%d %B %Y  %H:%M:%S', time());
                                $_to_name = preg_replace('#@.*$#', '', is_array($to_name) ? $to_name[$i] : $to_name);
                                // preg_replace is because some servers may reject sending names that look like e-mail addresses. ocP tries this from recommend module.
                                if (count($to_email) == 1) {
                                    if ($_to_name == '') {
                                        fwrite($socket, 'To: ' . $to_email[$i] . "\r\n");
                                    } else {
                                        fwrite($socket, 'To: ' . $_to_name . ' <' . $to_email[$i] . '>' . "\r\n");
                                    }
                                } else {
                                    fwrite($socket, 'To: ' . $_to_name . "\r\n");
                                }
                                fwrite($socket, 'Subject: ' . $tightened_subject . "\r\n");
                                fwrite($socket, 'Date: ' . $attractive_date . "\r\n");
                                $headers = preg_replace('#^\\.#m', '..', $headers);
                                $sending_message = preg_replace('#^\\.#m', '..', $sending_message);
                                fwrite($socket, $headers . "\r\n");
                                fwrite($socket, $sending_message);
                                fwrite($socket, "\r\n.\r\n");
                                $rcv = fread($socket, 1024);
                                fwrite($socket, "QUIT\r\n");
                                $rcv = fread($socket, 1024);
                            } else {
                                $error = do_lang('MAIL_ERROR_DATA') . ' (' . $rcv . ')';
                            }
                        }
                    } else {
                        $error = do_lang('MAIL_ERROR_FROM') . ' (' . $rcv . ')';
                    }
                    if (@fwrite($socket, "RSET\r\n") === false) {
                        @fclose($socket);
                        $socket = NULL;
                    } else {
                        $rcv = fread($socket, 1024);
                    }
                }
                if (!is_null($socket)) {
                    fclose($socket);
                }
                if (is_null($error)) {
                    $worked = true;
                }
            } else {
                $error = do_lang('MAIL_ERROR_CONNECT', $host, strval($port));
            }
        }
    } else {
        $worked = false;
        foreach ($to_email as $i => $to) {
            //exit($headers.chr(10).$sending_message);
            $GLOBALS['SUPPRESS_ERROR_DEATH'] = true;
            $additional = '';
            if (get_option('enveloper_override') == '1') {
                $additional = '-f ' . $website_email;
            }
            $_to_name = preg_replace('#@.*$#', '', is_array($to_name) ? $to_name[$i] : $to_name);
            // preg_replace is because some servers may reject sending names that look like e-mail addresses. ocP tries this from recommend module.
            if ($_to_name == '' || strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
                $to_line = $to;
            } else {
                $to_line = '"' . $_to_name . '" <' . $to . '>';
            }
            //if (function_exists('mb_language')) mb_language('en');	Stop overridden mbstring mail function from messing and base64'ing stuff. Actually we don't need this as we make sure to pass through as headers with blank message, bypassing any filtering.
            if (str_replace(array('on', 'true', 'yes'), array('1', '1', '1'), strtolower(ini_get('safe_mode'))) == '1') {
                $worked = mail($to_line, $tightened_subject, $sending_message, $headers);
            } else {
                $worked = mail($to_line, $tightened_subject, $sending_message, $headers, $additional);
            }
            if (!$worked && isset($php_errormsg)) {
                $error = $php_errormsg;
            }
            $GLOBALS['SUPPRESS_ERROR_DEATH'] = false;
        }
    }
    if (!$worked) {
        $SENDING_MAIL = false;
        if (get_param_integer('keep_hide_mail_failure', 0) == 0) {
            require_code('site');
            attach_message(!is_null($error) ? make_string_tempcode($error) : do_lang_tempcode('MAIL_FAIL', escape_html(get_option('staff_address'))), 'warn');
        } else {
            return warn_screen(get_page_title('ERROR_OCCURRED'), do_lang_tempcode('MAIL_FAIL', escape_html(get_option('staff_address'))));
        }
    }
    $SENDING_MAIL = false;
    return NULL;
}
Esempio n. 6
0
 /**
  * View an event.
  *
  * @return tempcode		The UI
  */
 function view_event()
 {
     check_specific_permission('view_calendar');
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'back';
     $id = get_param_integer('id');
     $filter = $this->get_filter();
     $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=calendar&filter=' . implode(',', $this->get_and_filter());
     $rows = $GLOBALS['SITE_DB']->query_select('calendar_events e LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'calendar_types t ON t.id=e.e_type', array('*'), array('e.id' => $id), '', 1);
     if (!array_key_exists(0, $rows)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $event = $rows[0];
     if ($event['e_is_public'] == 0) {
         enforce_personal_access($event['e_submitter'], 'view_personal_events');
     }
     if (!has_category_access(get_member(), 'calendar', strval($event['e_type']))) {
         access_denied('CATEGORY_ACCESS');
     }
     // Validation
     $warning_details = new ocp_tempcode();
     if ($event['validated'] == 0 && $event['e_is_public'] == 1) {
         if (!has_specific_permission(get_member(), 'jump_to_unvalidated')) {
             access_denied('SPECIFIC_PERMISSION', 'jump_to_unvalidated');
         }
         $warning_details->attach(do_template('WARNING_TABLE', array('_GUID' => '332faacba974e648a67e5e91ffd3d8e5', 'WARNING' => do_lang_tempcode(get_param_integer('redirected', 0) == 1 ? 'UNVALIDATED_TEXT_NON_DIRECT' : 'UNVALIDATED_TEXT'))));
     }
     if (addon_installed('awards')) {
         require_code('awards');
         $awards = find_awards_for('event', strval($id));
     } else {
         $awards = array();
     }
     $_title = get_translated_text($event['e_title']);
     $title_to_use = do_lang_tempcode('CALENDAR_EVENT_VCAL', escape_html($_title));
     $title_to_use_2 = do_lang('CALENDAR_EVENT', $_title);
     $title = get_page_title($title_to_use, false, NULL, NULL, $awards);
     seo_meta_load_for('event', strval($id), $title_to_use_2);
     $content = $event['e_type'] == db_get_first_id() ? make_string_tempcode(get_translated_text($event['e_content'])) : get_translated_tempcode($event['e_content']);
     $type = get_translated_text($event['t_title']);
     $subscribed = new ocp_tempcode();
     if (has_specific_permission(get_member(), 'view_event_subscriptions') && cron_installed()) {
         $subscriptions = $GLOBALS['SITE_DB']->query_select('calendar_reminders', array('DISTINCT n_member_id'), array('e_id' => $id), '', 100);
         if (count($subscriptions) < 100) {
             foreach ($subscriptions as $subscription) {
                 $username = $GLOBALS['FORUM_DRIVER']->get_username($subscription['n_member_id']);
                 if (!is_null($username)) {
                     $member_url = $GLOBALS['FORUM_DRIVER']->member_profile_url($subscription['n_member_id'], false, true);
                     $subscribed->attach(do_template('CALENDAR_SCREEN_SUBSCRIPTION', array('_GUID' => 'c756b8b3f0c57494fd46a94e9abce029', 'MEMBER_URL' => $member_url, 'USERNAME' => $username)));
                 }
             }
         }
     }
     $__first_date = mktime($event['e_start_hour'], $event['e_start_minute'], 0, $event['e_start_month'], $event['e_start_day'], $event['e_start_year']);
     $_first_date = cal_utctime_to_usertime($__first_date, $event['e_timezone'], $event['e_do_timezone_conv'] == 1);
     $first_date = date('Y-m-d', $_first_date);
     $date = get_param('date', $first_date);
     // It's year 10,000 compliant when it comes to year display ;).
     $back_type = get_param('back', 'day');
     $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => $back_type, 'id' => $date));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $back_url = build_url($map, '_SELF');
     list($rating_details, $comment_details, $trackback_details) = embed_feedback_systems('events', strval($id) . ($event['e_seg_recurrences'] == 1 ? '_' . $date : ''), $event['allow_rating'], $event['allow_comments'], $event['allow_trackbacks'], get_option('is_on_strong_forum_tie') == '0' || $event['e_is_public'] == 1 ? 1 : 0, $event['e_submitter'], build_url(array('page' => '_SELF', 'type' => 'view', 'id' => $id), '_SELF', NULL, false, false, true), $_title, get_value('comment_forum__calendar'));
     $_subscriptions = new ocp_tempcode();
     if (is_guest() || !cron_installed()) {
         $subscribe_url = new ocp_tempcode();
     } else {
         $subscriptions = $GLOBALS['SITE_DB']->query_select('calendar_reminders', array('id', 'n_seconds_before'), array('e_id' => $id, 'n_member_id' => get_member()));
         foreach ($subscriptions as $subscription) {
             $time = display_time_period(intval($subscription['n_seconds_before']));
             $unsubscribe_url = build_url(array('page' => '_SELF', 'type' => 'unsubscribe_event', 'id' => $id, 'reminder_id' => $subscription['id']), '_SELF');
             $_subscriptions->attach(do_template('CALENDAR_SCREEN_PERSONAL_SUBSCRIPTION', array('_GUID' => 'cc36c75ea516abfab1c65328c0e290fc', 'UNSUBSCRIBE_URL' => $unsubscribe_url, 'TIME' => $time)));
         }
         $subscribe_url = build_url(array('page' => '_SELF', 'type' => 'subscribe_event', 'id' => $id), '_SELF');
     }
     if (has_actual_page_access(NULL, 'cms_calendar', NULL, NULL) && has_edit_permission($event['e_is_public'] == 0 ? 'low' : 'mid', get_member(), $event['e_submitter'], 'cms_calendar', array('calendar', $event['e_type']))) {
         $edit_url = build_url(array('page' => 'cms_calendar', 'type' => '_ed', 'id' => $id), get_module_zone('cms_calendar'));
     } else {
         $edit_url = new ocp_tempcode();
     }
     if ($event['e_seg_recurrences'] == 0) {
         $NON_CANONICAL_PARAMS[] = 'day';
         $NON_CANONICAL_PARAMS[] = 'date';
     }
     $day = get_param('day', '');
     if ($day != '') {
         $explode = explode('-', $day);
         if (count($explode) == 3) {
             if (is_null($event['e_start_hour'])) {
                 if (is_null($event['e_end_year']) || is_null($event['e_end_month']) || is_null($event['e_end_day'])) {
                     $event['e_end_day'] = $event['e_start_day'];
                     $event['e_end_month'] = $event['e_start_month'];
                     $event['e_end_year'] = $event['e_start_year'];
                 }
             }
             if (!is_null($event['e_end_year']) && !is_null($event['e_end_month']) && !is_null($event['e_end_day'])) {
                 $event['e_end_year'] += intval($explode[0]) - $event['e_start_year'];
                 $event['e_end_month'] += intval($explode[1]) - $event['e_start_month'];
                 $event['e_end_day'] += intval($explode[2]) - $event['e_start_day'];
             }
             $event['e_start_year'] = intval($explode[0]);
             $event['e_start_month'] = intval($explode[1]);
             $event['e_start_day'] = intval($explode[2]);
         }
     }
     $time_raw = cal_get_start_utctime_for_event($event['e_timezone'], $event['e_start_year'], $event['e_start_month'], $event['e_start_day'], $event['e_start_hour'], $event['e_start_minute'], $event['e_do_timezone_conv'] == 1);
     $from = cal_utctime_to_usertime($time_raw, $event['e_timezone'], $event['e_do_timezone_conv'] == 1);
     $day_formatted = locale_filter(date(do_lang('calendar_date'), $from));
     if (!is_null($event['e_end_year']) && !is_null($event['e_end_month']) && !is_null($event['e_end_day'])) {
         $to_raw = cal_get_end_utctime_for_event($event['e_timezone'], $event['e_end_year'], $event['e_end_month'], $event['e_end_day'], $event['e_end_hour'], $event['e_end_minute'], $event['e_do_timezone_conv'] == 1);
         $to = cal_utctime_to_usertime($to_raw, $event['e_timezone'], $event['e_do_timezone_conv'] == 1);
         $to_day_formatted = locale_filter(date(do_lang('calendar_date'), $to));
         $time2 = date_range($from, $to, !is_null($event['e_start_hour']));
     } else {
         $to_raw = NULL;
         $time2 = is_null($event['e_start_hour']) ? '' : locale_filter(my_strftime(do_lang('calendar_minute'), $from));
         $to = NULL;
         $to_day_formatted = NULL;
     }
     $priority = $event['e_priority'];
     $is_public = $event['e_is_public'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO');
     $recurrence = do_lang_tempcode('NA_EM');
     if ($event['e_recurrence'] != 'none' && $event['e_recurrence'] != '') {
         $l_code = explode(' ', strtoupper($event['e_recurrence']));
         $recurrence = do_lang_tempcode($l_code[0]);
         if (!is_null($event['e_recurrences'])) {
             $recurrence = do_lang_tempcode('RECURRENCE_ITERATION', $recurrence, make_string_tempcode(integer_format($event['e_recurrences'])));
         }
     } elseif ($day == '') {
         $day = $first_date;
     }
     $priority_lang = do_lang_tempcode('PRIORITY_' . strval($priority));
     // Views
     if (get_db_type() != 'xml') {
         $event['e_views']++;
         $GLOBALS['SITE_DB']->query_update('calendar_events', array('e_views' => $event['e_views']), array('id' => $id), '', 1, NULL, false, true);
     }
     breadcrumb_set_parents(array(array($back_url, do_lang_tempcode('CALENDAR'))));
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $event['e_add_date']), 'creator' => $GLOBALS['FORUM_DRIVER']->get_username($event['e_submitter']), 'publisher' => '', 'modified' => is_null($event['e_edit_date']) ? '' : date('Y-m-d', $event['e_edit_date']), 'type' => 'Calendar event', 'title' => get_translated_text($event['e_title']), 'identifier' => '_SEARCH:calendar:view:' . strval($id), 'description' => get_translated_text($event['e_content']), 'image' => find_theme_image('bigicons/calendar'));
     $map = array('TITLE' => $title, '_TITLE' => get_translated_text($event['e_title']), 'ID' => strval($id), 'TAGS' => get_loaded_tags('calendar'), 'WARNING_DETAILS' => $warning_details, 'SUBMITTER' => strval($event['e_submitter']), 'ADD_DATE' => get_timezoned_date($event['e_add_date']), 'ADD_DATE_RAW' => strval($event['e_add_date']), 'EDIT_DATE_RAW' => is_null($event['e_edit_date']) ? '' : strval($event['e_edit_date']), 'VIEWS' => integer_format($event['e_views']), 'LOGO' => $event['t_logo'], 'DAY' => $day_formatted, 'TO_DAY' => $to_day_formatted, 'RECURRENCE' => $recurrence, 'IS_PUBLIC' => $is_public, 'PRIORITY' => strval($priority), 'PRIORITY_LANG' => $priority_lang, 'TYPE' => $type, 'TIME' => $time2, 'TIME_RAW' => strval($time_raw), 'TIME_VCAL' => date('Y-m-d', $time_raw) . ' ' . date('H:i:s', $time_raw), 'TO_TIME_VCAL' => is_null($to_raw) ? NULL : date('Y-m-d', $to_raw) . ' ' . date('H:i:s', $to_raw), 'EDIT_URL' => $edit_url, 'SUBSCRIPTIONS' => $_subscriptions, 'SUBSCRIBE_URL' => $subscribe_url, 'BACK_URL' => $back_url, 'CONTENT' => $content, 'SUBSCRIBED' => $subscribed, 'RATING_DETAILS' => $rating_details, 'TRACKBACK_DETAILS' => $trackback_details, 'COMMENT_DETAILS' => $comment_details, '_GUID' => '602e6f86f586ef0a24efed950eafd426');
     if ($event['e_do_timezone_conv'] == 0) {
         $timezone_map = get_timezone_list();
         $map['TIMEZONE'] = $timezone_map[$event['e_timezone']];
     }
     return do_template('CALENDAR_SCREEN', $map);
 }
Esempio n. 7
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_code('rss');
     require_lang('weather');
     if (array_key_exists('param', $map)) {
         $loc_code = $map['param'];
     } else {
         $loc_code = '34503';
     }
     // if not found setting a default location for weather
     if (!is_numeric($loc_code)) {
         $test = $GLOBALS['SITE_DB']->query_value_null_ok('cached_weather_codes', 'w_code', array('w_string' => $loc_code));
         if (is_null($test)) {
             require_code('files');
             $result = http_download_file('http://uk.weather.yahoo.com/search/weather?p=' . urlencode($loc_code));
             $matches = array();
             if (preg_match('#<a href=\'/redirwoei/(\\d+)\'>#', $result, $matches) != 0) {
                 $loc_code = $matches[1];
             } elseif (preg_match('#-(\\d+)/#', $GLOBALS['HTTP_DOWNLOAD_URL'], $matches) != 0) {
                 $loc_code = $matches[1];
             } else {
                 return new ocp_tempcode();
             }
             if (is_numeric($loc_code)) {
                 $GLOBALS['SITE_DB']->query_insert('cached_weather_codes', array('w_string' => $map['param'], 'w_code' => intval($loc_code)));
             }
         } else {
             $loc_code = strval($test);
         }
     }
     $temperature_unit = array_key_exists('unit', $map) && $map['unit'] != '' ? $map['unit'] : 'c';
     if (is_numeric($loc_code)) {
         $rss_url = 'http://weather.yahooapis.com/forecastrss?w=' . urlencode($loc_code) . '&u=' . urlencode($temperature_unit);
     } else {
         $rss_url = 'http://weather.yahooapis.com/forecastrss?p=' . urlencode($loc_code) . '&u=' . urlencode($temperature_unit);
     }
     $rss = new rss($rss_url);
     if (!is_null($rss->error)) {
         $GLOBALS['DO_NOT_CACHE_THIS'] = true;
         require_code('failure');
         relay_error_notification(do_lang('ERROR_HANDLING_RSS_FEED', '', $rss->error), false, 'error_occurred_weather');
         if (cron_installed()) {
             if (!$GLOBALS['FORUM_DRIVER']->is_staff(get_member())) {
                 return new ocp_tempcode();
             }
         }
         return do_template('INLINE_WIP_MESSAGE', array('MESSAGE' => htmlentities($rss->error)));
     }
     foreach ($rss->gleamed_items as $item) {
         if (array_key_exists('title', $item)) {
             $title = $item['title'];
         }
         if (array_key_exists('news', $item)) {
             $out = array();
             $content = $item['news'];
             if (preg_match('/<img src="(.*)"\\/?' . '>/Usm', $item['news'], $out) != 0) {
                 $image = $out[1];
             } else {
                 $image = '';
             }
             if (preg_match('/Current Conditions:<\\/b><br \\/>(.*)<BR \\/>/Uism', $item['news'], $out) != 0) {
                 $cur_conditions = $out[1];
             } else {
                 $cur_conditions = '';
             }
             if (preg_match('/Forecast:<\\/b><BR \\/>(.*)<br \\/>/ism', $item['news'], $out) != 0) {
                 $forecast = $out[1];
             } else {
                 $forecast = '';
             }
         }
     }
     return do_template('BLOCK_SIDE_WEATHER', array('TITLE' => $title, 'LOC_CODE' => $loc_code, 'IMAGE' => $image, 'COND' => $cur_conditions, 'FORECAST' => $forecast));
 }
Esempio n. 8
0
 /**
  * Get tempcode for a catalogue category adding/editing form.
  *
  * @param  ?ID_TEXT		The name of the catalogue the category is in (NULL: detect)
  * @param  SHORT_TEXT	The title of the category
  * @param  LONG_TEXT		Description for the category
  * @param  LONG_TEXT		Admin notes
  * @param  ?AUTO_LINK	The ID of the parent category (NULL: no parent) (-1: arbitrary default)
  * @param  ?AUTO_LINK	The ID of this category (NULL: we're adding, not editing)
  * @param  URLPATH		The rep-image for the catalogue category
  * @param  integer		The number of days before expiry (lower limit)
  * @param  integer		The number of days before expiry (higher limit)
  * @param  ?AUTO_LINK	The expiry category (NULL: do not expire)
  * @return array			A pair: the tempcode for the visible fields, and the tempcode for the hidden fields
  */
 function get_form_fields($catalogue_name = NULL, $title = '', $description = '', $notes = '', $parent_id = -1, $id = NULL, $rep_image = '', $move_days_lower = 30, $move_days_higher = 60, $move_target = NULL)
 {
     if (is_null($catalogue_name)) {
         $catalogue_name = get_param('catalogue_name', is_null($id) ? false : $GLOBALS['SITE_DB']->query_value('catalogues_categories', 'c_name', array('id' => $id)));
     }
     if ($parent_id == -1) {
         global $NON_CANONICAL_PARAMS;
         $NON_CANONICAL_PARAMS[] = 'parent_id';
         $NON_CANONICAL_PARAMS[] = 'title';
         $NON_CANONICAL_PARAMS[] = 'notes';
         $parent_id = get_param_integer('parent_id', -1);
         $title = get_param('title', $title);
         $notes = get_param('notes', $notes);
     }
     $fields = new ocp_tempcode();
     require_code('form_templates');
     $hidden = new ocp_tempcode();
     $hidden->attach(form_input_hidden('catalogue_name', $catalogue_name));
     $fields->attach(form_input_line(do_lang_tempcode('TITLE'), do_lang_tempcode('DESCRIPTION_TITLE'), 'title', $title, true));
     $fields->attach(form_input_text_comcode(do_lang_tempcode('DESCRIPTION'), do_lang_tempcode('DESCRIPTION_DESCRIPTION'), 'description', $description, false));
     if (get_value('disable_staff_notes') !== '1') {
         $fields->attach(form_input_text(do_lang_tempcode('NOTES'), do_lang_tempcode('DESCRIPTION_NOTES'), 'notes', $notes, false));
     }
     handle_max_file_size($hidden, 'image');
     $fields->attach(form_input_upload(do_lang_tempcode('REPRESENTATIVE_IMAGE'), do_lang_tempcode('DESCRIPTION_REPRESENTATIVE_IMAGE'), 'rep_image', false, $rep_image, NULL, true, str_replace(' ', '', get_option('valid_images'))));
     // Is the catalogue a tree?
     $is_tree = $GLOBALS['SITE_DB']->query_value_null_ok('catalogues', 'c_is_tree', array('c_name' => $catalogue_name));
     if (is_null($is_tree)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     if ($is_tree == 1 && !is_null($parent_id)) {
         $fields->attach(form_input_tree_list(do_lang_tempcode('PARENT'), do_lang_tempcode('DESCRIPTION_PARENT'), 'parent_id', NULL, 'choose_catalogue_category', array('catalogue_name' => $catalogue_name), true, is_null($parent_id) || $parent_id == -1 ? '' : strval($parent_id)));
     }
     $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => is_null($move_target), 'TITLE' => do_lang_tempcode('CLASSIFIED_ADS'))));
     $list = new ocp_tempcode();
     $fields->attach(form_input_tree_list(do_lang_tempcode('EXPIRY_MOVE_TARGET'), do_lang_tempcode('DESCRIPTION_EXPIRY_MOVE_TARGET'), 'move_target', NULL, 'choose_catalogue_category', array('catalogue_name' => $catalogue_name), false, is_null($move_target) ? NULL : strval($move_target)));
     if (cron_installed()) {
         $fields->attach(form_input_integer(do_lang_tempcode('EXPIRY_MOVE_DAYS_LOWER'), do_lang_tempcode('DESCRIPTION_EXPIRY_MOVE_DAYS_LOWER'), 'move_days_lower', $move_days_lower, true));
         $fields->attach(form_input_integer(do_lang_tempcode('EXPIRY_MOVE_DAYS_HIGHER'), do_lang_tempcode('DESCRIPTION_EXPIRY_MOVE_DAYS_HIGHER'), 'move_days_higher', $move_days_higher, true));
     }
     // Permissions
     if (get_value('disable_cat_cat_perms') !== '1') {
         $fields->attach($this->get_permission_fields(is_null($id) ? '' : strval($id), NULL, is_null($id)));
     }
     return array($fields, $hidden);
 }
Esempio n. 9
0
 /**
  * The UI for managing temporary usergroup memberships.
  *
  * @return tempcode		The UI
  */
 function group_member_timeouts()
 {
     $title = get_page_title('GROUP_MEMBER_TIMEOUTS');
     if (!cron_installed()) {
         attach_message(do_lang_tempcode('CRON_NEEDED_TO_WORK', escape_html(brand_base_url() . '/docs' . strval(ocp_version()) . '/pg/tut_configuration')), 'warn');
     }
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/usergroups_temp';
     breadcrumb_set_parents(array(array('_SEARCH:admin_ocf_join:menu', do_lang_tempcode('MEMBERS'))));
     require_code('form_templates');
     require_code('templates_results_table');
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 100);
     $max_rows = $GLOBALS[get_forum_type() == 'ocf' ? 'FORUM_DB' : 'SITE_DB']->query_value('f_group_member_timeouts', 'COUNT(*)');
     $fields_title = results_field_title(array(do_lang_tempcode('USERNAME'), do_lang_tempcode('_USERGROUP'), do_lang_tempcode('TIME')));
     $timeouts = $GLOBALS[get_forum_type() == 'ocf' ? 'FORUM_DB' : 'SITE_DB']->query_select('f_group_member_timeouts', array('member_id', 'group_id', 'timeout'), NULL, '', $max, $start);
     $usergroups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list();
     $tfields = new ocp_tempcode();
     foreach ($timeouts as $timeout) {
         $tfields->attach(results_entry(array($GLOBALS['FORUM_DRIVER']->get_username($timeout['member_id']), isset($usergroups[$timeout['group_id']]) ? $usergroups[$timeout['group_id']] : do_lang('UNKNOWN'), display_time_period($timeout['timeout'] - time())), true));
     }
     $results_table = results_table(do_lang('GROUP_MEMBER_TIMEOUTS'), $start, 'start', $max, 'max', $max_rows, $fields_title, $tfields);
     $fields = new ocp_tempcode();
     $fields->attach(form_input_username(do_lang_tempcode('USERNAME'), '', 'username', '', true));
     $_usergroups = new ocp_tempcode();
     foreach ($usergroups as $uid => $name) {
         if ($uid != db_get_first_id()) {
             $_usergroups->attach(form_input_list_entry($uid, false, $name));
         }
     }
     require_lang('dates');
     $fields->attach(form_input_list(do_lang_tempcode('_USERGROUP'), '', 'group_id', $_usergroups, NULL, false, true));
     $fields->attach(form_input_integer(do_lang_tempcode('_MINUTES'), do_lang_tempcode('DESCRIPTION_GROUPMT_MINUTES'), 'num_minutes', 60, true));
     $post_url = build_url(array('page' => '_SELF', 'type' => '_group_member_timeouts'), '_SELF');
     $submit_name = do_lang_tempcode('ADD');
     $form = do_template('FORM', array('TABINDEX' => strval(get_form_field_tabindex()), 'HIDDEN' => '', 'TEXT' => '', 'FIELDS' => $fields, 'URL' => $post_url, 'SUBMIT_NAME' => $submit_name));
     return do_template('RESULTS_TABLE_SCREEN', array('TITLE' => $title, 'RESULTS_TABLE' => $results_table, 'FORM' => $form));
 }
Esempio n. 10
0
/**
 * Find the default caching setting for a block.
 *
 * @param  ID_TEXT             The block name
 * @return ID_TEXT             The default caching setting
 */
function block_cache_default($codename)
{
    if (cron_installed()) {
        if ($codename == 'side_weather' || $codename == 'side_rss' || $codename == 'main_rss') {
            return '2';
        }
    }
    return '1';
}
Esempio n. 11
0
/**
 * Find whether a particular feature is available to ocPortal (e.g. it's an addon).
 *
 * @param  ID_TEXT		Feature name
 * @return boolean		Whether it is
 */
function has_feature($dependency)
{
    $dependency = str_replace(' ', '', strtolower(preg_replace('# (enabled|needed|required)$#', '', $dependency)));
    if ($dependency == 'yes') {
        return true;
    }
    // Buggy addon definition
    $remapping = array('chatrooms' => 'chat', 'side_stats' => 'stats_block');
    if (array_key_exists($dependency, $remapping)) {
        $dependency = $remapping[$dependency];
    }
    // Non-bundled addon
    $test = $GLOBALS['SITE_DB']->query_value_null_ok('addons', 'addon_name', array('addon_name' => $dependency));
    if (!is_null($test)) {
        return true;
    }
    // Bundled/new-style addon
    if (file_exists(get_file_base() . '/sources_custom/hooks/systems/addon_registry/' . $dependency . '.php')) {
        return true;
    }
    if (file_exists(get_file_base() . '/sources/hooks/systems/addon_registry/' . $dependency . '.php')) {
        return true;
    }
    // Some other features
    if ($dependency == 'javascript' && has_js()) {
        return true;
    }
    if ($dependency == 'cron' && cron_installed()) {
        return true;
    }
    if ($dependency == 'ocf' && get_forum_type() == 'ocf') {
        return true;
    }
    if ($dependency == 'gd' && get_option('is_on_gd') == '1' && function_exists('imagecreatefromstring')) {
        return true;
    }
    if ($dependency == 'adobeflash') {
        return true;
    }
    if (substr($dependency, 0, 3) == 'php') {
        $phpv = phpversion();
        if (version_compare(substr($phpv, 0, strlen(substr($dependency, 3))), substr($dependency, 3), '>=')) {
            return true;
        }
    }
    // ---
    // Try plural form
    if (substr($dependency, -1) != 's') {
        return has_feature($dependency . 's');
    }
    return false;
}
Esempio n. 12
0
/**
 * Get the tempcode for a date input, or if cron is not on, return blank.
 *
 * @param  mixed			A human intelligible name for this input field
 * @param  mixed			A description for this input field
 * @param  ID_TEXT		The parameter name stub for this input field (it's actually a composite field, read in by passing this stub to post_param_date)
 * @param  boolean		Whether this is a required field
 * @param  boolean		Whether this field is empty by default
 * @param  boolean		Whether to input time for this field also
 * @param  ?mixed			The default timestamp to use (either TIME or array of time components) (NULL: now)
 * @param  integer		The number of years to allow selection from (all into the future, as this field type is not meant for inputting past dates)
 * @param  ?integer		The year to start from (NULL: this year)
 * @param  ?integer		The tab index of the field (NULL: not specified)
 * @return tempcode		The input field
 */
function form_input_date__scheduler($pretty_name, $description, $stub, $null_ok, $null_default, $do_time, $default_time = NULL, $total_years_to_show = 10, $year_start = NULL, $tabindex = NULL)
{
    if (cron_installed()) {
        return form_input_date($pretty_name, $description, $stub, $null_ok, $null_default, $do_time, $default_time, $total_years_to_show, $year_start, $tabindex);
    }
    return new ocp_tempcode();
}
Esempio n. 13
0
 /**
  * Get the form fields for an event input form.
  *
  * @param  ?AUTO_LINK		The event type (NULL: default)
  * @param  ?integer			The year the event starts at (NULL: default)
  * @param  ?integer			The month the event starts at (NULL: default)
  * @param  ?integer			The day the event starts at (NULL: default)
  * @param  ?integer			The hour the event starts at (NULL: default)
  * @param  ?integer			The minute the event starts at (NULL: default)
  * @param  SHORT_TEXT		The title of the event
  * @param  LONG_TEXT			The full text describing the event
  * @param  SHORT_TEXT		The recurrence code
  * @param  ?integer			The number of recurrences (NULL: none/infinite)
  * @param  BINARY				Whether to segregate the comment-topics/rating/trackbacks per-recurrence
  * @param  BINARY				Whether it is a public event
  * @param  integer			The priority
  * @range  1 5
  * @param  ?integer			The year the event ends at (NULL: not a multi day event)
  * @param  ?integer			The month the event ends at (NULL: not a multi day event)
  * @param  ?integer			The day the event ends at (NULL: not a multi day event)
  * @param  ?integer			The hour the event ends at (NULL: not a multi day event)
  * @param  ?integer			The minute the event ends at (NULL: not a multi day event)
  * @param  ?ID_TEXT			The timezone for the event (NULL: current user's timezone)
  * @param  BINARY				Whether the time should be presented in the viewer's own timezone
  * @param  BINARY				Whether the event 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  LONG_TEXT			Notes
  * @return array				A tuple of: (fields, hidden-fields, delete-fields, edit-text, whether all delete fields are specified, posting form text, more fields)
  */
 function get_form_fields($type = NULL, $start_year = NULL, $start_month = NULL, $start_day = NULL, $start_hour = NULL, $start_minute = NULL, $title = '', $content = '', $recurrence = 'none', $recurrences = NULL, $seg_recurrences = 0, $is_public = 1, $priority = 3, $end_year = NULL, $end_month = NULL, $end_day = NULL, $end_hour = NULL, $end_minute = NULL, $timezone = NULL, $do_timezone_conv = 0, $validated = 1, $allow_rating = NULL, $allow_comments = NULL, $allow_trackbacks = NULL, $notes = '')
 {
     list($allow_rating, $allow_comments, $allow_trackbacks) = $this->choose_feedback_fields_statistically($allow_rating, $allow_comments, $allow_trackbacks);
     unset($content);
     if (is_null($timezone) || $timezone == '') {
         $timezone = get_users_timezone();
     }
     require_code('form_templates');
     if (is_null($type)) {
         global $NON_CANONICAL_PARAMS;
         $NON_CANONICAL_PARAMS[] = 'date';
         $NON_CANONICAL_PARAMS[] = 'e_type';
         $NON_CANONICAL_PARAMS[] = 'validated';
         $date = get_param('date', '');
         $start_hour = NULL;
         $start_minute = NULL;
         if ($date != '') {
             $date2 = explode(' ', $date);
             $exploded = explode('-', $date2[0]);
             //if (count($exploded)!=3) warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
             $start_year = intval($exploded[0]);
             $start_month = intval($exploded[1]);
             $start_day = intval($exploded[2]);
             if (array_key_exists(1, $date2)) {
                 $exploded = explode(':', $date2[1]);
                 //if (count($exploded)!=2) warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
                 $start_hour = intval($exploded[0]);
                 $start_minute = intval($exploded[1]);
             }
         } else {
             list($start_year, $start_month, $start_day) = array(NULL, NULL, NULL);
         }
         $type = get_param_integer('e_type', -1);
         if ($type == -1) {
             $type = NULL;
         }
         $adding = true;
     } else {
         $adding = false;
     }
     if (is_null($type)) {
         $type = db_get_first_id() + 1;
     }
     if (is_null($start_month)) {
         $start_year = intval(date('Y'));
         $start_month = intval(date('m'));
         $start_day = intval(date('d'));
         $start_hour = NULL;
         $start_minute = NULL;
     }
     if ((is_null($end_year) || is_null($end_month) || is_null($end_day)) && $adding) {
         $end_year = NULL;
         //$start_year;
         $end_month = NULL;
         //$start_month;
         $end_day = NULL;
         //$start_day;
         $end_hour = NULL;
         $end_minute = NULL;
     }
     $fields = new ocp_tempcode();
     $hidden = new ocp_tempcode();
     $fields->attach(form_input_line(do_lang_tempcode('TITLE'), do_lang_tempcode('DESCRIPTION_TITLE'), 'title', $title, true));
     //$fields->attach(form_input_text_comcode(do_lang_tempcode('EVENT_TEXT'),do_lang_tempcode('DESCRIPTION_EVENT_TEXT'),'content',$content,false));
     // Type
     $type_list = nice_get_event_types($type);
     $fields->attach(form_input_list(do_lang_tempcode('TYPE'), do_lang_tempcode('DESCRIPTION_EVENT_TYPE'), 'type', $type_list));
     // Dates
     $fields->attach(form_input_tick(do_lang_tempcode('ALL_DAY_EVENT'), do_lang_tempcode('DESCRIPTION_ALL_DAY_EVENT'), 'all_day_event', is_null($start_hour)));
     $fields->attach(form_input_date(do_lang_tempcode('DATE_TIME'), '', 'start', false, false, true, array(is_null($start_minute) ? find_timezone_start_minute_in_utc($timezone, $start_year, $start_month, $start_day) : $start_minute, is_null($start_hour) ? find_timezone_start_hour_in_utc($timezone, $start_year, $start_month, $start_day) : $start_hour, $start_month, $start_day, $start_year), 120, intval(date('Y')) - 100, NULL, NULL, true, $timezone, get_param('date', '') == ''));
     $fields->attach(form_input_date(do_lang_tempcode('END_DATE_AND_TIME'), do_lang_tempcode('DESCRIPTION_END_DATE_AND_TIME'), 'end', true, is_null($end_year), true, array(is_null($end_minute) ? find_timezone_end_minute_in_utc($timezone, $end_year, $end_month, $end_day) : $end_minute, is_null($end_hour) ? find_timezone_end_hour_in_utc($timezone, $end_year, $end_month, $end_day) : $end_hour, $end_month, $end_day, $end_year), 120, intval(date('Y')) - 100, NULL, NULL, true, $timezone));
     if ($validated == 0) {
         $validated = get_param_integer('validated', 0);
     }
     if (has_some_cat_specific_permission(get_member(), 'bypass_validation_' . $this->permissions_require . 'range_content', NULL, $this->permissions_cat_require)) {
         if (addon_installed('unvalidated')) {
             $fields->attach(form_input_tick(do_lang_tempcode('VALIDATED'), do_lang_tempcode('DESCRIPTION_VALIDATED'), 'validated', $validated == 1));
         }
     }
     $fields2 = new ocp_tempcode();
     $fields2->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => true, 'TITLE' => do_lang_tempcode('ADVANCED'))));
     // More date stuff
     $list = '';
     foreach (get_timezone_list() as $_timezone => $timezone_nice) {
         $list .= static_evaluate_tempcode(form_input_list_entry($_timezone, $_timezone == $timezone, $timezone_nice));
     }
     $fields2->attach(form_input_list(do_lang_tempcode('EVENT_TIMEZONE'), do_lang_tempcode('DESCRIPTION_EVENT_TIMEZONE'), 'timezone', make_string_tempcode($list)));
     $fields2->attach(form_input_tick(do_lang_tempcode('DO_TIMEZONE_CONV'), do_lang_tempcode('DESCRIPTION_DO_TIMEZONE_CONV'), 'do_timezone_conv', $do_timezone_conv == 1));
     if (has_specific_permission(get_member(), 'add_public_events')) {
         $fields2->attach(form_input_tick(do_lang_tempcode('IS_PUBLIC'), do_lang_tempcode('DESCRIPTION_IS_PUBLIC'), 'is_public', $is_public == 1));
     }
     // Priority
     $priority_list = new ocp_tempcode();
     $priority_list->attach(form_input_list_entry('1', $priority == 1, do_lang_tempcode('PRIORITY_1')));
     $priority_list->attach(form_input_list_entry('2', $priority == 2, do_lang_tempcode('PRIORITY_2')));
     $priority_list->attach(form_input_list_entry('3', $priority == 3, do_lang_tempcode('PRIORITY_3')));
     $priority_list->attach(form_input_list_entry('4', $priority == 4, do_lang_tempcode('PRIORITY_4')));
     $priority_list->attach(form_input_list_entry('5', $priority == 5, do_lang_tempcode('PRIORITY_5')));
     $fields2->attach(form_input_list(do_lang_tempcode('PRIORITY'), '', 'priority', $priority_list));
     // Recurrence
     $fields2->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => true, 'TITLE' => do_lang_tempcode('RECURRENCE'))));
     if (strpos($recurrence, ' ') === false) {
         $recurrence_main = $recurrence;
         $recurrence_pattern = '';
     } else {
         list($recurrence_main, $recurrence_pattern) = explode(' ', $recurrence);
     }
     $radios = form_input_radio_entry('recurrence', 'none', true, do_lang_tempcode('NA_EM'));
     $radios->attach(form_input_radio_entry('recurrence', 'daily', $recurrence_main == 'daily', do_lang_tempcode('DAILY')));
     $radios->attach(form_input_radio_entry('recurrence', 'weekly', $recurrence_main == 'weekly', do_lang_tempcode('WEEKLY')));
     $radios->attach(form_input_radio_entry('recurrence', 'monthly', $recurrence_main == 'monthly', do_lang_tempcode('MONTHLY')));
     $radios->attach(form_input_radio_entry('recurrence', 'yearly', $recurrence_main == 'yearly', do_lang_tempcode('YEARLY')));
     $fields2->attach(form_input_radio(do_lang_tempcode('RECURRENCE'), do_lang_tempcode('DESCRIPTION_RECURRENCE'), 'recurrence', $radios));
     // xth_dotw_of_monthly
     $fields2->attach(form_input_line(do_lang_tempcode('RECURRENCE_PATTERN'), do_lang_tempcode('DESCRIPTION_RECURRENCE_PATTERN'), 'recurrence_pattern', $recurrence_pattern, false));
     $fields2->attach(form_input_integer(do_lang_tempcode('RECURRENCES'), do_lang_tempcode('DESCRIPTION_RECURRENCES'), 'recurrences', $recurrences, false));
     $fields2->attach(form_input_tick(do_lang_tempcode('SEG_RECURRENCES'), do_lang_tempcode('DESCRIPTION_SEG_RECURRENCES'), 'seg_recurrences', $seg_recurrences == 1));
     if ($adding && cron_installed()) {
         $fields2->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => true, 'TITLE' => do_lang_tempcode('REMINDERS'))));
         $fields2->attach(form_input_tick(do_lang_tempcode('SIGN_UP_REMINDER'), do_lang_tempcode('DESCRIPTION_SIGN_UP_REMINDER'), 'sign_up_reminder', true));
         if (has_specific_permission(get_member(), 'add_public_events')) {
             $usergroup_list = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true);
             if (get_forum_type() == 'ocf') {
                 unset($usergroup_list[db_get_first_id()]);
             }
             $t_usergroup_list = new ocp_tempcode();
             foreach ($usergroup_list as $id => $name) {
                 $t_usergroup_list->attach(form_input_list_entry(strval($id), false, $name));
             }
             $fields2->attach(form_input_all_and_not(do_lang_tempcode('SIGN_UP_REMINDER_GROUPS'), do_lang_tempcode('DESCRIPTION_SIGN_UP_REMINDER_GROUPS'), 'sign_up_reminder_groups', $t_usergroup_list));
         }
         $fields2->attach(form_input_float(do_lang_tempcode('REMINDER_TIME'), do_lang_tempcode('DESCRIPTION_REMINDER_TIME'), 'hours_before', 1.0, true));
     }
     require_code('feedback2');
     $fields2->attach(feedback_fields($allow_rating == 1, $allow_comments == 1, $allow_trackbacks == 1, false, $notes, $allow_comments == 2));
     $fields2->attach(get_syndication_option_fields());
     return array($fields, $hidden, NULL, NULL, true, NULL, $fields2);
 }
Esempio n. 14
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_lang('news');
     require_css('news');
     require_css('side_blocks');
     require_code('obfuscate');
     $url = array_key_exists('param', $map) ? $map['param'] : 'http://ocportal.com/backend.php?type=rss&mode=news&filter=16,17,18,19,20';
     // http://channel9.msdn.com/Feeds/RSS/
     if (strpos($url, '{') !== false) {
         require_code('tempcode_compiler');
         $url = static_evaluate_tempcode(template_to_tempcode($url));
     }
     $ticker = array_key_exists('ticker', $map) && $map['ticker'] == '1';
     require_code('rss');
     $rss = new rss($url);
     if (!is_null($rss->error)) {
         $GLOBALS['DO_NOT_CACHE_THIS'] = true;
         require_code('failure');
         if (strpos($url, 'twitter') === false) {
             // Twitter is always failing ;).
             relay_error_notification(do_lang('ERROR_HANDLING_RSS_FEED', $url, $rss->error), false, 'error_occurred_rss');
         }
         if (cron_installed()) {
             if (!$GLOBALS['FORUM_DRIVER']->is_staff(get_member())) {
                 return new ocp_tempcode();
             }
         }
         return do_template('INLINE_WIP_MESSAGE', array('MESSAGE' => htmlentities($rss->error)));
     }
     // Sorting
     $items = array();
     foreach ($rss->gleamed_items as $item) {
         if (!array_key_exists('clean_add_date', $item)) {
             $item['clean_add_date'] = time();
         }
         $items[] = $item;
     }
     global $M_SORT_KEY;
     $M_SORT_KEY = 'clean_add_date';
     usort($items, 'multi_sort');
     $items = array_reverse($items);
     global $NEWS_CATS;
     $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL));
     $NEWS_CATS = list_to_map('id', $NEWS_CATS);
     if (!array_key_exists('title', $rss->gleamed_feed)) {
         $rss->gleamed_feed['title'] = do_lang_tempcode('RSS_STREAM');
     }
     if (array_key_exists('title', $map)) {
         $rss->gleamed_feed['title'] = $map['title'];
     }
     // Reduce what we collected about the feed to a minimum. This is very awkward, as we don't know what's here.
     if (array_key_exists('author', $rss->gleamed_feed)) {
         $__author = NULL;
         $_author_string = $rss->gleamed_feed['author'];
         if (array_key_exists('url', $rss->gleamed_feed)) {
             $__author = hyperlink($rss->gleamed_feed['url'], escape_html($_author_string), true);
         } elseif (array_key_exists('author_url', $rss->gleamed_feed)) {
             $__author = hyperlink($rss->gleamed_feed['author_url'], escape_html($_author_string), true);
         } elseif (array_key_exists('author_email', $rss->gleamed_feed)) {
             $__author = hyperlink(mailto_obfuscated() . obfuscate_email_address($rss->gleamed_feed['author_email']), escape_html($_author_string), true);
         }
         if (!is_null($__author)) {
             $_author_string = $__author->evaluate();
         }
         $_author = do_lang_tempcode('RSS_SOURCE_FROM', $_author_string);
     } else {
         $_author = new ocp_tempcode();
     }
     if (!array_key_exists('copyright', $rss->gleamed_feed)) {
         $rss->gleamed_feed['copyright'] = '';
     }
     if (array_key_exists('copyright', $map)) {
         $rss->gleamed_feed['copyright'] = $map['copyright'];
     }
     // Now for the actual stream contents
     $max = array_key_exists('max_entries', $map) ? intval($map['max_entries']) : 5;
     $content = new ocp_tempcode();
     foreach ($items as $i => $item) {
         if ($i >= $max) {
             break;
         }
         if (array_key_exists('full_url', $item)) {
             $full_url = $item['full_url'];
         } elseif (array_key_exists('guid', $item)) {
             $full_url = $item['guid'];
         } elseif (array_key_exists('comment_url', $item)) {
             $full_url = $item['comment_url'];
         } else {
             $full_url = '';
         }
         $_title = $item['title'];
         $_title = array_key_exists('title', $item) ? $item['title'] : '';
         $date = array_key_exists('clean_add_date', $item) ? get_timezoned_date($item['clean_add_date']) : (array_key_exists('add_date', $item) ? $item['add_date'] : '');
         $content->attach(do_template('BLOCK_SIDE_RSS_SUMMARY', array('_GUID' => '18f6d1ccfe980cc01bbdd2ee178c2410', 'TICKER' => $ticker, 'FEED_URL' => $url, 'FULL_URL' => $full_url, 'NEWS_TITLE' => $_title, 'DATE' => $date, 'DATE_RAW' => array_key_exists('clean_add_date', $item) ? strval($item['clean_add_date']) : '', 'SUMMARY' => array_key_exists('news', $item) ? $item['news'] : (array_key_exists('news_article', $item) ? $item['news_article'] : ''))));
     }
     return do_template('BLOCK_SIDE_RSS', array('_GUID' => 'fe3319e942d75fedb83e4cf80f80e19f', 'TICKER' => $ticker, 'FEED_URL' => $url, 'TITLE' => $rss->gleamed_feed['title'], 'CONTENT' => $content));
 }
Esempio n. 15
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));
 }
Esempio n. 16
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_lang('news');
     require_css('news');
     require_code('obfuscate');
     $url = array_key_exists('param', $map) ? $map['param'] : 'http://ocportal.com/backend.php?type=rss&mode=news&filter=1,2,17,18,29,30';
     // http://news.google.co.uk/news?hs=UTT&tab=wn&topic=w&output=atom
     require_code('rss');
     $rss_feeds = array();
     $urls = preg_split('#\\s+#', $url);
     $error = NULL;
     foreach (array_reverse($urls) as $url) {
         $url = trim($url);
         if ($url == '') {
             continue;
         }
         $rss = new rss($url);
         if (!is_null($rss->error)) {
             $error = $rss->error;
             continue;
         }
         $rss_feeds[] = $rss;
     }
     if (!is_null($error) && count($rss_feeds) == 0) {
         $GLOBALS['DO_NOT_CACHE_THIS'] = true;
         require_code('failure');
         if (strpos($url, 'twitter') === false) {
             // Twitter is always failing ;).
             relay_error_notification(do_lang('ERROR_HANDLING_RSS_FEED', $url, $error), false, 'error_occurred_rss');
         }
         if (cron_installed()) {
             if (!$GLOBALS['FORUM_DRIVER']->is_staff(get_member())) {
                 return new ocp_tempcode();
             }
         }
         return do_template('INLINE_WIP_MESSAGE', array('MESSAGE' => htmlentities($error)));
     }
     global $NEWS_CATS;
     $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL));
     $NEWS_CATS = list_to_map('id', $NEWS_CATS);
     if (!array_key_exists('title', $rss->gleamed_feed)) {
         $rss->gleamed_feed['title'] = do_lang_tempcode('RSS_STREAM');
     }
     if (array_key_exists('title', $map)) {
         $rss->gleamed_feed['title'] = $map['title'];
     }
     // Reduce what we collected about the feed to a minimum. This is very awkward, as we don't know what's here.
     if (!array_key_exists('copyright', $rss->gleamed_feed)) {
         $rss->gleamed_feed['copyright'] = '';
     }
     if (array_key_exists('copyright', $map)) {
         $rss->gleamed_feed['copyright'] = $map['copyright'];
     }
     // Now for the actual stream contents
     $max = array_key_exists('max_entries', $map) ? intval($map['max_entries']) : 10;
     $content = new ocp_tempcode();
     $items = array();
     foreach ($rss_feeds as $_rss) {
         foreach ($_rss->gleamed_items as $item) {
             if (!array_key_exists('clean_add_date', $item)) {
                 $item['clean_add_date'] = time();
             }
             $items[] = $item;
         }
     }
     global $M_SORT_KEY;
     $M_SORT_KEY = 'clean_add_date';
     usort($items, 'multi_sort');
     $items = array_reverse($items);
     foreach ($items as $i => $item) {
         if ($i >= $max) {
             break;
         }
         if (array_key_exists('full_url', $item)) {
             $_full_url = $item['full_url'];
         } elseif (array_key_exists('guid', $item)) {
             $_full_url = $item['guid'];
         } elseif (array_key_exists('comment_url', $item)) {
             $_full_url = $item['comment_url'];
         } else {
             $_full_url = '';
         }
         $_title = $item['title'];
         $_title = array_key_exists('title', $item) ? $item['title'] : '';
         $full_url = $_full_url != '' ? hyperlink($_full_url, do_lang_tempcode('VIEW'), true, false, $_title) : new ocp_tempcode();
         if (array_key_exists('category', $rss->gleamed_items)) {
             $_title = do_template('BLOCK_MAIN_RSS_TITLE', array('_GUID' => 'd962c1165564f080329decffeab88ba7', 'CATEGORY' => $rss->gleamed_items['category'], 'TITLE' => $_title));
         }
         if (!array_key_exists('news', $item)) {
             $news = array_key_exists('news_article', $item) ? $item['news_article'] : '';
             $news_full = new ocp_tempcode();
         } else {
             $news = $item['news'];
             if (array_key_exists('news_article', $item)) {
                 $news_full = do_template('BLOCK_MAIN_RSS_FULL', array('_GUID' => 'adcd82c64966f54fb0173b8edc626bd7', 'RAND' => strval(mt_rand(0, 999999)), 'NEWS_FULL' => $item['news_article']));
             } else {
                 $news_full = new ocp_tempcode();
             }
         }
         if (array_key_exists('author', $item)) {
             $_author = $item['author'];
             if (array_key_exists('author_url', $item)) {
                 $__author = hyperlink($item['author_url'], escape_html($_author));
             } elseif (array_key_exists('author_email', $item)) {
                 $__author = hyperlink(protect_from_escaping(mailto_obfuscated() . (strpos($item['author_email'], '&') !== false ? $item['author_email'] : obfuscate_email_address($item['author_email']))), escape_html($_author));
             } else {
                 $__author = make_string_tempcode($_author);
             }
             $author = do_lang_tempcode('SUBMITTED_BY', $__author->evaluate());
         } else {
             $author = new ocp_tempcode();
         }
         // If we want to show in a tails arrangement (by default, we won't)
         if (!$author->is_empty()) {
             $tails = do_template('BLOCK_MAIN_RSS_LIST_FIRST', array('_GUID' => '5ce8a5f1fd8a9487c01b63e791618589', 'X' => $author));
             $tails->attach(do_template('BLOCK_MAIN_RSS_LIST_LAST', array('_GUID' => 'f199850d1b76cc4a6774731e1f89762e', 'X' => $full_url)));
         } else {
             $tails = new ocp_tempcode();
         }
         if (array_key_exists('category', $item)) {
             global $IMG_CODES;
             $cat = NULL;
             foreach ($NEWS_CATS as $_cat => $news_cat) {
                 if (get_translated_text($news_cat['nc_title']) == $item['category']) {
                     $cat = $_cat;
                 }
             }
             if (!is_null($cat)) {
                 $img = find_theme_image($NEWS_CATS[$cat]['nc_img']);
                 if (is_null($img)) {
                     $img = '';
                 }
                 if ($img != '' && url_is_local($img)) {
                     $img = get_custom_base_url() . '/' . $img;
                 }
                 $category = do_template('BLOCK_MAIN_RSS_CATEGORY', array('_GUID' => '9b70a0d7524b62ea74bdb8071f4e88b5', 'IMG' => $img, 'CATEGORY' => $item['category']));
             } else {
                 $category = do_template('BLOCK_MAIN_RSS_CATEGORY_NO_IMG', array('_GUID' => '772e44215bd2682e51a96b7480753ded', 'CATEGORY' => $item['category']));
             }
         } else {
             $category = new ocp_tempcode();
         }
         if (array_key_exists('add_date', $item)) {
             $__title = do_template('BLOCK_MAIN_RSS_FROM_TITLE', array('_GUID' => 'ba9d262682d2e7d74c393508c8d49dd6', 'FEED_URL' => $url, 'NEWS_TITLE' => $_title, 'DATE' => $item['add_date']));
         } else {
             $__title = $_title;
         }
         $content->attach(do_template('BLOCK_MAIN_RSS_SUMMARY', array('_GUID' => '9ca64090348263449ea1fcea75c8ed5f', 'FEED_URL' => $url, 'NEWS_FULL' => $news_full, 'DATE' => array_key_exists('add_date', $item) ? $item['add_date'] : '', 'DATE_RAW' => array_key_exists('clean_add_date', $item) ? strval($item['clean_add_date']) : '', 'TAILS' => $tails, 'AUTHOR' => $author, 'CATEGORY' => $category, 'FULL_URL' => $full_url, 'FULL_URL_RAW' => $_full_url, 'NEWS_TITLE' => $__title, 'NEWS' => $news)));
     }
     if (array_key_exists('author', $rss->gleamed_feed)) {
         $__author = NULL;
         $_author_string = $rss->gleamed_feed['author'];
         if (array_key_exists('url', $rss->gleamed_feed)) {
             $__author = hyperlink($rss->gleamed_feed['url'], escape_html($_author_string), true);
         } elseif (array_key_exists('author_url', $rss->gleamed_feed)) {
             $__author = hyperlink($rss->gleamed_feed['author_url'], escape_html($_author_string), true);
         } elseif (array_key_exists('author_email', $rss->gleamed_feed)) {
             $__author = hyperlink(mailto_obfuscated() . obfuscate_email_address($rss->gleamed_feed['author_email']), escape_html($_author_string), true);
         }
         if (!is_null($__author)) {
             $_author_string = $__author->evaluate();
         }
         $author = do_lang_tempcode('RSS_SOURCE_FROM', $_author_string);
     } else {
         $author = new ocp_tempcode();
     }
     return do_template('BLOCK_MAIN_RSS', array('_GUID' => '6c9c1287abff88fda881e3e25ef7b296', 'FEED_URL' => $url, 'TITLE' => $rss->gleamed_feed['title'], 'COPYRIGHT' => $rss->gleamed_feed['copyright'], 'AUTHOR' => $author, 'CONTENT' => $content));
 }