/** * Standard modular run function for newsletter hooks. * * @param TIME The time that the entries found must be newer than * @param LANGUAGE_NAME The language the entries found must be in * @param string Category filter to apply * @return array Tuple of result details */ function run($cutoff_time, $lang, $filter) { $new = new ocp_tempcode(); require_code('ocfiltering'); if ($filter == '') { $filter = ','; } // Just welcome zone $or_list = ocfilter_to_sqlfragment($filter, 'b.the_zone', NULL, NULL, NULL, NULL, false); $_rows = $GLOBALS['SITE_DB']->query('SELECT a.* FROM ' . get_table_prefix() . 'cached_comcode_pages a JOIN ' . get_table_prefix() . 'comcode_pages b ON a.the_page=b.the_page AND a.the_zone=b.the_zone WHERE p_add_date>' . strval($cutoff_time) . ' AND (' . $or_list . ')', 300); if (count($_rows) == 300) { return array(); } $rows = array(); foreach ($_rows as $row) { $rows[$row['the_zone'] . ':' . $row['the_page']] = $row; } $_rows2 = $GLOBALS['SITE_DB']->query_select('seo_meta', array('*'), array('meta_for_type' => 'comcode_page')); $rows2 = array(); foreach ($_rows2 as $row) { $rows2[$row['meta_for_id']] = $row; } $zones = explode(',', $filter); //find_all_zones(); foreach ($zones as $zone) { if ($zone == 'cms') { continue; } if ($zone == 'adminzone') { continue; } $pages = find_all_pages($zone, 'comcode_custom/' . get_site_default_lang(), 'txt', false, $cutoff_time); foreach (array_keys($pages) as $page) { if (!is_string($page)) { $page = strval($page); } // PHP can be weird when things like '404' are put in arrays if (substr($page, 0, 6) == 'panel_') { continue; } $id = $zone . ':' . $page; $_url = build_url(array('page' => $page), $zone, NULL, false, false, true); $url = $_url->evaluate(); $name = ucfirst(str_replace('_', ' ', $page)); if (array_key_exists($id, $rows)) { $_name = get_translated_text($rows[$id]['cc_page_title'], NULL, NULL, true); if (!is_null($_name)) { $name = $_name; } } $description = ''; $member_id = NULL; if (array_key_exists($id, $rows2)) { $description = get_translated_text($rows2[$id]['meta_description']); } $new->attach(do_template('NEWSLETTER_NEW_RESOURCE_FCOMCODE', array('_GUID' => '67f165847dacd54d2965686d561b57ee', 'MEMBER_ID' => $member_id, 'URL' => $url, 'NAME' => $name, 'DESCRIPTION' => $description))); } } return array($new, do_lang('PAGES', '', '', '', $lang)); }
/** * Helper function for *_text_file * * @param string The file name (without .txt) * @param ?LANGUAGE_NAME The language to load from (NULL: none) (blank: search) * @return string The path to the file */ function _find_text_file_path($codename, $lang) { if (is_null($lang)) { $langs = array(''); } elseif ($lang != '') { $langs = array($lang); } else { $langs = array(user_lang()); if (get_site_default_lang() != user_lang()) { $langs[] = get_site_default_lang(); } if (fallback_lang() != get_site_default_lang()) { $langs[] = fallback_lang(); } } $i = 0; $path = ''; do { $lang = $langs[$i]; $path = get_custom_file_base() . '/text_custom/' . $lang . '/' . $codename . '.txt'; if (!file_exists($path)) { $path = get_file_base() . '/text/' . $lang . '/' . $codename . '.txt'; } $i++; } while (!file_exists($path) && array_key_exists($i, $langs)); if (!file_exists($path)) { $path = ''; } return $path; }
/** * Find whether this preview hook applies. * * @return array A pair: The preview, the updated post Comcode */ function applies() { $member_id = get_param_integer('id', get_member()); $applies = get_param('page', '') == 'admin_ocf_welcome_emails'; if ($applies) { require_lang('ocf'); require_code('mail'); $subject_tag = post_param('subject'); $message_raw = do_template('NEWSLETTER_DEFAULT', array('CONTENT' => post_param('text'), 'LANG' => get_site_default_lang())); $to = $GLOBALS['FORUM_DRIVER']->get_member_email_address(get_member()); if ($to == '') { $to = get_option('staff_address'); } mail_wrap($subject_tag, $message_raw->evaluate(get_site_default_lang()), array($to), $GLOBALS['FORUM_DRIVER']->get_username(get_member()), '', '', 3, NULL, false, get_member(), true); } return array($applies, NULL); }
function setUp() { parent::setUp(); require_code('calendar2'); require_code('feedback'); require_code('ocf_posts_action'); require_code('ocf_forum_driver_helper'); require_lang('lang'); $this->event_id = add_calendar_event(8, '1', NULL, 0, 'test_event', '', 3, 1, 2010, 1, 10, 10, 15, 2010, NULL, 1, 1, 19, NULL, 1, 1, 1, 1, 1, '', NULL, 0, NULL, NULL, NULL); if ('test_event' == get_translated_text($GLOBALS['SITE_DB']->query_value('calendar_events', 'e_title ', array('id' => $this->event_id)))) { $lang_id = insert_lang_comcode('test_comment_desc_1', 4, $GLOBALS['FORUM_DB']); $map = array('p_title' => 'test_comment1', 'p_post' => $lang_id, 'p_ip_address' => '127.0.0.1', 'p_time' => time(), 'p_poster' => 0, 'p_poster_name_if_guest' => '', 'p_validated' => 1, 'p_topic_id' => 4, 'p_is_emphasised' => 0, 'p_cache_forum_id' => 4, 'p_last_edit_time' => NULL, 'p_last_edit_by' => NULL, 'p_intended_solely_for' => NULL, 'p_skip_sig' => 0, 'p_parent_id' => NULL); $this->post_id = $GLOBALS['FORUM_DB']->query_insert('f_posts', $map, true); } $rows = $GLOBALS['FORUM_DB']->query('SELECT p_title FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'f_posts p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON t.id=p.p_post WHERE t.text_original NOT LIKE \'%' . db_encode_like(do_lang('SPACER_POST_MATCHER', '', '', '', get_site_default_lang()) . '%') . '\' AND ( p.id = ' . strval($this->post_id) . ') ORDER BY p.id'); $title = $rows[0]['p_title']; // Test the forum was actually created $this->assertTrue('test_comment1' == $title); }
/** * Get the products handled by this eCommerce hook. * * IMPORTANT NOTE TO PROGRAMMERS: This function may depend only on the database, and not on get_member() or any GET/POST values. * Such dependencies will break IPN, which works via a Guest and no dependable environment variables. It would also break manual transactions from the Admin Zone. * * @param boolean Whether to make sure the language for item_name is the site default language (crucial for when we read/go to third-party sales systems and use the item_name as a key). * @param ?ID_TEXT Product being searched for (NULL: none). * @param boolean Whether $search refers to the product name rather than the product_id. * @return array A map of product name to list of product details. */ function get_products($site_lang = false, $search = NULL, $search_titles_not_ids = false) { $products = array(); require_lang('shopping'); if (function_exists('set_time_limit')) { @set_time_limit(0); } if (!is_null($search)) { $where = '1=1'; if (!$search_titles_not_ids) { $l = do_lang('CART_ORDER', '', NULL, NULL, $site_lang ? get_site_default_lang() : user_lang()); if (substr($search, 0, strlen($l)) != $l) { return array(); } $where .= ' AND id=' . strval(intval(substr($search, strlen($l)))); } } else { $where = '(' . db_string_equal_to('order_status', 'ORDER_STATUS_awaiting_payment') . ' OR ' . db_string_equal_to('order_status', 'ORDER_STATUS_payment_received') . ')'; } if (is_null($search)) { $count = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'shopping_order WHERE ' . $where); if ($count > 50) { return array(); } // Too many to list } $start = 0; do { $orders = $GLOBALS['SITE_DB']->query('SELECT id,tot_price FROM ' . get_table_prefix() . 'shopping_order WHERE ' . $where, 500); foreach ($orders as $order) { $products[do_lang('CART_ORDER', strval($order['id']), NULL, NULL, $site_lang ? get_site_default_lang() : user_lang())] = array(PRODUCT_ORDERS, $order['tot_price'], 'handle_product_orders', array(), do_lang('CART_ORDER', strval($order['id']), NULL, NULL, $site_lang ? get_site_default_lang() : user_lang())); } $start += 500; } while (count($orders) == 500); return $products; }
/** * The UI to translate code. * * @return tempcode The UI */ function interface_code() { $lang = filter_naughty_harsh(get_param('lang', '')); $lang_new = get_param('lang_new', $lang); if ($lang_new != '') { require_code('type_validation'); if (!is_alphanumeric($lang_new, true)) { warn_exit(do_lang_tempcode('BAD_CODENAME')); } if (strlen($lang_new) > 5) { warn_exit(do_lang_tempcode('INVALID_LANG_CODE')); } $lang = $lang_new; } if ($lang == '') { $title = get_page_title('TRANSLATE_CODE'); $GLOBALS['HELPER_PANEL_TEXT'] = comcode_lang_string('DOC_FIND_LANG_STRING_TIP'); return $this->choose_lang($title, true, true, do_lang_tempcode('CHOOSE_EDIT_LIST_LANG_FILE')); } breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('CHOOSE')))); breadcrumb_set_self(do_lang_tempcode('TRANSLATE_CODE')); $base_lang = fallback_lang(); $map_a = get_file_base() . '/lang/langs.ini'; $map_b = get_custom_file_base() . '/lang_custom/langs.ini'; $search = get_param('search', '', true); if ($search != '') { $title = get_page_title('TRANSLATE_CODE'); require_code('form_templates'); $fields = new ocp_tempcode(); global $LANGUAGE; foreach ($LANGUAGE[user_lang()] as $key => $value) { if (strpos(strtolower($value), strtolower($search)) !== false) { $fields->attach(form_input_text($key, '', 'l_' . $key, str_replace('\\n', chr(10), $value), false)); } } if ($fields->is_empty()) { inform_exit(do_lang_tempcode('NO_ENTRIES')); } $post_url = build_url(array('page' => '_SELF', 'type' => '_code2'), '_SELF'); $hidden = new ocp_tempcode(); $hidden->attach(form_input_hidden('redirect', get_self_url(true))); $hidden->attach(form_input_hidden('lang', $lang)); return do_template('FORM_SCREEN', array('_GUID' => '2d7356fd2c4497ceb19450e65331c9c5', 'TITLE' => $title, 'HIDDEN' => $hidden, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => '', 'SUBMIT_NAME' => do_lang('TRANSLATE_CODE'))); } $lang_file = get_param('lang_file'); if (!file_exists($map_b)) { $map_b = $map_a; } $map = better_parse_ini_file($map_b); $title = get_page_title('_TRANSLATE_CODE', true, array(escape_html($lang_file), escape_html(array_key_exists($lang, $map) ? $map[$lang] : $lang))); // Upgrade to custom if not there yet (or maybe we are creating a new lang - same difference) $custom_dir = get_custom_file_base() . '/lang_custom/' . $lang; if (!file_exists($custom_dir)) { require_code('abstract_file_manager'); force_have_afm_details(); afm_make_directory('lang_custom/' . $lang, true); $cached_dir = get_custom_file_base() . '/lang_cached/' . $lang; if (!file_exists($cached_dir)) { afm_make_directory('lang_cached/' . $lang, true); } // Make comcode page dirs $zones = find_all_zones(); foreach ($zones as $zone) { $_special_dir = get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang; if (!file_exists($_special_dir)) { afm_make_directory($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang, true); } $_special_dir = get_custom_file_base() . '/' . $zone . '/pages/html_custom/' . $lang; if (!file_exists($_special_dir)) { afm_make_directory($zone . ($zone == '' ? '' : '/') . 'pages/html_custom/' . $lang, true); } } // Make templates_cached dirs require_code('themes2'); $themes = find_all_themes(); foreach (array_keys($themes) as $theme) { $_special_dir = get_custom_file_base() . '/themes/' . $theme . '/templates_cached/' . $lang; if (!file_exists($_special_dir)) { afm_make_directory('themes/' . $theme . '/templates_cached/' . $lang, true); } } } // Get some stuff $for_lang = get_lang_file_map($lang, $lang_file); $for_base_lang = get_lang_file_map($base_lang, $lang_file, true); $descriptions = get_lang_file_descriptions($base_lang, $lang_file); // Make our translation page $lines = ''; $intertrans = $this->get_intertran_conv($lang); $actions = new ocp_tempcode(); $next = 0; $trans_lot = ''; $delimit = chr(10) . '=-=-=-=-=-=-=-=-' . chr(10); foreach ($for_base_lang as $name => $old) { if (array_key_exists($name, $for_lang)) { $current = $for_lang[$name]; } else { $current = ''; //$this->find_lang_matches($old,$lang); Too slow / useless for code translation } if ($current == '' && strtolower($name) != $name) { $trans_lot .= str_replace('\\n', chr(10), str_replace(array('{', '}'), array('(((', ')))'), $old)) . $delimit; } } $translated_stuff = array(); if ($trans_lot != '' && $intertrans != '') { $result = http_download_file('http://translate.google.com/translate_t', NULL, false, false, 'ocPortal', array('text' => $trans_lot, 'langpair' => 'en|' . $intertrans)); if (!is_null($result)) { require_code('character_sets'); $result = convert_to_internal_encoding($result); $matches = array(); if (preg_match('#<div id=result_box dir="ltr">(.*)</div>#Us', convert_to_internal_encoding($result), $matches) != 0) { $result2 = $matches[1]; $result2 = @html_entity_decode($result2, ENT_QUOTES, get_charset()); $result2 = preg_replace('#\\s?<br>\\s?#', chr(10), $result2); $result2 = str_replace('> ', '>', str_replace(' <', ' <', str_replace('</ ', '</', str_replace(array('(((', ')))'), array('{', '}'), $result2)))); $translated_stuff = explode(trim($delimit), $result2 . chr(10)); } } } foreach ($for_base_lang + $for_lang as $name => $old) { if (array_key_exists($name, $for_lang)) { $current = $for_lang[$name]; } else { $current = ''; //$this->find_lang_matches($old,$lang); Too slow / useless for code translation } $description = array_key_exists($name, $descriptions) ? $descriptions[$name] : ''; if ($current == '' && strtolower($name) != $name && array_key_exists($next, $translated_stuff)) { $_current = ''; $translate_auto = trim($translated_stuff[$next]); $next++; } else { $_current = str_replace('\\n', chr(10), $current); $translate_auto = NULL; } if ($_current == '') { $_current = str_replace('\\n', chr(10), $old); } if ($intertrans != '' && get_value('google_translate_api_key') !== NULL) { $actions = do_template('TRANSLATE_ACTION', array('_GUID' => '9e9a68cb2c1a1e23a901b84c9af2280b', 'LANG_FROM' => get_site_default_lang(), 'LANG_TO' => $lang, 'NAME' => 'trans_' . $name, 'OLD' => $_current)); } $temp = do_template('TRANSLATE_LINE', array('_GUID' => '9cb331f5852ee043e6ad30b45aedc43b', 'TRANSLATE_AUTO' => $translate_auto, 'DESCRIPTION' => $description, 'NAME' => $name, 'OLD' => str_replace('\\n', chr(10), $old), 'CURRENT' => $_current, 'ACTIONS' => $actions)); $lines .= $temp->evaluate(); } $url = build_url(array('page' => '_SELF', 'type' => '_code', 'lang_file' => $lang_file, 'lang' => $lang), '_SELF'); return do_template('TRANSLATE_SCREEN', array('_GUID' => 'b3429f8bd0b4eb79c33709ca43e3207c', 'PAGE' => $lang_file, 'INTERTRANS' => get_value('google_translate_api_key') !== NULL ? $intertrans : '', 'LANG' => $lang, 'LINES' => $lines, 'TITLE' => $title, 'URL' => $url)); }
/** * The UI to confirm sending of our newsletter. * * @return tempcode The UI */ function confirm_send() { $title = get_page_title('NEWSLETTER_SEND'); $message = post_param('message'); $subject = post_param('subject'); $lang = choose_language($title); $template = post_param('template', 'MAIL'); $in_full = post_param_integer('in_full', 0); $html_only = post_param_integer('html_only', 0); $from_email = post_param('from_email', ''); $from_name = post_param('from_name', ''); $extra_post_data = array(); require_code('uploads'); if (is_swf_upload(true) && array_key_exists('file', $_FILES) || array_key_exists('file', $_FILES) && is_uploaded_file($_FILES['file']['tmp_name'])) { $_csv_data = array(); $myfile = fopen($_FILES['file']['tmp_name'], 'rt'); $del = ','; $csv_test_line = fgetcsv($myfile, 4096, $del); if (count($csv_test_line) == 1 && strpos($csv_test_line[0], ';') !== false) { $del = ';'; } rewind($myfile); while (($csv_line = fgetcsv($myfile, 4096, $del)) !== false) { $_csv_data[] = $csv_line; } fclose($myfile); $extra_post_data['csv_data'] = serialize($_csv_data); } if (post_param_integer('make_periodic', 0) == 1) { // We're making a periodic newsletter. Thus we need to pass this info // through to the next step $extra_post_data['make_periodic'] = '1'; // Re-generate preview from latest chosen_categories $message = $this->generate_whats_new_comcode(post_param('chosen_categories', ''), $in_full, $lang, get_input_date('cutoff')); } $address = $GLOBALS['FORUM_DRIVER']->get_member_email_address(get_member()); if ($address == '') { $address = get_option('staff_address'); } $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member()); $message = newsletter_variable_substitution($message, $subject, '', '', do_lang('UNKNOWN'), $address, 'test', ''); require_code('mail'); require_code('tempcode_compiler'); $in_html = false; if (strpos($message, '<html') !== false) { $_preview = template_to_tempcode($message); $in_html = true; } else { $comcode_version = comcode_to_tempcode($message, get_member(), true); $_preview = do_template('MAIL', array('TITLE' => $subject, 'CSS' => css_tempcode(true, true, $comcode_version->evaluate()), 'LANG' => get_site_default_lang(), 'LOGOURL' => get_logo_url(''), 'CONTENT' => $comcode_version), NULL, false, NULL, '.tpl', 'templates', $GLOBALS['FORUM_DRIVER']->get_theme('')); $in_html = $html_only == 1; } $text_preview = $html_only == 1 ? '' : comcode_to_clean_text(static_evaluate_tempcode(template_to_tempcode($message))); require_code('mail'); $preview_subject = $subject; if (post_param_integer('make_periodic', 0) == 1) { $preview_subject .= ' - ' . get_timezoned_date(time(), false, false, false, true); } require_code('comcode_text'); $preview = do_template('NEWSLETTER_CONFIRM_WRAP', array('_GUID' => '02bd5a782620141f8589e647e2c6d90b', 'TEXT_PREVIEW' => $text_preview, 'PREVIEW' => $_preview, 'SUBJECT' => $subject)); mail_wrap($preview_subject, $html_only == 1 ? $_preview->evaluate() : $message, array($address), $username, $from_email, $from_name, 3, NULL, true, NULL, true, $in_html); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MANAGE_NEWSLETTER')), array('_SELF:_SELF:new', do_lang_tempcode('NEWSLETTER_SEND')))); breadcrumb_set_self(do_lang_tempcode('CONFIRM')); require_code('templates_confirm_screen'); return form_confirm_screen($title, $preview, 'send', get_param('old_type', 'new'), $extra_post_data); }
/** * Makes a post in the specified forum, in the specified topic according to the given specifications. If the topic doesn't exist, it is created along with a spacer-post. * Spacer posts exist in order to allow staff to delete the first true post in a topic. Without spacers, this would not be possible with most forum systems. They also serve to provide meta information on the topic that cannot be encoded in the title (such as a link to the content being commented upon). * * @param object Link to the real forum driver * @param SHORT_TEXT The forum name * @param SHORT_TEXT The topic identifier (usually <content-type>_<content-id>) * @param MEMBER The member ID * @param LONG_TEXT The post title * @param LONG_TEXT The post content in Comcode format * @param string The topic title; must be same as content title if this is for a comment topic * @param string This is put together with the topic identifier to make a more-human-readable topic title or topic description (hopefully the latter and a $content_title title, but only if the forum supports descriptions) * @param ?URLPATH URL to the content (NULL: do not make spacer post) * @param ?TIME The post time (NULL: use current time) * @param ?IP The post IP address (NULL: use current members IP address) * @param ?BINARY Whether the post is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). This only works with the OCF driver. * @param ?BINARY Whether the topic is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). This only works with the OCF driver. * @param boolean Whether to skip post checks * @param SHORT_TEXT The name of the poster * @param ?AUTO_LINK ID of post being replied to (NULL: N/A) * @param boolean Whether the reply is only visible to staff * @param ?ID_TEXT DO NOT send notifications to: The notification code (NULL: no restriction) * @param ?SHORT_TEXT DO NOT send notifications to: The category within the notification code (NULL: none / no restriction) * @return array Topic ID (may be NULL), and whether a hidden post has been made */ function _helper_make_post_forum_topic($this_ref, $forum_name, $topic_identifier, $member_id, $post_title, $post, $content_title, $topic_identifier_encapsulation_prefix, $content_url, $time, $ip, $validated, $topic_validated, $skip_post_checks, $poster_name_if_guest, $parent_id, $staff_only, $no_notify_for__notification_code, $no_notify_for__code_category) { if (is_null($time)) { $time = time(); } if (is_null($ip)) { $ip = get_ip_address(); } require_code('comcode_check'); check_comcode($post, NULL, false, NULL, true); require_code('ocf_topics'); require_code('ocf_posts'); //require_code('ocf_forums'); require_lang('ocf'); require_code('ocf_posts_action'); require_code('ocf_posts_action2'); if (!is_integer($forum_name)) { $forum_id = $this_ref->forum_id_from_name($forum_name); if (is_null($forum_id)) { warn_exit(do_lang_tempcode('MISSING_FORUM', escape_html($forum_name))); } } else { $forum_id = (int) $forum_name; } $topic_id = $this_ref->find_topic_id_for_topic_identifier($forum_name, $topic_identifier); $update_caching = false; $support_attachments = false; if (!running_script('stress_test_loader') && get_page_name() != 'admin_import') { $update_caching = true; $support_attachments = true; } if (is_null($topic_id)) { $is_starter = true; require_code('ocf_topics_action'); $topic_id = ocf_make_topic($forum_id, $topic_identifier_encapsulation_prefix . ': #' . $topic_identifier, '', $topic_validated, 1, 0, 0, 0, NULL, NULL, false, 0, NULL, $content_url); if (strpos($topic_identifier, ':') !== false) { // Sync comment_posted ones to also monitor the forum ones; no need for opposite way as comment ones already trigger forum ones $start = 0; $max = 300; require_code('notifications'); $ob = _get_notification_ob_for_code('comment_posted'); do { list($members, $possibly_has_more) = $ob->list_members_who_have_enabled('comment_posted', $topic_identifier, NULL, $start, $max); foreach ($members as $to_member_id => $setting) { enable_notifications('ocf_topic', strval($topic_id), $to_member_id); } $start += $max; } while ($possibly_has_more); } // Make spacer post if (!is_null($content_url)) { $spacer_title = $content_title; $home_link = hyperlink($content_url, escape_html($content_title)); $spacer_post = '[semihtml]' . do_lang('SPACER_POST', $home_link->evaluate(), '', '', get_site_default_lang()) . '[/semihtml]'; ocf_make_post($topic_id, $spacer_title, $spacer_post, 0, true, 1, 0, do_lang('SYSTEM'), $ip, $time, db_get_first_id(), NULL, NULL, NULL, false, $update_caching, $forum_id, $support_attachments, $content_title, 0, NULL, false, false, false, false); $is_starter = false; } $is_new = true; } else { $is_starter = false; $is_new = false; } $GLOBALS['LAST_TOPIC_ID'] = $topic_id; $GLOBALS['LAST_TOPIC_IS_NEW'] = $is_new; if ($post == '') { return array(NULL, false); } ocf_check_post($post, $topic_id, $member_id); $poster_name = $poster_name_if_guest; if ($poster_name == '') { $poster_name = $this_ref->get_username($member_id); } $post_id = ocf_make_post($topic_id, $post_title, $post, 0, $is_starter, $validated, 0, $poster_name, $ip, $time, $member_id, $staff_only ? $GLOBALS['FORUM_DRIVER']->get_guest_id() : NULL, NULL, NULL, false, $update_caching, $forum_id, $support_attachments, $content_title, 0, NULL, false, $skip_post_checks, false, false, $parent_id); $GLOBALS['LAST_POST_ID'] = $post_id; if ($is_new) { // Broken cache now for the rest of this page view - fix by flushing global $TOPIC_IDENTIFIERS_TO_IDS; $TOPIC_IDENTIFIERS_TO_IDS = array(); } // Send out notifications $_url = build_url(array('page' => 'topicview', 'type' => 'findpost', 'id' => $post_id), 'forum', NULL, false, false, true, 'post_' . strval($post_id)); $url = $_url->evaluate(); ocf_send_topic_notification($url, $topic_id, $forum_id, $member_id, $is_new, $post, $content_title, NULL, false, $no_notify_for__notification_code, $no_notify_for__code_category); $is_hidden = false; if (!running_script('stress_test_loader') && get_page_name() != 'admin_import') { $validated_actual = $this_ref->connection->query_value('f_posts', 'p_validated', array('id' => $post_id)); if ($validated_actual == 0) { require_code('site'); attach_message(do_lang_tempcode('SUBMIT_UNVALIDATED'), 'inform'); $is_hidden = true; } } return array($topic_id, $is_hidden); }
/** * Get an array of topics in the given forum. Each topic is an array with the following attributes: * - id, the topic ID * - title, the topic title * - lastusername, the username of the last poster * - lasttime, the timestamp of the last reply * - closed, a Boolean for whether the topic is currently closed or not * - firsttitle, the title of the first post * - firstpost, the first post (only set if $show_first_posts was true) * * @param mixed The forum name or an array of forum IDs * @param integer The limit * @param integer The start position * @param integer The total rows (not a parameter: returns by reference) * @param SHORT_TEXT The topic title filter * @param boolean Whether to show the first posts * @param string The date key to sort by * @set lasttime firsttime * @param boolean Whether to limit to hot topics * @param SHORT_TEXT The topic description filter * @return ?array The array of topics (NULL: error) */ function show_forum_topics($name, $limit, $start, &$max_rows, $filter_topic_title = '', $show_first_posts = false, $date_key = 'lasttime', $hot = false, $filter_topic_description = '') { if (is_integer($name)) { $id_list = 'boardid=' . strval((int) $name); } elseif (!is_array($name)) { $id = $this->forum_id_from_name($name); if (is_null($id)) { return NULL; } $id_list = 'boardid=' . strval((int) $id); } else { $id_list = ''; foreach (array_keys($name) as $id) { if ($id_list != '') { $id_list .= ' OR '; } $id_list .= 'boardid=' . strval((int) $id); } if ($id_list == '') { return NULL; } } $topic_filter = $filter_topic_title != '' ? 'AND topic LIKE \'' . db_encode_like($filter_topic_title) . '\'' : ''; $rows = $this->connection->query('SELECT * FROM ' . $this->connection->get_table_prefix() . 'threads WHERE (' . $id_list . ') ' . $topic_filter . ' ORDER BY ' . ($date_key == 'lasttime' ? 'lastposttime' : 'starttime') . ' DESC', $limit, $start); $max_rows = $this->connection->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $this->connection->get_table_prefix() . 'threads WHERE (' . $id_list . ') ' . $topic_filter); $out = array(); foreach ($rows as $i => $r) { $out[$i] = array(); $out[$i]['id'] = $r['threadid']; $out[$i]['num'] = $r['replycount'] + 1; $out[$i]['title'] = $r['topic']; $out[$i]['description'] = $r['topic']; $out[$i]['firstusername'] = $r['starter']; $out[$i]['lastusername'] = $r['lastposter']; $out[$i]['firsttime'] = $r['starttime']; $out[$i]['lasttime'] = $r['lastposttime']; $out[$i]['closed'] = $r['closed'] == 1; $fp_rows = $this->connection->query('SELECT posttopic,message,userid FROM ' . $this->connection->get_table_prefix() . 'posts WHERE message NOT LIKE \'' . db_encode_like(do_lang('SPACER_POST', '', '', '', get_site_default_lang()) . '%') . '\' AND threadid=' . strval((int) $out[$i]['id']) . ' ORDER BY posttime', 1); if (!array_key_exists(0, $fp_rows)) { unset($out[$i]); continue; } $out[$i]['firsttitle'] = $fp_rows[0]['posttopic']; if ($show_first_posts) { global $LAX_COMCODE; $temp = $LAX_COMCODE; $LAX_COMCODE = true; $out[$i]['firstpost'] = comcode_to_tempcode($fp_rows[0]['message'], $fp_rows[0]['userid']); $LAX_COMCODE = $temp; } } if (count($out) != 0) { return $out; } return NULL; }
/** * Handle GET URLs requesting embedded media files. */ function handle_self_referencing_embedment() { // If this is self-referring to CSS or logo if (array_key_exists('type', $_GET)) { $type = $_GET['type']; if ($type == 'ajax_ftp_details') { header('Content-Type: text/plain'); if (!function_exists('ftp_connect')) { echo do_lang('NO_PHP_FTP'); exit; } $conn = false; $domain = trim(get_param('ftp_domain')); $port = 21; if (strpos($domain, ':') !== false) { list($domain, $_port) = explode(':', $domain, 2); $port = intval($_port); } if (function_exists('ftp_ssl_connect')) { $conn = @ftp_ssl_connect($domain, $port); } $ssl = $conn !== false; $username = get_param('ftp_username'); $password = get_param('ftp_password'); $ssl = $conn !== false; if ($ssl && !@ftp_login($conn, $username, $password)) { $conn = false; $ssl = false; } if ($conn === false) { $conn = ftp_connect($domain, $port); } if ($conn === false) { echo do_lang('NO_FTP_CONNECT'); exit; } if (!$ssl && !@ftp_login($conn, $username, $password)) { echo do_lang('NO_FTP_LOGIN', @strval($php_errormsg)); ftp_close($conn); exit; } $ftp_folder = get_param('ftp_folder'); if (substr($ftp_folder, -1) != '/') { $ftp_folder .= '/'; } if (!@ftp_chdir($conn, $ftp_folder)) { echo do_lang('NO_FTP_DIR', @strval($php_errormsg), '1'); ftp_close($conn); exit; } $files = @ftp_nlist($conn, '.'); if ($files === false) { $files = array(); if (@ftp_rename($conn, 'install.php', 'install.php')) { $files = array('install.php', 'data.ocp'); } } if (!in_array('install.php', $files)) { echo do_lang('NO_FTP_DIR', @strval($php_errormsg), '2'); } ftp_close($conn); exit; } if ($type == 'ajax_db_details') { header('Content-Type: text/plain'); global $SITE_INFO; if (!isset($SITE_INFO)) { $SITE_INFO = array(); } $SITE_INFO['db_type'] = get_param('db_type'); require_code('database'); if (get_param('db_site') == '') { $db = new database_driver(get_param('db_forums'), get_param('db_forums_host'), get_param('db_forums_user'), get_param('db_forums_password'), '', true); } else { $db = new database_driver(get_param('db_site'), get_param('db_site_host'), get_param('db_site_user'), get_param('db_site_password'), '', true); } $connection =& $db->connection_write; if (count($connection) > 4) { call_user_func_array(array($db->static_ob, 'db_get_connection'), $connection); } exit; } if ($type == 'logo') { header('Content-type: image/png'); if (!file_exists(get_file_base() . '/themes/default/images/' . get_site_default_lang() . '/logo/trimmed-logo.png')) { $out = file_array_get('themes/default/images/' . get_site_default_lang() . '/logo/trimmed-logo.png'); echo $out; } else { print file_get_contents(get_file_base() . '/themes/default/images/' . get_site_default_lang() . '/logo/trimmed-logo.png'); exit; } exit; } if ($type == 'contract') { header('Content-type: image/png'); if (!file_exists(get_file_base() . '/themes/default/images/contract.png')) { $out = file_array_get('themes/default/images/contract.png'); echo $out; } else { print file_get_contents(get_file_base() . '/themes/default/images/contract.png'); exit; } exit; } if ($type == 'expand') { header('Content-type: image/png'); if (!file_exists(get_file_base() . '/themes/default/images/expand.png')) { $out = file_array_get('themes/default/images/expand.png'); echo $out; } else { print file_get_contents(get_file_base() . '/themes/default/images/expand.png'); exit; } exit; } if (substr($type, 0, 15) == 'themes/default/') { header('Content-type: image/png'); if (!file_exists(get_file_base() . '/' . $type)) { $out = file_array_get(filter_naughty($type)); echo $out; } else { print file_get_contents(get_file_base() . '/' . filter_naughty($type)); exit; } exit; } if ($type == 'css') { header('Content-Type: text/css'); if (!file_exists(get_file_base() . '/themes/default/css/global.css')) { $file = file_array_get('themes/default/css/global.css'); } else { $file = file_get_contents(get_file_base() . '/themes/default/css/global.css', FILE_TEXT); } $file = preg_replace('#\\{\\$IMG;?\\,([^,\\}\']+)\\}#', 'install.php?type=themes/default/images/${1}.png', $file); require_code('tempcode_compiler'); $css = template_to_tempcode($file, 0, false, ''); $file = $css->evaluate(); print $file; exit; } if ($type == 'css_2') { header('Content-Type: text/css'); if (!file_exists(get_file_base() . '/themes/default/css/install.css')) { $file = file_array_get('themes/default/css/install.css'); echo $file; } else { $file = file_get_contents(get_file_base() . '/themes/default/css/install.css', FILE_TEXT); } $file = preg_replace('#\\{\\$IMG\\,([^,\\}\']+)\\}#', 'themes/default/images/${1}.png', $file); require_code('tempcode_compiler'); $css = template_to_tempcode($file, 0, false, ''); $file = $css->evaluate(); print $file; exit; } exit; } }
/** * Tests to see if something would evaluate to empty or not * * @return boolean Whether it is really empty */ function is_really_empty() { foreach ($this->bits as $bit) { if ($bit[1] == TC_KNOWN || $bit[1] == TC_SYMBOL && $bit[2] == 'PAGE_LINK') { if ($bit[2] != '') { return false; } } else { $bit_3 = $bit[3]; if ($bit_3 && $bit[1] != TC_DIRECTIVE) { foreach ($bit_3 as $i => $decode_bit) { if (is_object($decode_bit)) { $bit_3[$i] = $decode_bit->evaluate(); } } } $out = ecv(function_exists('get_site_default_lang') ? get_site_default_lang() : 'EN', array(), $bit[1], $bit[2], is_null($bit_3) ? array() : $bit_3); if ($out != '') { return false; } } } return true; }
/** * Dispatch a notification about a CEDI page * * @param AUTO_LINK The page ID * @param ID_TEXT The action type * @set ADD EDIT */ function dispatch_cedi_page_notification($page_id, $type) { $page_name = get_translated_text($GLOBALS['SITE_DB']->query_value('seedy_pages', 'title', array('id' => $page_id))); $_the_message = get_translated_text($GLOBALS['SITE_DB']->query_value('seedy_pages', 'description', array('id' => $page_id))); $_view_url = build_url(array('page' => 'cedi', 'type' => 'misc', 'id' => $page_id == db_get_first_id() ? NULL : $page_id), get_page_zone('cedi'), NULL, false, false, true); $view_url = $_view_url->evaluate(); $their_username = $GLOBALS['FORUM_DRIVER']->get_username(get_member()); $subject = do_lang($type . '_CEDI_PAGE_SUBJECT', $page_name, NULL, NULL, get_site_default_lang()); $message_raw = do_lang($type . '_CEDI_PAGE_BODY', comcode_escape($their_username), comcode_escape($page_name), array(comcode_escape($view_url), $_the_message), get_site_default_lang()); require_code('notifications'); dispatch_notification('cedi', strval($page_id), $subject, $message_raw); }
/** * Get all the image IDs (both already known, and those uncached) of a certain type (i.e. under a subdirectory). * * @param ID_TEXT The type of image (e.g. 'ocf_emoticons') * @param boolean Whether to search recursively; i.e. in subdirectories of the type subdirectory * @param ?object The database connection to work over (NULL: site db) * @param ?ID_TEXT The theme to search in, in addition to the default theme (NULL: current theme) * @param boolean Whether to only return directories (advanced option, rarely used) * @param boolean Whether to only return from the database (advanced option, rarely used) * @return array The list of image IDs */ function get_all_image_ids_type($type, $recurse = false, $db = NULL, $theme = NULL, $dirs_only = false, $db_only = false) { if (is_null($db)) { $db = $GLOBALS['SITE_DB']; } if (is_null($theme)) { $theme = $GLOBALS['FORUM_DRIVER']->get_theme(); } if (substr($type, 0, 4) == 'ocf_' && file_exists(get_file_base() . '/themes/default/images/avatars/index.html')) { $type = substr($type, 4); } if (substr($type, -1) == '/') { $type = substr($type, 0, strlen($type) - 1); } $ids = array(); if (!$db_only && ($db->connection_write == $GLOBALS['SITE_DB']->connection_write || $dirs_only || get_db_forums() == get_db_site())) { _get_all_image_ids_type($ids, get_file_base() . '/themes/default/images/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); _get_all_image_ids_type($ids, get_file_base() . '/themes/default/images/' . get_site_default_lang() . '/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); if ($theme != 'default') { _get_all_image_ids_type($ids, get_custom_file_base() . '/themes/' . $theme . '/images/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); _get_all_image_ids_type($ids, get_custom_file_base() . '/themes/' . $theme . '/images/' . get_site_default_lang() . '/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); } _get_all_image_ids_type($ids, get_file_base() . '/themes/default/images_custom/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); _get_all_image_ids_type($ids, get_file_base() . '/themes/default/images_custom/' . get_site_default_lang() . '/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); if ($theme != 'default') { _get_all_image_ids_type($ids, get_custom_file_base() . '/themes/' . $theme . '/images_custom/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); _get_all_image_ids_type($ids, get_custom_file_base() . '/themes/' . $theme . '/images_custom/' . get_site_default_lang() . '/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); } } if (!$dirs_only) { $query = 'SELECT DISTINCT id,path FROM ' . $db->get_table_prefix() . 'theme_images WHERE '; if (!$db_only) { $query .= 'path NOT LIKE \'' . db_encode_like('themes/default/images/%') . '\' AND ' . db_string_not_equal_to('path', 'themes/default/images/blank.gif') . ' AND '; } $query .= '(' . db_string_equal_to('theme', $theme) . ' OR ' . db_string_equal_to('theme', 'default') . ') AND id LIKE \'' . db_encode_like($type . '%') . '\' ORDER BY path'; $rows = $db->query($query); foreach ($rows as $row) { if ($row['path'] == '') { continue; } if (url_is_local($row['path']) && !file_exists((substr($row['path'], 0, 15) == 'themes/default/' ? get_file_base() : get_custom_file_base()) . '/' . rawurldecode($row['path']))) { continue; } if ($row['path'] != 'themes/default/images/blank.gif') { $ids[] = $row['id']; } else { $key = array_search($row['id'], $ids); if (is_integer($key)) { unset($ids[$key]); } } } } sort($ids); return array_unique($ids); }
/** * Get an array of topics in the given forum. Each topic is an array with the following attributes: * - id, the topic ID * - title, the topic title * - lastusername, the username of the last poster * - lasttime, the timestamp of the last reply * - closed, a Boolean for whether the topic is currently closed or not * - firsttitle, the title of the first post * - firstpost, the first post (only set if $show_first_posts was true) * * @param mixed The forum name or an array of forum IDs * @param integer The limit * @param integer The start position * @param integer The total rows (not a parameter: returns by reference) * @param SHORT_TEXT The topic title filter * @param boolean Whether to show the first posts * @param string The date key to sort by * @set lasttime firsttime * @param boolean Whether to limit to hot topics * @param SHORT_TEXT The topic description filter * @return ?array The array of topics (NULL: error) */ function show_forum_topics($name, $limit, $start, &$max_rows, $filter_topic_title = '', $show_first_posts = false, $date_key = 'lasttime', $hot = false, $filter_topic_description = '') { require_code('xhtml'); if (is_integer($name)) { $id_list = 'forum_id=' . strval((int) $name); } elseif (!is_array($name)) { if ($name == '<announce>' || is_null($name)) { $id_list = '(forum_id IS NULL)'; } else { $id = $this->forum_id_from_name($name); if (is_null($id)) { return NULL; } $id_list = 'forum_id=' . strval((int) $id); } } else { $id_list = ''; $id_list_2 = ''; foreach (array_keys($name) as $id) { if ($id_list != '') { $id_list .= ' OR '; } if (is_null($id) || $id == '') { $id_list .= '(forum_id IS NULL)'; } else { $id_list .= 'forum_id=' . strval((int) $id); } } if ($id_list == '') { return NULL; } } $topic_filter = $filter_topic_title != '' ? 'AND title LIKE \'' . db_encode_like($this->ipb_escape($filter_topic_title)) . '\'' : ''; if ($filter_topic_description != '') { $topic_filter .= ' AND description LIKE \'' . db_encode_like($this->ipb_escape($filter_topic_description)) . '\''; } $rows = $this->connection->query('SELECT * FROM ' . $this->connection->get_table_prefix() . 'topics WHERE (' . $id_list . ') ' . $topic_filter . ' ORDER BY ' . ($date_key == 'lasttime' ? 'last_post' : 'start_date') . ' DESC', $limit, $start); $max_rows = $this->connection->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $this->connection->get_table_prefix() . 'topics WHERE (' . $id_list . ') ' . $topic_filter); $emoticons_set_dir = $this->get_emo_dir(); $out = array(); foreach ($rows as $i => $r) { $out[$i] = array(); $out[$i]['id'] = $r['tid']; $out[$i]['num'] = $r['posts']; $out[$i]['title'] = $this->ipb_unescape($r['title']); $out[$i]['firstusername'] = $this->ipb_unescape($r['starter_name']); $out[$i]['lastusername'] = $this->ipb_unescape($r['last_poster_name']); $out[$i]['firstmemberid'] = $r['starter_id']; $out[$i]['lastmemberid'] = $r['last_poster_id']; $out[$i]['firsttime'] = $r['start_date']; $out[$i]['lasttime'] = $r['last_post']; $out[$i]['closed'] = $r['state'] == 'closed'; $fp_rows = $this->connection->query('SELECT * FROM ' . $this->connection->get_table_prefix() . 'posts WHERE post NOT LIKE \'' . db_encode_like(do_lang('SPACER_POST', '', '', '', get_site_default_lang()) . '%') . '\' AND topic_id=' . strval((int) $out[$i]['id']) . ' ORDER BY post_date', 1); if (!array_key_exists(0, $fp_rows)) { unset($out[$i]); continue; } $out[$i]['firsttitle'] = $this->ipb_unescape($fp_rows[0]['post_title']); if ($show_first_posts) { $post_id = $fp_rows[0]['pid']; $post = $fp_rows[0]['post']; if (array_key_exists('post_htmlstate', $fp_rows[0]) && $fp_rows[0]['post_htmlstate'] != 0) { if ($fp_rows[0]['post_htmlstate'] == 1) { $post = str_replace('<br />', '', $post); } $post = @html_entity_decode($post, ENT_QUOTES, get_charset()); } $post = preg_replace('#public/style_emoticons/<\\#EMO_DIR\\#>(.+?)\'#is', $emoticons_set_dir . '\\1\'', $post); $post = str_replace("class='quotetop'", "class='comcode_quote_h4'", $post); $post = str_replace("class='quotemain'", "class='comcode_quote_content'", $post); // Attachments $attachments = $this->connection->query_select('attachments', array('attach_member_id', 'attach_id', 'attach_file', 'attach_location', 'attach_thumb_location', 'attach_is_image', 'attach_filesize', 'attach_hits'), array('attach_post_key' => $fp_rows[0]['post_key'])); foreach ($attachments as $attachment) { if ($attachment['attach_thumb_location'] != '' || $attachment['attach_is_image'] == 0) { $url = get_forum_base_url() . '/index.php?act=Attach&type=post&id=' . $attachment['attach_id']; if ($attachment['attach_thumb_location'] != '') { $special = do_template('FORUM_ATTACHMENT_IMAGE_THUMB', array('_GUID' => '98a66462f270f53101c4c0a1b63f0bfc', 'FULL' => $url, 'URL' => get_forum_base_url() . '/uploads/' . $attachment['attach_thumb_location'])); } else { $special = do_template('FORUM_ATTACHMENT_LINK', array('_GUID' => '002a3220f35debbe567ce7a225aa221e', 'FULL' => $url, 'FILENAME' => $attachment['attach_file'], 'CLEAN_SIZE' => clean_file_size($attachment['attach_filesize']), 'NUM_DOWNLOADS' => integer_format($attachment['attach_hits']))); } } else { $special = do_template('FORUM_ATTACHMENT_IMAGE', array('_GUID' => '49dbf65cb5e20340a5ad4379ea6344c3', 'URL' => get_forum_base_url() . '/uploads/' . $attachment['attach_location'])); } // See if we have to place it somewhere special inside the post $old_post = $post; $post = str_replace('[attachmentid=' . $attachment['attach_id'] . ']', $special->evaluate(), $post); if ($old_post == $post) { $post .= $special->evaluate(); } } global $LAX_COMCODE; $end = 0; while (($pos = strpos($post, '[right]', $end)) !== false) { $e_pos = strpos($post, '[/right]', $pos); if ($e_pos === false) { break; } $end = $e_pos + strlen('[/right]'); $segment = substr($post, $pos, $end - $pos); $temp = $LAX_COMCODE; $LAX_COMCODE = true; $comcode = comcode_to_tempcode($segment, $r['starter_id']); $LAX_COMCODE = $temp; $post = substr($post, 0, $pos) . $comcode->evaluate() . substr($post, $end); } $temp = $LAX_COMCODE; $LAX_COMCODE = true; $out[$i]['firstpost'] = comcode_to_tempcode(xhtmlise_html($post), $r['starter_id'], false, 60, NULL, NULL, false, false, true); // Assumes HTML for posts $LAX_COMCODE = $temp; } } if (count($out) != 0) { return $out; } return NULL; }
/** * 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; }
/** * 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; }
/** * Load up a language file, compiling it (it's not cached yet). * * @param ID_TEXT The language file name * @param ?LANGUAGE_NAME The language (NULL: uses the current language) * @param ?string The language type (lang_custom, or custom) (NULL: normal priorities are used) * @set lang_custom custom * @param PATH Where we are cacheing too * @param boolean Whether to just return if there was a loading error * @return boolean Whether we FAILED to load */ function require_lang_compile($codename, $lang, $type, $cache_path, $ignore_errors = false) { global $LANGUAGE, $REQUIRE_LANG_LOOP, $LANG_LOADED_LANG; $desire_cache = function_exists('get_option') && (get_option('is_on_lang_cache', true) == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1) && get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache', NULL) !== 0; if ($desire_cache) { if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 0) { global $DECACHED_COMCODE_LANG_STRINGS; // Cleanup language strings if (!$DECACHED_COMCODE_LANG_STRINGS) { $DECACHED_COMCODE_LANG_STRINGS = true; $comcode_lang_strings = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => '!'), '', NULL, NULL, true); if (!is_null($comcode_lang_strings)) { $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => '!')); foreach ($comcode_lang_strings as $comcode_lang_string) { delete_lang($comcode_lang_string['string_index']); } } } } $load_target = array(); } else { $load_target =& $LANGUAGE[$lang]; } global $FILE_ARRAY; if (@is_array($FILE_ARRAY) && file_array_exists('lang/' . $lang . '/' . $codename . '.ini')) { $lang_file = 'lang/' . $lang . '/' . $codename . '.ini'; $file = file_array_get($lang_file); _get_lang_file_map($file, $load_target, NULL, true); $bad = true; } else { $bad = true; $dirty = false; // Load originals $lang_file = get_file_base() . '/lang/' . $lang . '/' . filter_naughty($codename) . '.ini'; if (file_exists($lang_file)) { _get_lang_file_map($lang_file, $load_target, NULL, false); $bad = false; } // Load overrides now if they are there if ($type != 'lang') { $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini'; if (!file_exists($lang_file) && get_file_base() != get_custom_file_base()) { $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini'; } if (!file_exists($lang_file)) { $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.po'; if (!file_exists($lang_file)) { $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '-' . strtolower($lang) . '.po'; } } } if ($type != 'lang' && file_exists($lang_file)) { _get_lang_file_map($lang_file, $load_target, NULL, false); $bad = false; $dirty = true; // Tainted from the official pack, so can't store server wide } // NB: Merge op doesn't happen in require_lang. It happens when do_lang fails and then decides it has to force a recursion to do_lang(xx,fallback_lang()) which triggers require_lang(xx,fallback_lang()) when it sees it's not loaded if ($bad && $lang != fallback_lang()) { require_lang($codename, fallback_lang(), $type, $ignore_errors); $REQUIRE_LANG_LOOP--; $fallback_cache_path = get_custom_file_base() . '/lang_cached/' . fallback_lang() . '/' . $codename . '.lcd'; if (file_exists($fallback_cache_path)) { require_code('files'); @copy($fallback_cache_path, $cache_path); fix_permissions($cache_path); } if (!array_key_exists($lang, $LANG_LOADED_LANG)) { $LANG_LOADED_LANG[$lang] = array(); } $LANG_LOADED_LANG[$lang][$codename] = 1; return $bad; } if ($bad) { if ($ignore_errors) { return true; } if ($codename != 'critical_error' || $lang != get_site_default_lang()) { fatal_exit(do_lang_tempcode('MISSING_LANG_FILE', escape_html($codename), escape_html($lang))); } else { critical_error('CRIT_LANG'); } } } if (is_null($GLOBALS['MEM_CACHE'])) { // Cache if ($desire_cache) { $file = @fopen($cache_path, 'wt'); // Will fail if cache dir missing .. e.g. in quick installer if ($file) { if (fwrite($file, serialize($load_target)) > 0) { // Success fclose($file); require_code('files'); fix_permissions($cache_path); } else { // Failure fclose($file); @unlink($cache_path); } } } } else { persistant_cache_set(array('LANG', $lang, $codename), $load_target, !$dirty); } if ($desire_cache) { $LANGUAGE[$lang] += $load_target; } return $bad; }
/** * Update the spacer post of a comment topic, after an edit. * * @param boolean Whether this resource allows comments (if not, this function does nothing - but it's nice to move out this common logic into the shared function) * @param ID_TEXT The type (download, etc) that this commenting is for * @param ID_TEXT The ID of the type that this commenting is for * @param mixed The URL to where the commenting will pass back to (to put into the comment topic header) (URLPATH or Tempcode) * @param ?string The title to where the commenting will pass back to (to put into the comment topic header) (NULL: don't know, but not first post so not important) * @param ?string The name of the forum to use (NULL: default comment forum) * @param ?AUTO_LINK ID of spacer post (NULL: unknown) */ function update_spacer_post($allow_comments, $content_type, $content_id, $content_url, $content_title, $forum = NULL, $post_id = NULL) { if (get_option('is_on_comments') == '0' || !$allow_comments) { return; } if (get_forum_type() != 'ocf') { return; } $home_link = is_null($content_title) ? new ocp_tempcode() : hyperlink($content_url, escape_html($content_title)); if (is_null($forum)) { $forum = get_option('comments_forum_name'); } if (!is_integer($forum)) { $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum); if (is_null($forum_id)) { return; } } else { $forum_id = (int) $forum; } $content_title = strip_comcode($content_title); if (is_null($post_id)) { $topic_id = $GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier($forum_id, $content_type . '_' . $content_id); if (is_null($topic_id)) { return; } $post_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_posts', 'MIN(id)', array('p_topic_id' => $topic_id)); if (is_null($post_id)) { return; } } else { $topic_id = $GLOBALS['FORUM_DB']->query_value('f_posts', 'p_topic_id', array('id' => $post_id)); } $spacer_title = is_null($content_title) ? $content_type . '_' . $content_id : $content_title . ' (#' . $content_type . '_' . $content_id . ')'; $spacer_post = '[semihtml]' . do_lang('SPACER_POST', $home_link->evaluate(), '', '', get_site_default_lang()) . '[/semihtml]'; if (get_forum_type() == 'ocf') { require_code('ocf_posts_action3'); ocf_edit_post($post_id, 1, is_null($content_title) ? $spacer_title : $content_title, $spacer_post, 0, 0, NULL, false, false, '', false); require_code('ocf_topics_action2'); ocf_edit_topic($topic_id, do_lang('COMMENT') . ': #' . $content_type . '_' . $content_id, NULL, NULL, NULL, NULL, NULL, NULL, '', NULL, $home_link->evaluate(), false); } }
/** * Standard modular UI to edit an entry. * * @return tempcode The UI */ function _ed() { $doing = 'EDIT_' . $this->lang_type; if ($this->catalogue && get_param('catalogue_name', '') != '') { $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title', array('c_name' => get_param('catalogue_name')))); if ($this->type_code == 'd') { $doing = do_lang('CATALOGUE_GENERIC_EDIT', escape_html($catalogue_title)); } elseif ($this->type_code == 'c') { $doing = do_lang('CATALOGUE_GENERIC_EDIT_CATEGORY', escape_html($catalogue_title)); } } $title = get_page_title($doing); //$submit_name=(strpos($doing,' ')!==false)?protect_from_escaping($doing):do_lang($doing); //if (!is_null($this->edit_submit_name)) $submit_name=$this->edit_submit_name; $submit_name = do_lang_tempcode('SAVE'); //$test=$this->choose_catalogue($title); //if (!is_null($test)) return $test; $id = mixed(); // Define type as mixed $id = $this->non_integer_id ? get_param('id', false, true) : strval(get_param_integer('id')); $map = array('page' => '_SELF', 'type' => '__e' . $this->type_code, 'id' => $id); if (get_param('catalogue_name', '') != '') { $map['catalogue_name'] = get_param('catalogue_name'); } if (!is_null(get_param('redirect', NULL))) { $map['redirect'] = get_param('redirect'); } if (!is_null(get_param('continue', NULL))) { $map['continue'] = get_param('continue'); } if (!is_null($this->upload) || $this->possibly_some_kind_of_upload) { $map['uploading'] = 1; } $post_url = build_url($map, '_SELF'); if (multi_lang() && has_actual_page_access(get_member(), 'admin_lang') && user_lang() != get_site_default_lang()) { require_code('lang2'); $switch_url = get_self_url(false, false, array('keep_lang' => get_site_default_lang())); attach_message(do_lang_tempcode('lang:EDITING_CONTENT_IN_LANGUAGE_STAFF', escape_html(lookup_language_full_name(user_lang())), escape_html(lookup_language_full_name(get_site_default_lang())), escape_html($switch_url->evaluate())), 'warn'); } if (method_exists($this, 'get_submitter')) { list($submitter, $date_and_time) = $this->get_submitter($id); } else { $submitter = NULL; $date_and_time = NULL; } if (!is_null($this->permissions_require)) { check_edit_permission($this->permissions_require, $submitter, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? NULL : $this->get_cat($id), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? NULL : $this->get_cat_b($id)), $this->permission_page_name); } if (!is_null($this->permissions_cat_require) && !has_category_access(get_member(), $this->permissions_cat_require, $this->get_cat($id))) { access_denied('CATEGORY_ACCESS'); } if (!is_null($this->permissions_cat_require_b) && !has_category_access(get_member(), $this->permissions_cat_require_b, $this->get_cat_b($id))) { access_denied('CATEGORY_ACCESS'); } $bits = $this->fill_in_edit_form($id); $delete_fields = new ocp_tempcode(); $all_delete_fields_given = false; $fields2 = new ocp_tempcode(); if (is_array($bits)) { $fields = $bits[0]; $hidden = $bits[1]; if (array_key_exists(2, $bits) && !is_null($bits[2])) { $delete_fields = $bits[2]; } if (array_key_exists(3, $bits) && !is_null($bits[3])) { $this->edit_text = $bits[3]; } if (array_key_exists(4, $bits) && $bits[4]) { $all_delete_fields_given = true; } if (array_key_exists(5, $bits) && !is_null($bits[5])) { $this->posting_form_text = $bits[5]; } if (array_key_exists(6, $bits) && !is_null($bits[6])) { $fields2 = $bits[6]; } if (array_key_exists(7, $bits)) { $this->posting_form_text_parsed = $bits[7]; } } else { $fields = $bits; $hidden = new ocp_tempcode(); } // Add in custom fields if ($this->has_tied_catalogue()) { require_code('fields'); $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('MORE')))); append_form_custom_fields($this->award_type, $id, $fields, $hidden); } // SEO? if (!is_null($this->seo_type)) { require_code('seo2'); $fields2->attach(seo_get_fields($this->seo_type, $id)); } // Awards? if (addon_installed('awards')) { if (!is_null($this->award_type)) { require_code('awards'); $fields2->attach(get_award_fields($this->award_type, $id)); } } // Action fields / deletion options $delete_permission = true; if (!is_null($this->permissions_require)) { $delete_permission = has_delete_permission($this->permissions_require, get_member(), $submitter, is_null($this->permission_page_name) ? get_page_name() : $this->permission_page_name, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? NULL : $this->get_cat($id), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? NULL : $this->get_cat_b($id))); } $may_delete = (!method_exists($this, 'may_delete_this') || $this->may_delete_this($id)) && (!is_numeric($id) || intval($id) >= db_get_first_id() + $this->protect_first) && $delete_permission; // Deletion options $action_fields = new ocp_tempcode(); if ($may_delete) { if (!$all_delete_fields_given) { $action_fields->attach(form_input_tick(do_lang_tempcode('DELETE'), do_lang_tempcode('DESCRIPTION_DELETE'), 'delete', false)); } if (addon_installed('points') && !is_null($submitter) && !is_null($date_and_time)) { $points_test = $GLOBALS['SITE_DB']->query_value_null_ok('gifts', 'id', array('date_and_time' => $date_and_time, 'gift_to' => $submitter, 'gift_from' => $GLOBALS['FORUM_DRIVER']->get_guest_id())); if (!is_null($points_test)) { require_lang('points'); $action_fields->attach(form_input_tick(do_lang_tempcode('REVERSE_TITLE'), do_lang_tempcode('REVERSE_TITLE_DESCRIPTION'), 'reverse_point_transaction', false)); } } $action_fields->attach($delete_fields); } if (!$this->appended_actions_already && !$action_fields->is_empty()) { $fields2->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('ACTIONS')))); } $fields2->attach($action_fields); if (!is_object($this->edit_text)) { $this->edit_text = make_string_tempcode(is_null($this->edit_text) ? '' : $this->edit_text); } if (!is_null($this->upload)) { if ($this->upload == 'image') { require_code('images'); $max = floatval(get_max_image_size()) / floatval(1024 * 1024); if ($max < 3.0) { require_code('files2'); $config_url = get_upload_limit_config_url(); $this->edit_text->attach(paragraph(do_lang_tempcode(is_null($config_url) ? 'MAXIMUM_UPLOAD' : 'MAXIMUM_UPLOAD_STAFF', escape_html($max > 10.0 ? integer_format(intval($max)) : float_format($max)), escape_html(is_null($config_url) ? '' : $config_url)))); } } else { require_code('files2'); $max = floatval(get_max_file_size()) / floatval(1024 * 1024); if ($max < 30.0) { $config_url = get_upload_limit_config_url(); $this->edit_text->attach(paragraph(do_lang_tempcode(is_null($config_url) ? 'MAXIMUM_UPLOAD' : 'MAXIMUM_UPLOAD_STAFF', escape_html($max > 10.0 ? integer_format(intval($max)) : float_format($max)), escape_html(is_null($config_url) ? '' : $config_url)))); } } } if (get_param('type', '_ed') == '_edit_catalogue') { require_javascript('javascript_catalogues'); // Existing fields $field_count = 0; $c_name = get_param('id', false, true); $rows = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $c_name), 'ORDER BY cf_order'); $fields_existing = new ocp_tempcode(); foreach ($rows as $i => $myrow) { $name = get_translated_text($myrow['cf_name']); $description = get_translated_text($myrow['cf_description']); $prefix = 'existing_field_' . strval($myrow['id']) . '_'; list($_fields_existing, $_fields_hidden) = $this->get_field_fields($i == 0 && substr($c_name, 0, 1) != '_', count($rows) + 10, $prefix, $field_count, $name, $description, $myrow['cf_type'], $myrow['cf_defines_order'], $myrow['cf_visible'], $myrow['cf_searchable'], $myrow['cf_default'], $myrow['cf_required'], $myrow['cf_put_in_category'], $myrow['cf_put_in_search']); if (!is_ecommerce_catalogue($c_name) || $i > 9) { $_fields_existing->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('ACTIONS')))); $_fields_existing->attach(form_input_tick(do_lang_tempcode('DELETE'), do_lang_tempcode('DESCRIPTION_DELETE'), $prefix . 'delete', false)); } $temp = do_template('FORM_FIELD_SET_GROUPER', array('_GUID' => '1492d973db45cbecff892ad4ac1af28f' . get_class($this), 'NAME' => $name, 'ID' => 'FIELD_' . strval($i + 1), 'FIELDS' => $_fields_existing->evaluate())); $fields_existing->attach($temp); $hidden->attach($_fields_hidden); $field_count++; } // New field $fields_new = new ocp_tempcode(); for ($i = 0; $i < 5; $i++) { list($_fields_new, $_fields_hidden) = $this->get_field_fields(false, count($rows) + 10, 'new_field_' . strval($i) . '_', $field_count); $temp = do_template('FORM_FIELD_SET_GROUPER', array('_GUID' => '8b9a632eafae003ccc6b007eefb0ce3d' . get_class($this), 'NAME' => do_lang_tempcode('NEW_FIELD', strval($i + 1)), 'ID' => 'NEW_FIELD_' . strval($i + 1), 'FIELDS' => $_fields_new->evaluate())); $fields_new->attach($temp); $hidden->attach($_fields_hidden); $field_count++; } $fields->attach($fields2); return do_template('CATALOGUE_EDITING_SCREEN', array('_GUID' => '584d7dc7c2c13939626102374f13f508' . get_class($this), 'HIDDEN' => $hidden, 'TITLE' => $title, 'TEXT' => $this->add_text, 'URL' => $post_url, 'FIELDS' => $fields->evaluate(), 'FIELDS_EXISTING' => $fields_existing->evaluate(), 'FIELDS_NEW' => $fields_new->evaluate(), 'SUBMIT_NAME' => $submit_name, 'JAVASCRIPT' => $this->javascript)); } list($warning_details, $ping_url) = handle_conflict_resolution(); if (!is_null($this->posting_form_title)) { $posting_form = get_posting_form($submit_name, $this->posting_form_text, $post_url, $hidden, $fields, $this->posting_form_title, '', $fields2, $this->posting_form_text_parsed, $this->javascript, NULL, $this->posting_field_required); return do_template('POSTING_SCREEN', array('_GUID' => '841b9af3aa80bcab86b907e4b942786a' . get_class($this), 'PREVIEW' => $this->do_preview, 'TITLE' => $title, 'SEPARATE_PREVIEW' => $this->second_stage_preview, 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'TEXT' => $this->add_text, 'POSTING_FORM' => $posting_form->evaluate(), 'JAVASCRIPT' => $this->javascript)); } else { $fields->attach($fields2); return do_template('FORM_SCREEN', array('_GUID' => '2d70be34595a16c6f170d966b894bfe2' . get_class($this), 'PREVIEW' => $this->do_preview, 'SEPARATE_PREVIEW' => $this->second_stage_preview, 'TITLE' => $title, 'SKIP_VALIDATION' => $this->skip_validation, 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'HIDDEN' => $hidden, 'TEXT' => $this->edit_text, 'URL' => $post_url, 'FIELDS' => $fields->evaluate(), 'SUBMIT_NAME' => $submit_name, 'JAVASCRIPT' => $this->javascript)); } }
/** * Send out booking mails. * * @param array Booking details structure. */ function send_booking_emails($request) { require_code('notifications'); // Send receipt to customer $customer_email = $GLOBALS['FORUM_DRIVER']->get_member_email_address(get_member()); $customer_name = $GLOBALS['FORUM_DRIVER']->get_username(get_member()); $receipt = do_template('BOOKING_CONFIRM_FCOMCODE', array('EMAIL_ADDRESS' => $customer_email, 'MEMBER_ID' => strval(get_member()), 'USERNAME' => $customer_name, 'PRICE' => float_format(find_booking_price($request)), 'DETAILS' => make_booking_request_printable($request))); dispatch_notification('booking_customer', NULL, do_lang('SUBJECT_BOOKING_CONFIRM', get_site_name()), static_evaluate_tempcode($receipt), array(get_member()), A_FROM_SYSTEM_PRIVILEGED); // Send notice to staff $notice = do_template('BOOKING_NOTICE_FCOMCODE', array('EMAIL_ADDRESS' => $customer_email, 'MEMBER_ID' => strval(get_member()), 'USERNAME' => $customer_name, 'PRICE' => float_format(find_booking_price($request)), 'DETAILS' => make_booking_request_printable($request)), get_site_default_lang()); dispatch_notification('booking_inform_staff', NULL, do_lang('SUBJECT_BOOKING_NOTICE', $GLOBALS['FORUM_DRIVER']->get_username(get_member()), get_site_name()), static_evaluate_tempcode($notice), NULL, NULL, 2); }
/** * Get an array of topics in the given forum. Each topic is an array with the following attributes: * - id, the topic ID * - title, the topic title * - lastusername, the username of the last poster * - lasttime, the timestamp of the last reply * - closed, a Boolean for whether the topic is currently closed or not * - firsttitle, the title of the first post * - firstpost, the first post (only set if $show_first_posts was true) * * @param mixed The forum name or an array of forum IDs * @param integer The limit * @param integer The start position * @param integer The total rows (not a parameter: returns by reference) * @param SHORT_TEXT The topic title filter * @param boolean Whether to show the first posts * @param string The date key to sort by * @set lasttime firsttime * @param boolean Whether to limit to hot topics * @param SHORT_TEXT The topic description filter * @return ?array The array of topics (NULL: error) */ function show_forum_topics($name, $limit, $start, &$max_rows, $filter_topic_title = '', $show_first_posts = false, $date_key = 'lasttime', $hot = false, $filter_topic_description = '') { if (is_integer($name)) { $id_list = 't_bid=' . strval((int) $name); } elseif (!is_array($name)) { $id = $this->forum_id_from_name($name); if (is_null($id)) { return NULL; } $id_list = 't_bid=' . strval((int) $id); } else { $id_list = ''; foreach (array_keys($name) as $id) { if ($id_list != '') { $id_list .= ' OR '; } $id_list .= 't_bid=' . strval((int) $id); } if ($id_list == '') { return NULL; } } $topic_filter = $filter_topic_title != '' ? 'AND topic LIKE \'' . db_encode_like($filter_topic_title) . '\'' : ''; if ($filter_topic_description != '') { $topic_filter .= ' AND t_description LIKE \'' . db_encode_like($filter_topic_description) . '\''; } $topic_filter .= ' ORDER BY ' . ($date_key == 'lasttime' ? 'last_post_id' : 'last_post_id') . ' DESC'; //there is no 'topic_time' or something like it, so we will sort by the 'last_post_id' field $rows = $this->connection->query('SELECT * FROM ' . $this->connection->get_table_prefix() . 'topics WHERE (' . $id_list . ') ' . $topic_filter, $limit, $start); $max_rows = $this->connection->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $this->connection->get_table_prefix() . 'topics WHERE (' . $id_list . ') ' . $topic_filter); $i = 0; $firsttime = array(); $username = array(); $memberid = array(); $datetimes = array(); $rs = array(); while (array_key_exists($i, $rows)) { $r = $rows[$i]; $id = $r['tid']; $topic_first_post_id = $r['first_post_id']; //because there is no info in topics for time we will use the first and last posts in the topic $topic_first_post_row = $this->connection->query('SELECT * FROM ' . $this->connection->get_table_prefix() . 'posts p WHERE pid=' . strval((int) $topic_first_post_id)); $topic_first_post_row = !empty($topic_first_post_row[0]) ? $topic_first_post_row[0] : array(); $topic_last_post_id = $r['last_post_id']; $topic_last_post_row = $this->connection->query('SELECT * FROM ' . $this->connection->get_table_prefix() . 'posts p WHERE pid=' . strval((int) $topic_last_post_id)); $topic_last_post_row = !empty($topic_last_post_row[0]) ? $topic_last_post_row[0] : array(); $r['topic_time'] = $topic_first_post_row['ptime']; $r['topic_poster'] = $topic_first_post_row['poster_id']; $r['last_poster'] = $topic_last_post_row['poster_id']; $r['last_time'] = $topic_last_post_row['ptime']; $firsttime[$id] = $topic_first_post_row['ptime']; $post_rows = $this->connection->query('SELECT * FROM ' . $this->connection->get_table_prefix() . 'posts p WHERE post_tid=' . strval((int) $id) . ' AND post NOT LIKE \'' . db_encode_like(substr(do_lang('SPACER_POST', '', '', '', get_site_default_lang()), 0, 20) . '%') . '\' ORDER BY ptime DESC', 1); if (!array_key_exists(0, $post_rows)) { $i++; continue; } $r2 = $post_rows[0]; $username[$id] = $this->get_username($r2['poster_id']); $username[$id] = $r2['poster_id']; $datetimes[$id] = $r2['ptime']; $rs[$id] = $r; $i++; } if ($i > 0) { arsort($datetimes); $i = 0; $out = array(); if (count($datetimes) > 0) { foreach ($datetimes as $id => $datetime) { $r = $rs[$id]; $out[$i] = array(); $out[$i]['id'] = $id; $out[$i]['num'] = $r['n_posts'] + 1; $out[$i]['title'] = $r['topic']; $out[$i]['description'] = $r['t_description']; $out[$i]['firsttime'] = $r['topic_time']; $out[$i]['firstusername'] = $this->get_username($r['topic_poster']); $out[$i]['lastusername'] = $this->get_username($r['last_poster']); //$username[$id]; $out[$i]['firstmemberid'] = $r['topic_poster']; $out[$i]['lastmemberid'] = $r['last_poster']; //$memberid[$id]; $out[$i]['lasttime'] = $r['last_time']; //$datetime; $out[$i]['closed'] = $r['t_status'] == 1; $fp_rows = $this->connection->query('SELECT post_title,post,poster_id FROM ' . $this->connection->get_table_prefix() . 'posts p WHERE post NOT LIKE \'' . db_encode_like(substr(do_lang('SPACER_POST', '', '', '', get_site_default_lang()), 0, 20) . '%') . '\' AND ptime=' . strval((int) $firsttime[$id]) . ' AND post_tid=' . strval((int) $id), 1); if (!array_key_exists(0, $fp_rows)) { unset($out[$i]); continue; } $out[$i]['firsttitle'] = $fp_rows[0]['post_title']; if ($show_first_posts) { global $LAX_COMCODE; $temp = $LAX_COMCODE; $LAX_COMCODE = true; $out[$i]['firstpost'] = $fp_rows[0]['post']; $LAX_COMCODE = $temp; } $i++; if ($i == $limit) { break; } } } return $out; } return NULL; }
/** * Standard stage of pointstore item purchase. * * @return tempcode The UI */ function ___text() { if (get_option('is_on_flagrant_buy') == '0') { return new ocp_tempcode(); } $title = get_page_title('TITLE_NEWTEXT'); // Define variables $member_id = get_member(); $message = post_param('message'); $days = post_param_integer('days'); $points_left = available_points($member_id); // First we need to know the price of the number of days we ordered. After that, compare that price with our users current number of points. $dayprice = intval(get_option('text')); $total = $dayprice * $days; if ($points_left < $total && !has_specific_permission(get_member(), 'give_points_self')) { return warn_screen($title, do_lang_tempcode('FLAGRANT_LACK_POINTS', integer_format($days), integer_format($total), integer_format($points_left))); } // Add this to the database $GLOBALS['SITE_DB']->query_insert('text', array('notes' => '', 'activation_time' => NULL, 'active_now' => 0, 'user_id' => $member_id, 'the_message' => insert_lang_comcode($message, 2), 'days' => $days, 'order_time' => time())); // Mail off the notice require_code('notifications'); $_url = build_url(array('page' => 'admin_flagrant'), 'adminzone', NULL, false, false, true); $manage_url = $_url->evaluate(); dispatch_notification('pointstore_request_flagrant', NULL, do_lang('TITLE_NEWTEXT', NULL, NULL, NULL, get_site_default_lang()), do_lang('MAIL_FLAGRANT_TEXT', $message, comcode_escape($manage_url), NULL, get_site_default_lang())); // Now, deduct the points from our user's account require_code('points2'); charge_member($member_id, $total, do_lang('PURCHASED_FLAGRANT')); $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF'); return redirect_screen($title, $url, do_lang_tempcode('ORDER_FLAGRANT_DONE')); }
/** * Get the products handled by this eCommerce hook. * * IMPORTANT NOTE TO PROGRAMMERS: This function may depend only on the database, and not on get_member() or any GET/POST values. * Such dependencies will break IPN, which works via a Guest and no dependable environment variables. It would also break manual transactions from the Admin Zone. * * @param boolean Whether to make sure the language for item_name is the site default language (crucial for when we read/go to third-party sales systems and use the item_name as a key). * @return array A map of product name to list of product details. */ function get_products($site_lang = false) { $products = array('WORK' => array(PRODUCT_INVOICE, '?', '', array(), do_lang('CUSTOM_PRODUCT_WORK', NULL, NULL, NULL, $site_lang ? get_site_default_lang() : user_lang()))); return $products; }
/** * The actualiser to edit a zone. * * @return tempcode The UI */ function __edit_zone() { $zone = post_param('zone'); $delete = post_param_integer('delete', 0); if ($delete == 1) { $title = get_page_title('DELETE_ZONE'); actual_delete_zone($zone); // Show it worked / Refresh $_url = build_url(array('page' => '_SELF', 'type' => 'edit'), '_SELF'); return redirect_screen($title, $_url, do_lang_tempcode('SUCCESS')); } else { $_title = post_param('title'); $default_page = post_param('default_page'); $header_text = post_param('header_text'); $theme = post_param('theme'); $wide = post_param_integer('wide'); if ($wide == -1) { $wide = NULL; } $require_session = post_param_integer('require_session', 0); $displayed_in_menu = post_param_integer('displayed_in_menu', 0); $new_zone = post_param('new_zone'); actual_edit_zone($zone, $_title, $default_page, $header_text, $theme, $wide, $require_session, $displayed_in_menu, $new_zone); if ($new_zone != '') { $this->set_permissions($new_zone); } $title = get_page_title('EDIT_ZONE'); // Get title late, as we might be changing the theme this title is got from // Handle logos if (addon_installed('zone_logos')) { require_code('themes2'); require_code('uploads'); $themes = find_all_themes(); foreach (array_keys($themes) as $theme) { $iurl = ''; if (is_swf_upload() || array_key_exists('logo_upload_' . $theme, $_FILES) && is_uploaded_file($_FILES['logo_upload_' . $theme]['tmp_name'])) { $urls = get_url('', 'logo_upload_' . $theme, 'themes/' . $theme . '/images_custom', 0, OCP_UPLOAD_IMAGE); $iurl = $urls[0]; } if ($iurl == '') { $theme_img_code = post_param('logo_select_' . $theme, ''); if ($theme_img_code == '') { continue; // Probably a theme was added half-way //warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD')); } $iurl = find_theme_image($theme_img_code, false, true, $theme); } $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => 'logo/' . $new_zone . '-logo', 'theme' => $theme, 'lang' => get_site_default_lang()), '', 1); $GLOBALS['SITE_DB']->query_insert('theme_images', array('id' => 'logo/' . $new_zone . '-logo', 'theme' => $theme, 'path' => $iurl, 'lang' => get_site_default_lang())); persistant_cache_delete('THEME_IMAGES'); } } // Show it worked / Refresh $url = get_param('redirect', NULL); if (is_null($url)) { $_url = build_url(array('page' => '_SELF', 'type' => 'edit'), '_SELF'); $url = $_url->evaluate(); } return redirect_screen($title, $url, do_lang_tempcode('SUCCESS')); } }
/** * Get an array of topics in the given forum. Each topic is an array with the following attributes: * - id, the topic ID * - title, the topic title * - lastusername, the username of the last poster * - lasttime, the timestamp of the last reply * - closed, a Boolean for whether the topic is currently closed or not * - firsttitle, the title of the first post * - firstpost, the first post (only set if $show_first_posts was true) * * @param mixed The forum name or an array of forum IDs * @param integer The limit * @param integer The start position * @param integer The total rows (not a parameter: returns by reference) * @param SHORT_TEXT The topic title filter * @param boolean Whether to show the first posts * @param string The date key to sort by * @set lasttime firsttime * @param boolean Whether to limit to hot topics * @param SHORT_TEXT The topic description filter * @return ?array The array of topics (NULL: error) */ function show_forum_topics($name, $limit, $start, &$max_rows, $filter_topic_title = '', $show_first_posts = false, $date_key = 'lasttime', $hot = false, $filter_topic_description = '') { if (is_integer($name)) { $id_list = 'forum_id=' . strval((int) $name); } elseif (!is_array($name)) { $id = $this->forum_id_from_name($name); if (is_null($id)) { return NULL; } $id_list = 'forum_id=' . strval((int) $id); } else { $id_list = ''; foreach (array_keys($name) as $id) { if ($id_list != '') { $id_list .= ' OR '; } $id_list .= 'forum_id=' . strval((int) $id); } if ($id_list == '') { return NULL; } } $topic_filter = $filter_topic_title != '' ? 'AND title LIKE \'' . db_encode_like($this->ipb_escape($filter_topic_title)) . '\'' : ''; $rows = $this->connection->query('SELECT * FROM ' . $this->connection->get_table_prefix() . 'topics WHERE (' . $id_list . ') ' . $topic_filter . ' ORDER BY ' . ($date_key == 'lasttime' ? 'last_post' : 'start_date') . ' DESC', $limit, $start); $max_rows = $this->connection->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $this->connection->get_table_prefix() . 'topics WHERE (' . $id_list . ') ' . $topic_filter); $out = array(); foreach ($rows as $i => $r) { $out[$i] = array(); $out[$i]['id'] = $r['tid']; $out[$i]['num'] = $r['posts']; $out[$i]['title'] = $this->ipb_unescape($r['title']); $out[$i]['description'] = $this->ipb_unescape($r['title']); $out[$i]['firstusername'] = $this->ipb_unescape($r['starter_name']); $out[$i]['lastusername'] = $this->ipb_unescape($r['last_poster_name']); $out[$i]['firstmemberid'] = $r['starter_id']; $out[$i]['lastmemberid'] = $r['last_poster_id']; $out[$i]['firsttime'] = $r['start_date']; $out[$i]['lasttime'] = $r['last_post']; $out[$i]['closed'] = $r['state'] == 'closed'; $fp_rows = $this->connection->query('SELECT post_title,post FROM ' . $this->connection->get_table_prefix() . 'posts WHERE post NOT LIKE \'' . db_encode_like(do_lang('SPACER_POST', '', '', '', get_site_default_lang()) . '%') . '\' AND topic_id=' . strval((int) $out[$i]['id']) . ' ORDER BY post_date', 1); if (!array_key_exists(0, $fp_rows)) { unset($out[$i]); continue; } $out[$i]['firsttitle'] = $this->ipb_unescape($fp_rows[0]['post_title']); if ($show_first_posts) { $out[$i]['firstpost'] = $fp_rows[0]['post']; // Assumes HTML for posts } } if (count($out) != 0) { return $out; } return NULL; }
/** * Get an array of topics in the given forum. Each topic is an array with the following attributes: * - id, the topic ID * - title, the topic title * - lastusername, the username of the last poster * - lasttime, the timestamp of the last reply * - closed, a Boolean for whether the topic is currently closed or not * - firsttitle, the title of the first post * - firstpost, the first post (only set if $show_first_posts was true) * * @param mixed The forum name or an array of forum IDs * @param integer The limit * @param integer The start position * @param integer The total rows (not a parameter: returns by reference) * @param SHORT_TEXT The topic title filter * @param boolean Whether to show the first posts * @param string The date key to sort by * @set lasttime firsttime * @param boolean Whether to limit to hot topics * @param SHORT_TEXT The topic description filter * @return ?array The array of topics (NULL: error) */ function show_forum_topics($name, $limit, $start, &$max_rows, $filter_topic_title = '', $show_first_posts = false, $date_key = 'lasttime', $hot = false, $filter_topic_description = '') { if (is_integer($name)) { $id_list = 'forum_id=' . strval((int) $name); } elseif (!is_array($name)) { $id = $this->forum_id_from_name($name); if (is_null($id)) { return NULL; } $id_list = 'forum_id=' . strval((int) $id); } else { $id_list = ''; foreach (array_keys($name) as $id) { if ($id_list != '') { $id_list .= ' OR '; } $id_list .= 'forum_id=' . strval((int) $id); } if ($id_list == '') { return NULL; } } $topic_filter = $filter_topic_title != '' ? 'AND topic_title LIKE \'' . db_encode_like($filter_topic_title) . '\'' : ''; $topic_filter .= ' ORDER BY ' . ($date_key == 'lasttime' ? 'topic_last_post_id' : 'topic_time') . ' DESC'; $rows = $this->connection->query('SELECT * FROM ' . $this->connection->get_table_prefix() . 'topics WHERE (' . $id_list . ') ' . $topic_filter, $limit, $start); $max_rows = $this->connection->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $this->connection->get_table_prefix() . 'topics WHERE (' . $id_list . ') ' . $topic_filter); $i = 0; $firsttime = array(); $username = array(); $memberid = array(); $datetimes = array(); $rs = array(); while (array_key_exists($i, $rows)) { $r = $rows[$i]; $id = $r['topic_id']; $firsttime[$id] = $r['topic_time']; $post_rows = $this->connection->query('SELECT * FROM ' . $this->connection->get_table_prefix() . 'posts p WHERE topic_id=' . strval((int) $id) . ' AND post_text NOT LIKE \'' . db_encode_like(substr(do_lang('SPACER_POST', '', '', '', get_site_default_lang()), 0, 20) . '%') . '\' ORDER BY post_time DESC', 1); if (!array_key_exists(0, $post_rows)) { $i++; continue; } $r2 = $post_rows[0]; $username[$id] = $this->get_username($r2['poster_id']); $memberid[$id] = $r2['poster_id']; $datetimes[$id] = $r2['post_time']; $rs[$id] = $r; $i++; } if ($i > 0) { arsort($datetimes); $i = 0; $out = array(); if (count($datetimes) > 0) { foreach ($datetimes as $id => $datetime) { $r = $rs[$id]; $out[$i] = array(); $out[$i]['id'] = $id; $out[$i]['num'] = $r['topic_replies_real'] + 1; $out[$i]['title'] = $r['topic_title']; $out[$i]['description'] = $r['topic_title']; $out[$i]['firsttime'] = $r['topic_time']; $out[$i]['firstusername'] = $this->get_username($r['topic_poster']); $out[$i]['lastusername'] = $username[$id]; $out[$i]['firstmemberid'] = $r['topic_poster']; $out[$i]['lastmemberid'] = $memberid[$id]; $out[$i]['lasttime'] = $datetime; $out[$i]['closed'] = $r['topic_status'] == 1; $fp_rows = $this->connection->query('SELECT post_subject,post_text,bbcode_uid,poster_id FROM ' . $this->connection->get_table_prefix() . 'posts p WHERE post_text NOT LIKE \'' . db_encode_like(substr(do_lang('SPACER_POST', '', '', '', get_site_default_lang()), 0, 20) . '%') . '\' AND post_time=' . strval((int) $firsttime[$id]) . ' AND topic_id=' . strval((int) $id), 1); if (!array_key_exists(0, $fp_rows)) { unset($out[$i]); continue; } $out[$i]['firsttitle'] = $fp_rows[0]['post_subject']; if ($show_first_posts) { global $LAX_COMCODE; $temp = $LAX_COMCODE; $LAX_COMCODE = true; $out[$i]['firstpost'] = comcode_to_tempcode($this->_cleanup_post($fp_rows[0]['bbcode_uid'], $fp_rows[0]['post_text']), $fp_rows[0]['poster_id']); $LAX_COMCODE = $temp; } $i++; if ($i == $limit) { break; } } } return $out; } return NULL; }
/** * Give a member some points, from another member. * * @param integer The amount being given * @param MEMBER The member receiving the points * @param MEMBER The member sending the points * @param SHORT_TEXT The reason for the gift * @param boolean Does the sender want to remain anonymous? * @param boolean Whether to send out an email about it */ function give_points($amount, $recipient_id, $sender_id, $reason, $anonymous = false, $send_email = true) { require_lang('points'); require_code('points'); $your_username = $GLOBALS['FORUM_DRIVER']->get_username($sender_id); $GLOBALS['SITE_DB']->query_insert('gifts', array('date_and_time' => time(), 'amount' => $amount, 'gift_from' => $sender_id, 'gift_to' => $recipient_id, 'reason' => insert_lang_comcode($reason, 4), 'anonymous' => $anonymous ? 1 : 0)); $sender_gift_points_used = point_info($sender_id); $sender_gift_points_used = array_key_exists('gift_points_used', $sender_gift_points_used) ? $sender_gift_points_used['gift_points_used'] : 0; $GLOBALS['FORUM_DRIVER']->set_custom_field($sender_id, 'gift_points_used', strval($sender_gift_points_used + $amount)); $temp_points = point_info($recipient_id); $GLOBALS['FORUM_DRIVER']->set_custom_field($recipient_id, 'points_gained_given', strval((array_key_exists('points_gained_given', $temp_points) ? $temp_points['points_gained_given'] : 0) + $amount)); $their_username = $GLOBALS['FORUM_DRIVER']->get_username($recipient_id); if (is_null($their_username)) { warn_exit(do_lang_tempcode('_USER_NO_EXIST', $recipient_id)); } $yes = $GLOBALS['FORUM_DRIVER']->get_member_email_allowed($recipient_id); if ($yes && $send_email) { $_url = build_url(array('page' => 'points', 'type' => 'member', 'id' => $recipient_id), get_module_zone('points'), NULL, false, false, true); $url = $_url->evaluate(); require_code('notifications'); if ($anonymous) { $message_raw = do_lang('GIVEN_POINTS_FOR_ANON', comcode_escape(get_site_name()), comcode_escape(integer_format($amount)), array(comcode_escape($reason), comcode_escape($url)), get_lang($recipient_id)); dispatch_notification('received_points', NULL, do_lang('YOU_GIVEN_POINTS', integer_format($amount), NULL, NULL, get_lang($recipient_id)), $message_raw, array($recipient_id), A_FROM_SYSTEM_UNPRIVILEGED); } else { $message_raw = do_lang('GIVEN_POINTS_FOR', comcode_escape(get_site_name()), comcode_escape(integer_format($amount)), array(comcode_escape($reason), comcode_escape($url), comcode_escape($your_username)), get_lang($recipient_id)); dispatch_notification('received_points', NULL, do_lang('YOU_GIVEN_POINTS', integer_format($amount), NULL, NULL, get_lang($recipient_id)), $message_raw, array($recipient_id), $sender_id); } $message_raw = do_lang('USER_GIVEN_POINTS_FOR', comcode_escape($their_username), comcode_escape(integer_format($amount)), array(comcode_escape($reason), comcode_escape($url), comcode_escape($your_username)), get_site_default_lang()); dispatch_notification('receive_points_staff', NULL, do_lang('USER_GIVEN_POINTS', integer_format($amount), NULL, NULL, get_site_default_lang()), $message_raw, NULL, $sender_id); } global $TOTAL_POINTS_CACHE, $POINT_INFO_CACHE; if (array_key_exists($recipient_id, $TOTAL_POINTS_CACHE)) { $TOTAL_POINTS_CACHE[$recipient_id] += $amount; } if (array_key_exists($recipient_id, $POINT_INFO_CACHE) && array_key_exists('points_gained_given', $POINT_INFO_CACHE[$recipient_id])) { $POINT_INFO_CACHE[$recipient_id]['points_gained_given'] += $amount; } if (array_key_exists($sender_id, $POINT_INFO_CACHE) && array_key_exists('gift_points_used', $POINT_INFO_CACHE[$sender_id])) { $POINT_INFO_CACHE[$sender_id]['gift_points_used'] += $amount; } if (get_forum_type() == 'ocf') { require_code('ocf_posts_action'); require_code('ocf_posts_action2'); ocf_member_handle_promotion($recipient_id); } if (!$anonymous) { if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'points')) { syndicate_described_activity(is_null($recipient_id) || is_guest($recipient_id) ? 'points:_ACTIVITY_GIVE_POINTS' : 'points:ACTIVITY_GIVE_POINTS', $reason, integer_format($amount), '', '_SEARCH:points:member:' . strval($recipient_id), '', '', 'points', 1, NULL, false, $recipient_id); } } }
/** * Stock maintain warning mail * * @param SHORT_TEXT product name * @param AUTO_LINK Product id */ function stock_maintain_warn_mail($product_name, $product_id) { $product_info_url = build_url(array('page' => 'catalogues', 'type' => 'entry', 'id' => $product_id), get_module_zone('catalogues')); $subject = do_lang('STOCK_LEVEL_MAIL_SUBJECT', get_site_name(), $product_name, NULL, get_site_default_lang()); $message = do_lang('STOCK_MAINTENANCE_WARN_MAIL', comcode_escape(get_site_name()), comcode_escape($product_name), array($product_info_url->evaluate()), get_site_default_lang()); require_code('notifications'); dispatch_notification('low_stock', NULL, $subject, $message, NULL, NULL, A_FROM_SYSTEM_PRIVILEGED); }
/** * Convert a language string into another language string. * * @param mixed The string to convert * @param LONG_TEXT The language to convert to * @return LONG_TEXT The converted string */ function google_translate($str_in, $lang) { $tempcode = is_object($str_in); $GLOBALS['NO_QUERY_LIMIT'] = true; if (get_option('enable_google_translate', true) !== '1') { return $str_in; } if ($tempcode) { $str_in = $str_in->evaluate(); } global $DOING_TRANSLATE; if (!isset($DOING_TRANSLATE)) { $DOING_TRANSLATE = false; } if ($DOING_TRANSLATE) { return $tempcode ? protect_from_escaping($str_in) : $str_in; } // Don't want loops if ($str_in == '') { return $tempcode ? protect_from_escaping(escape_html('')) : escape_html(''); } if (strpos($str_in, 'gtranslate_cache') !== false) { return $tempcode ? protect_from_escaping($str_in) : $str_in; } // Stop loops about corrupt/missing database tables $language_list = array('ar' => 'Arabic', 'bg' => 'Bulgarian', 'zh-cn' => 'Simplified Chinese', 'zh-tw' => 'Traditional Chinese', 'hr' => 'Croatian', 'cs' => 'Czech', 'da' => 'Danish', 'nl' => 'Dutch', 'en' => 'English', 'fi' => 'Finnish', 'fr' => 'French', 'de' => 'German', 'el' => 'Greek', 'hi' => 'Hindi', 'it' => 'Italian', 'ja' => 'Japanese', 'ko' => 'Korean', 'pl' => 'Polish', 'pt' => 'Portuguese', 'ro' => 'Romanian', 'ru' => 'Russian', 'es' => 'Spanish', 'sv' => 'Swedish'); $lang = strtolower($lang); if (!array_key_exists($lang, $language_list)) { return $tempcode ? protect_from_escaping($str_in) : $str_in; } $DOING_TRANSLATE = true; require_lang('lang'); $chache = check_google_cache($str_in, $lang); if (count($chache) == 0) { require_code('GTranslate'); $translate = new GTranslate(); $num_matches = array(); $matches = array(); $rep = array(); $prepped = $str_in; $j = 0; foreach (array(array('[', ']'), array('{', '}')) as $symbol) { $_matches = array(); $_num_matches = preg_match_all('#[' . preg_quote($symbol[0]) . '][^' . preg_quote($symbol[0]) . preg_quote($symbol[1]) . ']*[' . preg_quote($symbol[1]) . ']#', $str_in, $_matches); $matches[$symbol[0]] = $_matches; $num_matches[$symbol[0]] = $_num_matches; for ($i = 0; $i < $_num_matches; $i++) { $from = $_matches[0][$i]; $to = '<span class="notranslate">' . strval($j) . '</span>'; $rep['!' . strval($j)] = $from; // The '!' bit is because we can't trust indexing in PHP arrays if it is numeric $pos = 0; do { $pos = strpos($prepped, $from, $pos); if ($pos !== false) { $pos_open = strrpos(substr($prepped, 0, $pos), '<'); $pos_close = strrpos(substr($prepped, 0, $pos), '>'); if ($pos_open === false || $pos_close !== false && $pos_close > $pos_open) { $prepped = substr($prepped, 0, $pos) . $to . substr($prepped, $pos + strlen($from)); $pos += strlen($to); } else { $pos_title = strrpos(substr($prepped, 0, $pos), 'title="'); $pos_alt = strrpos(substr($prepped, 0, $pos), 'alt="'); $pos_quote = strrpos(substr($prepped, 0, $pos), '"'); if ($pos_alt !== false && $pos_alt > $pos_open && $pos_quote == $pos_alt + 4 || $pos_title !== false && $pos_title > $pos_open && $pos_quote == $pos_title + 6) { $to2 = ' conv' . strval($j) . ' '; $prepped = substr($prepped, 0, $pos) . $to2 . substr($prepped, $pos + strlen($from)); $pos += strlen($to2); } else { $pos += strlen($from); } } } } while ($pos !== false); $j++; } } if (strpos(preg_replace('#<[^>]*>#', '', $prepped), '{') !== false) { $DOING_TRANSLATE = false; return $tempcode ? protect_from_escaping($str_in) : $str_in; // Cannot translate as it has very complex Tempcode in it } $to = $language_list[$lang]; $from_lang = strtolower(get_site_default_lang()); try { $convertedstring = $translate->Text($prepped)->From(array_key_exists($from_lang, $language_list) ? $language_list[$from_lang] : 'English')->To($to); } catch (Exception $e) { } if ($convertedstring === NULL) { $convertedstring = $str_in; } do { $before = $convertedstring; $convertedstring = preg_replace('#(<span class="notranslate">\\d+) (.*</span>)#', '${1}</span> <span class="notranslate">${2}', $convertedstring); } while ($before != $convertedstring); foreach (array_reverse($rep) as $_j => $from) { $j = intval(substr($_j, 1)); $convertedstring = preg_replace('#\\s*<span class="notranslate">\\s*' . preg_quote(strval($j)) . '\\s*</span>\\s*#', $from, $convertedstring); $convertedstring = preg_replace('# conv' . preg_quote(strval($j)) . '\\s*#', $from, $convertedstring); } $convertedstring = str_replace('<html> ', '', $convertedstring); $convertedstring = str_replace(''', '', $convertedstring); save_google_cache($str_in, $lang, $convertedstring); $str = $convertedstring; } else { $str = $chache['t_result']; } $DOING_TRANSLATE = false; if (function_exists('ocp_mark_as_escaped') && ocp_is_escaped($str_in)) { ocp_mark_as_escaped($str); } return $tempcode ? protect_from_escaping($str) : $str; }
/** * Edit a video in a specified gallery. * * @param AUTO_LINK The ID of the entry to edit * @param SHORT_TEXT Video title * @param ID_TEXT The gallery name * @param LONG_TEXT The video comments * @param URLPATH The URL to the actual video * @param URLPATH The URL to the thumbnail of the actual video * @param BINARY Whether the video has been validated for display on the site * @param BINARY Whether the video may be rated * @param BINARY Whether the video may be commented upon * @param BINARY Whether the video may be trackbacked * @param LONG_TEXT Hidden notes associated with the video * @param integer The length of the video * @param integer The width of the video * @param integer The height of the video * @param SHORT_TEXT Meta keywords * @param LONG_TEXT Meta description */ function edit_video($id, $title, $cat, $comments, $url, $thumb_url, $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes, $video_length, $video_width, $video_height, $meta_keywords, $meta_description) { require_code('urls2'); suggest_new_idmoniker_for('galleries', 'video', strval($id), $title == '' ? $comments : $title); $_title = $GLOBALS['SITE_DB']->query_value('videos', 'title', array('id' => $id)); $_comments = $GLOBALS['SITE_DB']->query_value('videos', 'comments', array('id' => $id)); require_code('files2'); delete_upload('uploads/galleries', 'videos', 'url', 'id', $id, $url); delete_upload('uploads/galleries_thumbs', 'videos', 'thumb_url', 'id', $id, $thumb_url); require_code('transcoding'); $url = transcode_video($url, 'videos', 'url', NULL, 'video_width', 'video_height'); if (!addon_installed('unvalidated')) { $validated = 1; } require_code('submit'); $just_validated = !content_validated('video', strval($id)) && $validated == 1; if ($just_validated) { send_content_validated_notification('video', strval($id)); } $GLOBALS['SITE_DB']->query_update('videos', array('title' => lang_remap_comcode($_title, $title), 'edit_date' => time(), 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'allow_trackbacks' => $allow_trackbacks, 'notes' => $notes, 'validated' => $validated, 'cat' => $cat, 'comments' => lang_remap_comcode($_comments, $comments), 'url' => $url, 'thumb_url' => $thumb_url, 'video_length' => $video_length, 'video_width' => $video_width, 'video_height' => $video_height), array('id' => $id), '', 1); $self_url = build_url(array('page' => 'galleries', 'type' => 'video', 'id' => $id), get_module_zone('galleries'), NULL, false, false, true); if ($just_validated) { require_lang('galleries'); require_code('notifications'); $subject = do_lang('VIDEO_NOTIFICATION_MAIL_SUBJECT', get_site_name(), strip_comcode($title)); $mail = do_lang('VIDEO_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($title), array(comcode_escape($self_url->evaluate()))); dispatch_notification('gallery_entry', $cat, $subject, $mail); } log_it('EDIT_VIDEO', strval($id), $title); require_code('seo2'); seo_meta_set_for_explicit('video', strval($id), $meta_keywords, $meta_description); decache('main_gallery_embed'); require_lang('galleries'); require_code('feedback'); update_spacer_post($allow_comments != 0, 'videos', strval($id), $self_url, do_lang('VIEW_VIDEO', '', '', '', get_site_default_lang()), get_value('comment_forum__videos')); }