Example #1
0
/**
 * Get list of staff contextual actions.
 *
 * @return string		The list
 */
function get_staff_actions_list()
{
    require_lang('lang');
    $list = array('view' => do_lang_tempcode('SCREEN_DEV_TOOLS'));
    $list += array('spacer_1' => do_lang_tempcode('THEME'), 'show_edit_links' => do_lang_tempcode('TEMPLATES_WITH_EDIT_LINKS'), 'show_markers' => do_lang_tempcode('TEMPLATES_WITH_HTML_COMMENT_MARKERS'), 'tree' => do_lang_tempcode('TEMPLATE_TREE'), 'templates' => do_lang_tempcode('TEMPLATES'), 'theme_images' => do_lang_tempcode('THEME_IMAGE_EDITING'), 'code' => do_lang_tempcode('VALIDATION'), 'site_tree' => do_lang_tempcode('FIND_IN_SITE_TREE'));
    require_code('lang2');
    $list += array('spacer_2' => do_lang_tempcode('LANGUAGE'));
    $all_langs = multi_lang() ? find_all_langs() : array(user_lang() => 'lang_custom');
    $tcode = do_lang('lang:TRANSLATE_CODE');
    foreach (array_keys($all_langs) as $lang) {
        $list += array('lang_' . $lang => $tcode . (count($all_langs) == 1 ? '' : ': ' . lookup_language_full_name($lang)));
    }
    if (multi_lang()) {
        $tcontent = do_lang('TRANSLATE_CONTENT');
        foreach (array_keys($all_langs) as $lang) {
            $list['lang_content_' . $lang] = $tcontent . ': ' . lookup_language_full_name($lang);
        }
    }
    $list += array('spacer_3' => do_lang_tempcode('DEVELOPMENT_VIEWS'), 'query' => do_lang_tempcode('VIEW_PAGE_QUERIES'), 'ide_linkage' => do_lang_tempcode('IDE_LINKAGE'));
    if (function_exists('xdebug_enable')) {
        $list['profile'] = do_lang_tempcode('PROFILING');
    }
    if (function_exists('memory_get_usage')) {
        $list['memory'] = do_lang_tempcode('_MEMORY_USAGE');
    }
    $special_page_type = get_param('special_page_type', 'view');
    $staff_actions = '';
    foreach ($list as $name => $text) {
        $disabled = $name[0] == 's' && substr($name, 0, 7) == 'spacer_';
        $staff_actions .= '<option ' . ($disabled ? 'disabled="disabled" ' : '') . ($name == $special_page_type ? 'selected="selected" ' : '') . 'value="' . escape_html($name) . '">' . (is_object($text) ? $text->evaluate() : escape_html($text)) . '</option>';
        // XHTMLXHTML
        //$staff_actions.=static_evaluate_tempcode(form_input_list_entry($name,($name==$special_page_type),$text,false,$disabled));
    }
    return $staff_actions;
}
Example #2
0
 /**
  * Standard modular run function for do_next_menu hooks. They find links to put on standard navigation menus of the system.
  *
  * @return array			Array of links and where to show
  */
 function run()
 {
     $has_langs = false;
     $_dir = opendir(get_file_base() . '/lang/');
     $_langs = array();
     while (false !== ($file = readdir($_dir))) {
         if ($file == fallback_lang()) {
             continue;
         }
         if (!should_ignore_file('lang/' . $file, IGNORE_ACCESS_CONTROLLERS) && strlen($file) <= 5) {
             if (is_dir(get_file_base() . '/lang/' . $file)) {
                 $has_langs = true;
             }
         }
     }
     closedir($_dir);
     if (!in_safe_mode()) {
         $_dir = @opendir(get_custom_file_base() . '/lang_custom/');
         if ($_dir !== false) {
             while (false !== ($file = readdir($_dir))) {
                 if ($file == fallback_lang()) {
                     continue;
                 }
                 if (!should_ignore_file('lang_custom/' . $file, IGNORE_ACCESS_CONTROLLERS) && strlen($file) <= 5) {
                     if (is_dir(get_custom_file_base() . '/lang_custom/' . $file)) {
                         $has_langs = true;
                     }
                 }
             }
             closedir($_dir);
         }
         if (get_custom_file_base() != get_file_base()) {
             $_dir = opendir(get_file_base() . '/lang_custom/');
             while (false !== ($file = readdir($_dir))) {
                 if ($file == fallback_lang()) {
                     continue;
                 }
                 if (!should_ignore_file('lang_custom/' . $file, IGNORE_ACCESS_CONTROLLERS) && strlen($file) <= 5) {
                     $has_langs = true;
                 }
             }
             closedir($_dir);
         }
     }
     return array(array('style', 'language', array('admin_lang', array('type' => 'misc'), get_module_zone('admin_lang')), do_lang_tempcode('TRANSLATE_CODE'), 'DOC_TRANSLATE'), multi_lang() ? array('style', 'language', array('admin_lang', array('type' => 'content'), get_module_zone('admin_lang')), do_lang_tempcode('TRANSLATE_CONTENT'), 'DOC_TRANSLATE_CONTENT') : NULL, !$has_langs ? NULL : array('style', 'criticise_language', array('admin_lang', array('type' => 'criticise'), get_module_zone('admin_lang')), do_lang_tempcode('CRITICISE_LANGUAGE_PACK'), 'DOC_CRITICISE_LANGUAGE_PACK'));
 }
Example #3
0
 /**
  * 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));
     }
 }
Example #4
0
 /**
  * The UI to translate content.
  *
  * @return tempcode		The UI
  */
 function interface_content()
 {
     $title = get_page_title('TRANSLATE_CONTENT');
     if (!multi_lang()) {
         warn_exit(do_lang_tempcode('MULTILANG_OFF'));
     }
     $max = get_param_integer('max', 100);
     $lang = choose_language($title);
     if (is_object($lang)) {
         return $lang;
     }
     // Fiddle around in order to find what we haven't translated. Subqueries and self joins don't work well enough across different db's
     if (!db_has_subqueries($GLOBALS['SITE_DB']->connection_read)) {
         $_done_id_list = collapse_2d_complexity('id', 'text_original', $GLOBALS['SITE_DB']->query_select('translate', array('id', 'text_original'), array('language' => $lang, 'broken' => 0)));
         $done_id_list = '';
         foreach (array_keys($_done_id_list) as $done_id) {
             if ($done_id_list != '') {
                 $done_id_list .= ',';
             }
             $done_id_list .= strval($done_id);
         }
         $and_clause = $done_id_list == '' ? '' : 'AND id NOT IN (' . $done_id_list . ')';
         $query = 'FROM ' . get_table_prefix() . 'translate WHERE ' . db_string_not_equal_to('language', $lang) . ' ' . $and_clause . ' AND ' . db_string_not_equal_to('text_original', '') . ' ORDER BY importance_level';
         $to_translate = $GLOBALS['SITE_DB']->query('SELECT * ' . $query, $max);
     } else {
         $query = 'FROM ' . get_table_prefix() . 'translate a LEFT JOIN ' . get_table_prefix() . 'translate b ON a.id=b.id AND b.broken=0 AND ' . db_string_equal_to('b.language', $lang) . ' WHERE b.id IS NULL AND ' . db_string_not_equal_to('a.language', $lang) . ' AND ' . db_string_not_equal_to('a.text_original', '');
         $to_translate = $GLOBALS['SITE_DB']->query('SELECT a.* ' . $query . (can_arbitrary_groupby() ? ' GROUP BY a.id' : '') . ' ORDER BY a.importance_level', $max);
     }
     $total = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) ' . $query);
     if (count($to_translate) == 0) {
         inform_exit(do_lang_tempcode('NOTHING_TO_TRANSLATE'));
     }
     require_all_lang($lang, true);
     require_all_open_lang_files($lang);
     // Make our translation page
     require_code('lang2');
     $lines = '';
     $intertrans = $this->get_intertran_conv($lang);
     $actions = make_string_tempcode('&nbsp;');
     $last_level = NULL;
     $too_many = count($to_translate) == $max;
     $ids_to_lookup = array();
     foreach ($to_translate as $it) {
         $ids_to_lookup[] = $it['id'];
     }
     $names = find_lang_content_names($ids_to_lookup);
     foreach ($to_translate as $i => $it) {
         if ($it['importance_level'] == 0) {
             continue;
         }
         // Corrupt data
         $id = $it['id'];
         $old = $it['text_original'];
         $current = $this->find_lang_matches($old, $lang);
         $priority = $last_level === $it['importance_level'] ? NULL : do_lang('PRIORITY_' . strval($it['importance_level']));
         $name = $names[$id];
         if (is_null($name)) {
             continue;
         }
         // Orphaned string
         if ($intertrans != '') {
             $actions = do_template('TRANSLATE_ACTION', array('_GUID' => 'f625cf15c9db5e5af30fc772a7f0d5ff', 'LANG_FROM' => $it['language'], 'LANG_TO' => $lang, 'NAME' => 'trans_' . strval($id), 'OLD' => $old));
         }
         $line = do_template('TRANSLATE_LINE_CONTENT', array('_GUID' => '87a0f5298ce9532839f3206cd0e06051', 'NAME' => $name, 'ID' => strval($id), 'OLD' => $old, 'CURRENT' => $current, 'ACTIONS' => $actions, 'PRIORITY' => $priority));
         $lines .= $line->evaluate();
         /*XHTMLXHTML*/
         $last_level = $it['importance_level'];
     }
     $url = build_url(array('page' => '_SELF', 'type' => '_content', 'lang' => $lang), '_SELF');
     require_code('lang2');
     return do_template('TRANSLATE_SCREEN_CONTENT_SCREEN', array('_GUID' => 'af732c5e595816db1c6f025c4b8fa6a2', 'MAX' => integer_format($max), 'TOTAL' => integer_format($total - $max), 'LANG_ORIGINAL_NAME' => get_site_default_lang(), 'LANG_NICE_ORIGINAL_NAME' => lookup_language_full_name(get_site_default_lang()), 'LANG_NICE_NAME' => lookup_language_full_name($lang), 'TOO_MANY' => $too_many, 'INTERTRANS' => $intertrans, 'LANG' => $lang, 'LINES' => $lines, 'TITLE' => $title, 'URL' => $url));
 }
Example #5
0
 /**
  * The UI to select to view a past newsletter.
  *
  * @return tempcode		The UI
  */
 function archive()
 {
     $title = get_page_title('NEWSLETTER_ARCHIVE');
     $lang = choose_language($title);
     if (is_object($lang)) {
         return $lang;
     }
     $newsletters = new ocp_tempcode();
     $where = multi_lang() ? array('language' => $lang) : NULL;
     $rows = $GLOBALS['SITE_DB']->query_select('newsletter_archive', array('id', 'subject', 'date_and_time'), $where, 'ORDER BY date_and_time DESC');
     foreach ($rows as $newsletter) {
         $newsletters->attach(form_input_list_entry(strval($newsletter['id']), false, $newsletter['subject']));
     }
     if ($newsletters->is_empty()) {
         inform_exit(do_lang_tempcode('NO_ENTRIES'));
     }
     require_code('form_templates');
     $fields = form_input_list(do_lang_tempcode('NEWSLETTER'), '', 'id', $newsletters, NULL, true);
     $hidden = form_input_hidden('lang', $lang);
     $submit_name = do_lang_tempcode('VIEW');
     $post_url = build_url(array('page' => '_SELF', 'type' => 'view'), '_SELF', NULL, false, true);
     return do_template('FORM_SCREEN', array('_GUID' => 'ee295e41dc86c4583c123e6e0e445380', 'GET' => true, 'SKIP_VALIDATION' => true, 'HIDDEN' => $hidden, 'TITLE' => $title, 'TEXT' => '', 'FIELDS' => $fields, 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url));
 }
Example #6
0
/**
 * Add a configuration option into the database, and initialise it with a specified value.
 *
 * @param  ID_TEXT		The language code to the human name of the config option
 * @param  ID_TEXT		The codename for the config option
 * @param  ID_TEXT		The type of the config option
 * @set    float integer tick line text transline transtext list date forum category usergroup colour
 * @param  SHORT_TEXT	The PHP code to execute to get the default value for this option. Be careful not to make a get_option loop.
 * @param  ID_TEXT		The language code for the option category to store the option in
 * @param  ID_TEXT		The language code for the option group to store the option in
 * @param  BINARY			Whether the option is not settable when on a shared ocportal-hosting environment
 * @param  SHORT_TEXT	Extra data for the option
 */
function add_config_option($human_name, $name, $type, $eval, $category, $group, $shared_hosting_restricted = 0, $data = '')
{
    if (!in_array($type, array('float', 'integer', 'tick', 'line', 'text', 'transline', 'transtext', 'list', 'date', '?forum', 'forum', 'category', 'usergroup', 'colour'))) {
        fatal_exit('Invalid config option type');
    }
    $map = array('c_set' => 0, 'config_value' => '', 'the_name' => $name, 'human_name' => $human_name, 'the_type' => $type, 'eval' => $eval, 'the_page' => $category, 'section' => $group, 'explanation' => 'CONFIG_OPTION_' . $name, 'shared_hosting_restricted' => $shared_hosting_restricted, 'c_data' => $data);
    if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 0) {
        $GLOBALS['SITE_DB']->query_insert('config', $map, false, true);
        // Allow failure in case the config option got auto-installed through searching (can happen if the option is referenced efore the module installs right)
    } else {
        $GLOBALS['SITE_DB']->query_insert('config', $map);
        // From installer we want to know if there are errors in our install cycle
    }
    if (function_exists('persistant_cache_delete')) {
        persistant_cache_delete('OPTIONS');
    }
    global $OPTIONS;
    if ($OPTIONS == array()) {
        load_options();
    } else {
        $OPTIONS[$name] = $map;
        if (multi_lang()) {
            unset($OPTIONS[$name]['config_value_translated']);
        }
    }
}
Example #7
0
/**
 * Get an array containing new comcode, and tempcode. The function wraps the normal comcode_to_tempcode function. The function will do attachment management, including deleting of attachments that have become unused due to editing of some comcode and removing of the reference.
 *
 * @param  LONG_TEXT		The unparsed comcode that references the attachments
 * @param  ID_TEXT		The type the attachment will be used for (e.g. download)
 * @param  ID_TEXT		The ID the attachment will be used for
 * @param  boolean		Whether we are only previewing the attachments (i.e. don't store them!)
 * @param  ?object		The database connection to use (NULL: standard site connection)
 * @param  ?boolean		Whether to insert it as an admin (any comcode parsing will be carried out with admin privileges) (NULL: autodetect)
 * @param  ?MEMBER		The member to use for ownership permissions (NULL: current member)
 * @return array			A map containing 'comcode' (after substitution for tying down the new attachments) and 'tempcode'
 */
function do_comcode_attachments($original_comcode, $type, $id, $previewing_only = false, $connection = NULL, $insert_as_admin = NULL, $for_member = NULL)
{
    require_lang('comcode');
    global $COMCODE_ATTACHMENTS;
    unset($COMCODE_ATTACHMENTS[$id]);
    // In case we have some kind of conflict
    if (is_null($connection)) {
        $connection = $GLOBALS['SITE_DB'];
    }
    if ($for_member !== NULL) {
        $member = $for_member;
        if (is_null($insert_as_admin)) {
            $insert_as_admin = false;
        }
    } else {
        if (function_exists('get_member')) {
            $member = get_member();
            if (is_null($insert_as_admin)) {
                $insert_as_admin = false;
            }
        } else {
            $member = 0;
            if (is_null($insert_as_admin)) {
                $insert_as_admin = true;
            }
        }
    }
    $comcode_text = substr($original_comcode, 0, 8) != '<comcode';
    // Handle data URLs for attachment embedding
    if (function_exists('imagecreatefromstring')) {
        $matches = array();
        $matches2 = array();
        $num_matches = preg_match_all('#<img[^<>]*src="data:image/\\w+;base64,([^"]*)"[^<>]*>#', $original_comcode, $matches);
        $num_matches2 = preg_match_all('#\\[img[^\\[\\]]*\\]data:image/\\w+;base64,([^"]*)\\[/img\\]#', $original_comcode, $matches2);
        for ($i = 0; $i < $num_matches2; $i++) {
            $matches[0][$num_matches] = $matches2[0][$i];
            $matches[1][$num_matches] = $matches2[1][$i];
            $num_matches++;
        }
        for ($i = 0; $i < $num_matches; $i++) {
            if (strpos($original_comcode, $matches[0][$i]) !== false) {
                $data = @base64_decode($matches[1][$i]);
                if ($data !== false && function_exists('imagepng')) {
                    $image = @imagecreatefromstring($data);
                    if ($image !== false) {
                        do {
                            $new_filename = uniqid('', true) . '.png';
                            $new_path = get_custom_file_base() . '/uploads/attachments/' . $new_filename;
                        } while (file_exists($new_path));
                        imagepng($image, $new_path);
                        $attachment_id = $GLOBALS['SITE_DB']->query_insert('attachments', array('a_member_id' => get_member(), 'a_file_size' => strlen($data), 'a_url' => 'uploads/attachments/' . $new_filename, 'a_thumb_url' => '', 'a_original_filename' => basename($new_filename), 'a_num_downloads' => 0, 'a_last_downloaded_time' => time(), 'a_description' => '', 'a_add_time' => time()), true);
                        $GLOBALS['SITE_DB']->query_insert('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $attachment_id));
                        $original_comcode = str_replace($matches[0][$i], '[attachment type="inline" thumb="0"]' . strval($attachment_id) . '[/attachment]', $original_comcode);
                    }
                }
            }
        }
    }
    global $ATTACHMENTS_ALREADY_REFERENCED;
    $old_already = $ATTACHMENTS_ALREADY_REFERENCED;
    $ATTACHMENTS_ALREADY_REFERENCED = array();
    $before = $connection->query_select('attachment_refs', array('a_id', 'id'), array('r_referer_type' => $type, 'r_referer_id' => $id));
    foreach ($before as $ref) {
        $ATTACHMENTS_ALREADY_REFERENCED[$ref['a_id']] = 1;
    }
    $has_one = false;
    $may_have_one = false;
    foreach ($_POST as $key => $value) {
        if (preg_match('#^hidFileID\\_#i', $key) != 0) {
            require_code('uploads');
            $may_have_one = is_swf_upload();
        }
    }
    if ($may_have_one) {
        require_code('uploads');
        is_swf_upload(true);
        require_code('comcode_from_html');
        $original_comcode = preg_replace_callback('#<input [^>]*class="ocp_keep_ui_controlled" [^>]*title="([^"]*)" [^>]*type="text" [^>]*value="[^"]*"[^>]*/?' . '>#siU', 'debuttonise', $original_comcode);
    }
    $myfile = mixed();
    foreach ($_FILES as $key => $file) {
        $matches = array();
        if (($may_have_one && is_swf_upload() || is_uploaded_file($file['tmp_name'])) && preg_match('#file(\\d+)#', $key, $matches) != 0) {
            $has_one = true;
            $atype = post_param('attachmenttype' . $matches[1], '');
            $is_extract = preg_match('#\\[attachment [^\\]]*type="\\w+_extract"[^\\]]*\\]new_' . $matches[1] . '\\[/#', $original_comcode) != 0 || preg_match('#<attachment [^>]*type="\\w+_extract"[^>]*>new_' . $matches[1] . '</#', $original_comcode) != 0;
            if (substr($atype, -8) == '_extract' || $is_extract) {
                require_code('uploads');
                require_code('files');
                require_code('files2');
                $thumb = preg_match('#\\[(attachment|attachment_safe) [^\\]]*thumb="1"[^\\]]*\\]new_' . $matches[1] . '\\[/#', $original_comcode) != 0 || preg_match('#<(attachment|attachment_safe) [^>]*thumb="1"[^>]*>new_' . $matches[1] . '</#', $original_comcode) != 0;
                $arcext = get_file_extension($_FILES[$key]['name']);
                if ($arcext == 'tar' || $arcext == 'zip') {
                    if ($arcext == 'tar') {
                        require_code('tar');
                        $myfile = tar_open($file['tmp_name'], 'rb');
                        $dir = tar_get_directory($myfile, true);
                    } elseif ($arcext == 'zip') {
                        if (!function_exists('zip_open') && get_option('unzip_cmd') == '') {
                            warn_exit(do_lang_tempcode('ZIP_NOT_ENABLED'));
                        }
                        if (!function_exists('zip_open')) {
                            require_code('m_zip');
                            $mzip = true;
                        } else {
                            $mzip = false;
                        }
                        $myfile = zip_open($file['tmp_name']);
                        if (is_integer($myfile)) {
                            require_code('failure');
                            warn_exit(zip_error($myfile, $mzip));
                        }
                        $dir = array();
                        while (($zip_entry = zip_read($myfile)) !== false) {
                            $dir[] = array('zip_entry' => $zip_entry, 'path' => zip_entry_name($zip_entry), 'size' => zip_entry_filesize($zip_entry));
                        }
                    }
                    if (count($dir) > 100) {
                        require_code('site');
                        attach_message(do_lang_tempcode('TOO_MANY_FILES_TO_EXTRACT'), 'warn');
                    } else {
                        foreach ($dir as $entry) {
                            if (substr($entry['path'], -1) == '/') {
                                continue;
                            }
                            // Ignore folders
                            $_file = preg_replace('#\\..*\\.#', '.', basename($entry['path']));
                            if (!check_extension($_file, false, NULL, true)) {
                                continue;
                            }
                            if (should_ignore_file($entry['path'], IGNORE_ACCESS_CONTROLLERS | IGNORE_HIDDEN_FILES)) {
                                continue;
                            }
                            $place = get_custom_file_base() . '/uploads/attachments/' . $_file;
                            $i = 2;
                            // Hunt with sensible names until we don't get a conflict
                            while (file_exists($place)) {
                                $_file = strval($i) . basename($entry['path']);
                                $place = get_custom_file_base() . '/uploads/attachments/' . $_file;
                                $i++;
                            }
                            $i = 2;
                            $_file_thumb = basename($entry['path']);
                            $place_thumb = get_custom_file_base() . '/uploads/attachments_thumbs/' . $_file_thumb;
                            // Hunt with sensible names until we don't get a conflict
                            while (file_exists($place_thumb)) {
                                $_file_thumb = strval($i) . basename($entry['path']);
                                $place_thumb = get_custom_file_base() . '/uploads/attachments_thumbs/' . $_file_thumb;
                                $i++;
                            }
                            if ($arcext == 'tar') {
                                $file_details = tar_get_file($myfile, $entry['path'], false, $place);
                            } elseif ($arcext == 'zip') {
                                zip_entry_open($myfile, $entry['zip_entry']);
                                $file_details = array('size' => $entry['size']);
                                $out_file = @fopen($place, 'wb') or intelligent_write_error($place);
                                $more = mixed();
                                do {
                                    $more = zip_entry_read($entry['zip_entry']);
                                    if ($more !== false) {
                                        if (fwrite($out_file, $more) < strlen($more)) {
                                            warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                                        }
                                    }
                                } while ($more !== false && $more != '');
                                fclose($out_file);
                                zip_entry_close($entry['zip_entry']);
                            }
                            $description = do_lang('EXTRACTED_FILE');
                            if (strpos($entry['path'], '/') !== false) {
                                $description = do_lang('EXTRACTED_FILE_PATH', dirname($entry['path']));
                            }
                            // Thumbnail
                            $thumb_url = '';
                            require_code('images');
                            if (is_image($_file)) {
                                $gd = get_option('is_on_gd') == '1' && function_exists('imagetypes');
                                if ($gd) {
                                    require_code('images');
                                    if (!is_saveable_image($_file)) {
                                        $ext = '.png';
                                    } else {
                                        $ext = '.' . get_file_extension($_file);
                                    }
                                    $thumb_url = 'uploads/attachments_thumbs/' . $_file_thumb;
                                    convert_image(get_custom_base_url() . '/uploads/attachments/' . $_file, $place_thumb, -1, -1, intval(get_option('thumb_width')), true, NULL, false, true);
                                    if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
                                        $thumb_url = get_custom_base_url() . '/' . $thumb_url;
                                    }
                                } else {
                                    $thumb_url = 'uploads/attachments/' . $_file;
                                }
                            }
                            $url = 'uploads/attachments/' . $_file;
                            if (addon_installed('galleries')) {
                                require_code('images');
                                if (is_video($url) && $connection->connection_read == $GLOBALS['SITE_DB']->connection_read) {
                                    require_code('transcoding');
                                    $url = transcode_video($url, 'attachments', 'a_url', 'a_original_filename', NULL, NULL);
                                }
                            }
                            $attachment_id = $connection->query_insert('attachments', array('a_member_id' => get_member(), 'a_file_size' => $file_details['size'], 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => basename($entry['path']), 'a_num_downloads' => 0, 'a_last_downloaded_time' => time(), 'a_description' => $description, 'a_add_time' => time()), true);
                            $connection->query_insert('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $attachment_id));
                            if ($comcode_text) {
                                $original_comcode .= chr(10) . chr(10) . '[attachment type="' . comcode_escape(str_replace('_extract', '', $atype)) . '" description="' . comcode_escape($description) . '" thumb="' . ($thumb ? '1' : '0') . '"]' . strval($attachment_id) . '[/attachment]';
                            } else {
                                require_code('comcode_xml');
                                //$original_comcode.=chr(10).chr(10).'<attachment type="'.comcode_escape(str_replace('_extract','',$atype)).'" thumb="'.($thumb?'1':'0').'"><attachmentDescription>'.comcode_text__to__comcode_xml($description).'</attachmentDescription>'.strval($attachment_id).'</attachment>';			Would go in bad spot
                            }
                        }
                    }
                    if ($arcext == 'tar') {
                        tar_close($myfile);
                    } elseif ($arcext == 'zip') {
                        zip_close($myfile);
                    }
                }
            } else {
                if (strpos($original_comcode, ']new_' . $matches[1] . '[/attachment]') === false && strpos($original_comcode, '>new_' . $matches[1] . '</attachment>') === false && strpos($original_comcode, ']new_' . $matches[1] . '[/attachment_safe]') === false && strpos($original_comcode, '>new_' . $matches[1] . '</attachment_safe>') === false) {
                    if (preg_match('#\\]\\d+\\[/attachment\\]#', $original_comcode) == 0 && preg_match('#>\\d+</attachment>#', $original_comcode) == 0) {
                        if ($comcode_text) {
                            $original_comcode .= chr(10) . chr(10) . '[attachment]new_' . $matches[1] . '[/attachment]';
                        } else {
                            //$original_comcode.=chr(10).chr(10).'<attachment>new_'.$matches[1].'</attachment>';		Would go in bad spot
                        }
                    }
                }
            }
        }
    }
    global $LAX_COMCODE;
    $temp = $LAX_COMCODE;
    if ($has_one) {
        $LAX_COMCODE = true;
    }
    // We don't want a simple syntax error to cause us to lose our attachments
    $tempcode = comcode_to_tempcode($original_comcode, $member, $insert_as_admin, 60, $id, $connection, false, false, false, false, false, NULL, $for_member);
    $LAX_COMCODE = $temp;
    $ATTACHMENTS_ALREADY_REFERENCED = $old_already;
    /*if ((array_key_exists($id,$COMCODE_ATTACHMENTS)) && (array_key_exists(0,$COMCODE_ATTACHMENTS[$id])))
    	{
    		$original_comcode=$COMCODE_ATTACHMENTS[$id][0]['comcode'];
    	}*/
    $new_comcode = $original_comcode;
    if (array_key_exists($id, $COMCODE_ATTACHMENTS)) {
        $ids_present = array();
        for ($i = 0; $i < count($COMCODE_ATTACHMENTS[$id]); $i++) {
            $attachment = $COMCODE_ATTACHMENTS[$id][$i];
            // If it's a new one, we need to change the comcode to reference the ID we made for it
            if ($attachment['type'] == 'new') {
                $marker = $attachment['marker'];
                //				echo $marker.'!'.$new_comcode;
                $a_id = $attachment['id'];
                $old_length = strlen($new_comcode);
                // Search backwards from $marker
                $tag_end_start = $marker - strlen('[/' . $attachment['tag_type'] . ']');
                // </attachment> would be correct if it is Comcode-XML, but they have the same length, so it's irrelevant
                $tag_start_end = $tag_end_start;
                while ($tag_start_end > 1 && (!isset($new_comcode[$tag_start_end - 1]) || $new_comcode[$tag_start_end - 1] != ']' && $new_comcode[$tag_start_end - 1] != '>')) {
                    $tag_start_end--;
                }
                $param_keep = substr($new_comcode, 0, $tag_start_end - 1);
                $end_keep = substr($new_comcode, $tag_end_start);
                if ($comcode_text) {
                    $new_comcode = $param_keep;
                    if (strpos(substr($param_keep, strrpos($param_keep, '[')), ' type=') === false) {
                        $new_comcode .= ' type="' . comcode_escape($attachment['attachmenttype']) . '"';
                    }
                    if (strpos(substr($param_keep, strrpos($param_keep, '[')), ' description=') === false) {
                        $new_comcode .= ' description="' . comcode_escape($attachment['description']) . '"';
                    }
                    $new_comcode .= ']' . strval($a_id) . $end_keep;
                } else {
                    require_code('comcode_xml');
                    $new_comcode = $param_keep;
                    if (strpos(substr($param_keep, strrpos($param_keep, '<')), ' type=') === false) {
                        $new_comcode .= ' type="' . comcode_escape($attachment['attachmenttype']);
                    }
                    $new_comcode .= '">';
                    if (strpos(substr($param_keep, strrpos($param_keep, '<')), ' description=') === false) {
                        require_code('comcode_xml');
                        $new_comcode .= '<attachmentDescription>' . comcode_text__to__comcode_xml($attachment['description'], true) . '</attachmentDescription>';
                    }
                    $new_comcode .= strval($a_id) . $end_keep;
                }
                //				echo $new_comcode.'<br />!<br />';
                // Update other attachment markers
                $dif = strlen($new_comcode) - $old_length;
                for ($j = $i + 1; $j < count($COMCODE_ATTACHMENTS[$id]); $j++) {
                    //					echo $COMCODE_ATTACHMENTS[$id][$i]['marker'].'!';
                    $COMCODE_ATTACHMENTS[$id][$j]['marker'] += $dif;
                }
                if (!is_null($type)) {
                    $connection->query_insert('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $a_id));
                }
            } else {
                // (Re-)Reference it
                $connection->query_delete('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $attachment['id']), '', 1);
                $connection->query_insert('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $attachment['id']));
            }
            $ids_present[] = $attachment['id'];
        }
        if (!$previewing_only && get_value('disable_attachment_cleanup') !== '1') {
            // Clear any de-referenced attachments
            foreach ($before as $ref) {
                if (!in_array($ref['a_id'], $ids_present) && strpos($new_comcode, 'attachment.php?id=') === false && !multi_lang()) {
                    // Delete reference (as it's not actually in the new comcode!)
                    $connection->query_delete('attachment_refs', array('id' => $ref['id']), '', 1);
                    // Was that the last reference to this attachment? (if so -- delete attachment)
                    $test = $connection->query_value_null_ok('attachment_refs', 'id', array('a_id' => $ref['a_id']));
                    if (is_null($test)) {
                        require_code('attachments3');
                        _delete_attachment($ref['a_id'], $connection);
                    }
                }
            }
        }
    }
    return array('comcode' => $new_comcode, 'tempcode' => $tempcode);
}
Example #8
0
/**
 * Find a group of members the newsletter will go to.
 *
 * @param  array				A map describing what newsletters and newsletter levels the newsletter is being sent to
 * @param  LANGUAGE_NAME	The language
 * @param  integer			Start position in result set (results are returned in parallel for each category of result)
 * @param  integer			Maximum records to return from each category
 * @param  boolean			Whether to get raw rows rather than mailer-ready correspondance lists
 * @param  string				Serialized CSV data to also consider
 * @return array				Returns a tuple of corresponding detail lists, emails,hashes,usernames,forenames,surnames,ids, and a record count for levels (depending on requests: csv, 1, <newsletterID>, g<groupID>) [record counts not returned if $start is not zero, for performance reasons]
 */
function newsletter_who_send_to($send_details, $lang, $start, $max, $get_raw_rows = false, $csv_data = '')
{
    // Find who to send to
    $level = 0;
    $usernames = array();
    $forenames = array();
    $surnames = array();
    $emails = array();
    $ids = array();
    $hashes = array();
    $total = array();
    $raw_rows = array();
    // Standard newsletter subscribers
    $newsletters = $GLOBALS['SITE_DB']->query_select('newsletters', array('*'));
    foreach ($newsletters as $newsletter) {
        $this_level = array_key_exists(strval($newsletter['id']), $send_details) ? $send_details[strval($newsletter['id'])] : 0;
        if ($this_level != 0) {
            $where_lang = multi_lang() ? db_string_equal_to('language', $lang) . ' AND ' : '';
            $query = ' FROM ' . get_table_prefix() . 'newsletter_subscribe s LEFT JOIN ' . get_table_prefix() . 'newsletter n ON n.email=s.email WHERE ' . $where_lang . 'code_confirm=0 AND s.newsletter_id=' . strval($newsletter['id']) . ' AND the_level>=' . strval((int) $this_level);
            $temp = $GLOBALS['SITE_DB']->query('SELECT n.id,n.email,the_password,n_forename,n_surname' . $query, $max, $start);
            if ($start == 0) {
                $test = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'newsletter_subscribe WHERE newsletter_id=' . strval($newsletter['id']) . ' AND the_level>=' . strval((int) $this_level));
                if ($test > 10000) {
                    $total[strval($newsletter['id'])] = $test;
                } else {
                    $total[strval($newsletter['id'])] = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*)' . $query);
                }
            }
            foreach ($temp as $_temp) {
                if (!in_array($_temp['email'], $emails)) {
                    if (!$get_raw_rows) {
                        $emails[] = $_temp['email'];
                        $forenames[] = $_temp['n_forename'];
                        $surnames[] = $_temp['n_surname'];
                        $username = trim($_temp['n_forename'] . ' ' . $_temp['n_surname']);
                        if ($username == '') {
                            $username = do_lang('NEWSLETTER_SUBSCRIBER', get_site_name());
                        }
                        $usernames[] = $username;
                        $ids[] = 'n' . strval($_temp['id']);
                        $hashes[] = best_hash($_temp['the_password'], 'xunsub');
                    } else {
                        $raw_rows[] = $_temp;
                    }
                }
            }
        }
        $level = max($level, $this_level);
    }
    // OCF imports
    if (get_forum_type() == 'ocf') {
        $where_lang = multi_lang() ? '(' . db_string_equal_to('m_language', $lang) . ' OR ' . db_string_equal_to('m_language', '') . ') AND ' : '';
        // Usergroups
        $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list();
        foreach ($send_details as $_id => $is_on) {
            if (is_string($_id) && substr($_id, 0, 1) == 'g' && $is_on == 1) {
                $id = intval(substr($_id, 1));
                global $SITE_INFO;
                if (isset($SITE_INFO['mysql_old']) && $SITE_INFO['mysql_old'] == '1' || !isset($SITE_INFO['mysql_old']) && is_file(get_file_base() . '/mysql_old')) {
                    $query = 'SELECT xxxxx FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members m LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_group_members g ON m.id=g.gm_member_id AND g.gm_validated=1 WHERE ' . db_string_not_equal_to('m_email_address', '') . ' AND ' . $where_lang . 'm_validated=1 AND (gm_group_id=' . strval($id) . ' OR m_primary_group=' . strval($id) . ')';
                    if (get_option('allow_email_from_staff_disable') == '1') {
                        $query .= ' AND m_allow_emails=1';
                    }
                    $query .= ' AND m_is_perm_banned=0';
                } else {
                    $query = 'SELECT xxxxx  FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members m LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_group_members g ON m.id=g.gm_member_id AND g.gm_validated=1 WHERE ' . db_string_not_equal_to('m_email_address', '') . ' AND ' . $where_lang . 'm_validated=1 AND gm_group_id=' . strval($id);
                    if (get_option('allow_email_from_staff_disable') == '1') {
                        $query .= ' AND m_allow_emails=1';
                    }
                    $query .= ' AND m_is_perm_banned=0';
                    $query .= ' UNION SELECT xxxxx FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members m WHERE ' . db_string_not_equal_to('m_email_address', '') . ' AND ' . $where_lang . 'm_validated=1 AND m_primary_group=' . strval($id);
                    if (get_option('allow_email_from_staff_disable') == '1') {
                        $query .= ' AND m_allow_emails=1';
                    }
                    $query .= ' AND m_is_perm_banned=0';
                }
                $_rows = $GLOBALS['FORUM_DB']->query(str_replace('xxxxx', 'm.id,m.m_email_address,m.m_username', $query), $max, $start, false, true);
                if ($start == 0) {
                    $total['g' . strval($id)] = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT (' . str_replace(' UNION ', ') + (', str_replace('xxxxx', 'COUNT(*)', $query)) . ')', false, true);
                }
                foreach ($_rows as $row) {
                    if (!in_array($row['m_email_address'], $emails)) {
                        if (!$get_raw_rows) {
                            $emails[] = $row['m_email_address'];
                            $forenames[] = '';
                            $surnames[] = '';
                            $usernames[] = $row['m_username'];
                            $ids[] = 'm' . strval($row['id']);
                            $hashes[] = '';
                        } else {
                            $raw_rows[] = $row;
                        }
                    }
                }
            }
        }
        // *All* OCF members (we could have chosen all usergroups, but for legacy reasons we still have this option)
        if (array_key_exists('-1', $send_details) ? $send_details['-1'] : 0 == 1) {
            $query = ' FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE ' . db_string_not_equal_to('m_email_address', '') . ' AND ' . $where_lang . 'm_validated=1';
            if (get_option('allow_email_from_staff_disable') == '1') {
                $query .= ' AND m_allow_emails=1';
            }
            $query .= ' AND m_is_perm_banned=0';
            $_rows = $GLOBALS['FORUM_DB']->query('SELECT id,m_email_address,m_username' . $query, $max, $start);
            if ($start == 0) {
                $total['-1'] = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*)' . $query);
            }
            foreach ($_rows as $_temp) {
                if (!in_array($_temp['m_email_address'], $emails)) {
                    if (!$get_raw_rows) {
                        $emails[] = $_temp['m_email_address'];
                        $forenames[] = '';
                        $surnames[] = '';
                        $usernames[] = $_temp['m_username'];
                        $ids[] = 'm' . strval($_temp['id']);
                        $hashes[] = '';
                    } else {
                        $raw_rows[] = $_temp;
                    }
                }
            }
        }
    }
    // From CSV
    if ($csv_data != '') {
        secure_serialized_data($csv_data, array());
        $_csv_data = unserialize($csv_data);
        $email_index = 0;
        $forename_index = 1;
        $surname_index = 2;
        $username_index = 3;
        $id_index = 4;
        $hash_index = 5;
        if ($start == 0) {
            $total['csv'] = 0;
        }
        $pos = 0;
        foreach ($_csv_data as $i => $csv_line) {
            if ($i <= 1 && count($csv_line) >= 1 && isset($csv_line[0]) && strpos($csv_line[0], '@') === false && isset($csv_line[1]) && strpos($csv_line[1], '@') === false) {
                foreach ($csv_line as $j => $val) {
                    if (in_array(strtolower($val), array('e-mail', 'email', 'email address', 'e-mail address'))) {
                        $email_index = $j;
                    }
                    if (in_array(strtolower($val), array('forename', 'forenames', 'first name'))) {
                        $forename_index = $j;
                    }
                    if (in_array(strtolower($val), array('surname', 'surnames', 'last name'))) {
                        $surname_index = $j;
                    }
                    if (in_array(strtolower($val), array('username'))) {
                        $username_index = $j;
                    }
                    if (in_array(strtolower($val), array('id', 'identifier'))) {
                        $id_index = $j;
                    }
                    if (in_array(strtolower($val), array('hash', 'password', 'pass', 'code', 'secret'))) {
                        $hash_index = $j;
                    }
                }
                continue;
            }
            if (count($csv_line) >= 1 && !is_null($csv_line[$email_index]) && strpos($csv_line[$email_index], '@') !== false) {
                if ($pos >= $start && $pos - $start < $max) {
                    if (!$get_raw_rows) {
                        $emails[] = $csv_line[$email_index];
                        $forenames[] = array_key_exists($forename_index, $csv_line) ? $csv_line[$forename_index] : '';
                        $surnames[] = array_key_exists($surname_index, $csv_line) ? $csv_line[$surname_index] : '';
                        $usernames[] = array_key_exists($username_index, $csv_line) ? $csv_line[$username_index] : '';
                        $ids[] = array_key_exists($id_index, $csv_line) ? $csv_line[$id_index] : '';
                        $hashes[] = array_key_exists($hash_index, $csv_line) ? $csv_line[$hash_index] : '';
                    } else {
                        $raw_rows[] = $csv_line;
                    }
                }
                if ($start == 0) {
                    $total['csv']++;
                }
                $pos++;
            }
        }
    }
    return array($emails, $hashes, $usernames, $forenames, $surnames, $ids, $total, $raw_rows);
}
Example #9
0
/**
 * Get an array of all the pages everywhere in the zone (for small sites everything will be returned, for larger ones it depends on the show method).
 *
 * @param  ID_TEXT		The zone name
 * @param  boolean		Whether to leave file extensions on the page name
 * @param  boolean		Whether to take redirects into account
 * @param  integer		Selection algorithm constant
 * @set 0 1 2
 * @param  ?ID_TEXT		Page type to show (NULL: all)
 * @return array			A map of page name to type (modules_custom, etc)
 */
function _find_all_pages_wrap($zone, $keep_ext_on = false, $consider_redirects = false, $show_method = 0, $page_type = NULL)
{
    $pages = array();
    if (is_null($page_type) || $page_type == 'modules') {
        if (!in_safe_mode()) {
            $pages += find_all_pages($zone, 'modules_custom', 'php', $keep_ext_on, NULL, $show_method);
        }
        $pages += find_all_pages($zone, 'modules', 'php', $keep_ext_on, NULL, $show_method);
    }
    $langs = multi_lang() ? array_keys(find_all_langs()) : array(get_site_default_lang());
    foreach ($langs as $lang) {
        if (is_null($page_type) || $page_type == 'comcode') {
            if (!in_safe_mode()) {
                $pages += find_all_pages($zone, 'comcode_custom/' . $lang, 'txt', $keep_ext_on, NULL, $show_method);
            }
            $pages += find_all_pages($zone, 'comcode/' . $lang, 'txt', $keep_ext_on, NULL, $show_method);
        }
        if (is_null($page_type) || $page_type == 'html') {
            if (!in_safe_mode()) {
                $pages += find_all_pages($zone, 'html_custom/' . $lang, 'htm', $keep_ext_on, NULL, $show_method);
            }
            $pages += find_all_pages($zone, 'html/' . $lang, 'htm', $keep_ext_on, NULL, $show_method);
        }
    }
    if (is_null($page_type) || $page_type == 'minimodules') {
        if (!in_safe_mode()) {
            $pages += find_all_pages($zone, 'minimodules_custom', 'php', $keep_ext_on, NULL, $show_method);
        }
        $pages += find_all_pages($zone, 'minimodules', 'php', $keep_ext_on, NULL, $show_method);
    }
    if (addon_installed('redirects_editor')) {
        if ($consider_redirects) {
            $redirects = $GLOBALS['SITE_DB']->query_select('redirects', array('*'), array('r_from_zone' => $zone));
            foreach ($redirects as $r) {
                if ($r['r_is_transparent'] == 0) {
                    //unset($pages[$r['r_from_page']]); // We don't want to link to anything that is a full redirect		-	Actually, we don't want to hide things too much, could be confusing
                } else {
                    $pages[$r['r_from_page']] = 'redirect:' . $r['r_to_zone'] . ':' . $r['r_to_page'];
                }
            }
        }
    }
    return $pages;
}
Example #10
0
/**
 * UI to choose a language.
 *
 * @param  tempcode			Title for the form
 * @param  boolean			Whether to give a tip about edit order
 * @param  boolean			Whether to add an 'all' entry to the list
 * @return mixed				The UI (tempcode) or the language to use (string/LANGUAGE_NAME)
 */
function choose_language($title, $tip = false, $allow_all_selection = false)
{
    if (!multi_lang()) {
        return user_lang();
    }
    $lang = either_param('lang', NULL);
    if (!is_null($lang)) {
        return filter_naughty($lang);
    }
    if (!$tip) {
        $text = do_lang_tempcode('CHOOSE_LANG_DESCRIP');
    } else {
        global $LANGS_MAP;
        if ($LANGS_MAP === NULL) {
            $map_a = get_file_base() . '/lang/langs.ini';
            $map_b = get_custom_file_base() . '/lang_custom/langs.ini';
            if (!is_file($map_b)) {
                $map_b = $map_a;
            }
            $LANGS_MAP = better_parse_ini_file($map_b);
        }
        $lang_name = get_site_default_lang();
        if (array_key_exists($lang_name, $LANGS_MAP)) {
            $lang_name = $LANGS_MAP[$lang_name];
        }
        $text = do_lang_tempcode('CHOOSE_LANG_DESCRIP_ADD_TO_MAIN_LANG_FIRST', escape_html($lang_name));
    }
    $langs = new ocp_tempcode();
    if ($allow_all_selection) {
        $langs->attach(form_input_list_entry('', false, do_lang_tempcode('_ALL')));
    }
    $langs->attach(nice_get_langs());
    require_code('form_templates');
    $fields = form_input_list(do_lang_tempcode('LANGUAGE'), do_lang_tempcode('DESCRIPTION_LANGUAGE'), 'lang', $langs, NULL, true);
    $hidden = build_keep_post_fields();
    $url = get_self_url();
    return do_template('FORM_SCREEN', array('_GUID' => '1a2823d450237aa299c095bf9c689a2a', 'SKIP_VALIDATION' => true, 'HIDDEN' => $hidden, 'SUBMIT_NAME' => do_lang_tempcode('PROCEED'), 'TITLE' => $title, 'FIELDS' => $fields, 'URL' => $url, 'TEXT' => $text));
}
Example #11
0
/**
 * Find the URL to the theme image of the specified ID. It searches various priorities, including language and theme overrides.
 *
 * @param  ID_TEXT			The theme image ID
 * @param  boolean			Whether to silently fail (i.e. not give out an error message when a theme image cannot be found)
 * @param  boolean			Whether to leave URLs as relative local URLs
 * @param  ?ID_TEXT			The theme to search in (NULL: users current theme)
 * @param  ?LANGUAGE_NAME  The language to search for (NULL: users current language)
 * @param  ?object			The database to use (NULL: site database)
 * @param  boolean			Whether to only search the default 'images' filesystem
 * @return URLPATH			The URL found (blank: not found)
 */
function find_theme_image($id, $silent_fail = false, $leave_local = false, $theme = NULL, $lang = NULL, $db = NULL, $pure_only = false)
{
    if (substr($id, 0, 4) == 'ocf_' && is_file(get_file_base() . '/themes/default/images/avatars/index.html')) {
        $id = substr($id, 4);
    }
    if (isset($_GET['keep_theme_seed']) && get_param('keep_theme_seed', NULL) !== NULL && function_exists('has_specific_permission') && has_specific_permission(get_member(), 'view_profiling_modes')) {
        require_code('themewizard');
        $test = find_theme_image_themewizard_preview($id);
        if ($test !== NULL) {
            return $test;
        }
    }
    if ($db === NULL) {
        $db = $GLOBALS['SITE_DB'];
    }
    global $RECORD_IMG_CODES;
    if ($RECORD_IMG_CODES) {
        global $RECORDED_IMG_CODES;
        if (isset($GLOBALS['FORUM_DB']) && $db->connection_write !== $GLOBALS['FORUM_DB']->connection_write) {
            $RECORDED_IMG_CODES[serialize(array($id, $theme, $lang))] = 1;
        }
    }
    $true_theme = $GLOBALS['FORUM_DRIVER']->get_theme();
    if ($theme === NULL) {
        $theme = $true_theme;
    }
    global $USER_LANG_CACHED;
    $true_lang = $USER_LANG_CACHED === NULL ? user_lang() : $USER_LANG_CACHED;
    if ($lang === NULL) {
        $lang = $true_lang;
    }
    $truism = $theme == $true_theme && $lang == $true_lang;
    $site = $GLOBALS['SITE_DB'] == $db ? 'site' : 'forums';
    global $IMG_CODES;
    if (!isset($IMG_CODES[$site])) {
        static $cache = NULL;
        if ($site == 'site') {
            $cache = persistant_cache_get('THEME_IMAGES');
        }
        if (!isset($cache[$true_theme][$true_lang])) {
            $IMG_CODES[$site] = $db->query_select('theme_images', array('id', 'path'), array('theme' => $true_theme, 'lang' => $true_lang));
            $IMG_CODES[$site] = collapse_2d_complexity('id', 'path', $IMG_CODES[$site]);
            if ($site == 'site') {
                if ($cache === NULL) {
                    $cache = array();
                }
                $cache[$theme][$true_lang] = $IMG_CODES[$site];
                persistant_cache_set('THEME_IMAGES', $cache);
            }
        } else {
            $IMG_CODES[$site] = $cache[$true_theme][$true_lang];
        }
    }
    if (!$truism && !$pure_only) {
        $path = $db->query_value_null_ok('theme_images', 'path', array('theme' => $theme, 'lang' => $lang, 'id' => $id));
        if ($path !== NULL) {
            if (url_is_local($path) && !$leave_local) {
                $path = ($db->connection_write != $GLOBALS['SITE_DB']->connection_write ? get_forum_base_url() : (substr($path, 0, 22) == 'themes/default/images/' ? get_base_url() : get_custom_base_url())) . '/' . $path;
            }
            return cdn_filter($path);
        }
    }
    if ($pure_only || !isset($IMG_CODES[$site][$id]) || !$truism) {
        $path = NULL;
        $priorities = array();
        if (!$pure_only) {
            $priorities = array_merge($priorities, array(array($theme, $lang, 'images_custom'), array($theme, '', 'images_custom'), $lang == fallback_lang() ? NULL : array($theme, fallback_lang(), 'images_custom')));
        }
        // This will not do a DB search, just a filesystem search. The Theme Wizard makes these though
        $priorities = array_merge($priorities, array(array($theme, $lang, 'images'), array($theme, '', 'images'), $lang == fallback_lang() ? NULL : array($theme, fallback_lang(), 'images')));
        if ($theme != 'default') {
            if (!$pure_only) {
                $priorities = array_merge($priorities, array(array('default', $lang, 'images_custom'), array('default', '', 'images_custom'), $lang == fallback_lang() ? NULL : array('default', fallback_lang(), 'images_custom')));
            }
            $priorities = array_merge($priorities, array(array('default', $lang, 'images'), array('default', '', 'images'), $lang == fallback_lang() ? NULL : array('default', fallback_lang(), 'images')));
        }
        foreach ($priorities as $i => $priority) {
            if ($priority === NULL) {
                continue;
            }
            if ($priority[2] == 'images_custom' && $priority[1] != '') {
                $smap = array('id' => $id, 'theme' => $priority[0], 'lang' => $priority[1]);
                $nql_backup = $GLOBALS['NO_QUERY_LIMIT'];
                $GLOBALS['NO_QUERY_LIMIT'] = true;
                $truism_b = $priority[0] == $true_theme && (!multi_lang() || $priority[1] == '' || $priority[1] === $true_lang);
                $path = $truism_b ? NULL : $db->query_value_null_ok('theme_images', 'path', $smap);
                $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup;
                if ($path !== NULL) {
                    if (strpos($path, '/images/' . $id . '.') !== false) {
                        continue;
                    }
                    if (array_key_exists('lang', $smap) && strpos($path, '/images/' . $smap['lang'] . '/' . $id . '.') !== false) {
                        continue;
                    }
                    break;
                }
            }
            $test = _search_img_file($priority[0], $priority[1], $id, $priority[2]);
            if ($test !== NULL) {
                $path_bits = explode('/', $test);
                $path = '';
                foreach ($path_bits as $bit) {
                    if ($path != '') {
                        $path .= '/';
                    }
                    $path .= rawurlencode($bit);
                }
                break;
            }
        }
        if ($db->connection_write == $GLOBALS['SITE_DB']->connection_write) {
            if ($path !== NULL && $path != '' || $silent_fail && !$GLOBALS['SEMI_DEBUG_MODE']) {
                $nql_backup = $GLOBALS['NO_QUERY_LIMIT'];
                $GLOBALS['NO_QUERY_LIMIT'] = true;
                $db->query_delete('theme_images', array('id' => $id, 'theme' => $theme, 'lang' => $lang));
                // Allow for race conditions
                $db->query_insert('theme_images', array('id' => $id, 'theme' => $theme, 'path' => $path === NULL ? '' : $path, 'lang' => $lang), false, true);
                // Allow for race conditions
                $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup;
                persistant_cache_delete('THEME_IMAGES');
            }
        }
        if ($path === NULL) {
            if (!$silent_fail) {
                require_code('site');
                attach_message(do_lang_tempcode('NO_SUCH_IMAGE', escape_html($id)), 'warn');
            }
            return '';
        }
        if ($truism) {
            $IMG_CODES[$site][$id] = $path;
        }
        // only cache if we are looking up for our own theme/lang
    } else {
        $path = $IMG_CODES[$site][$id];
        global $SITE_INFO;
        if ($path != '' && (!isset($SITE_INFO['disable_smart_decaching']) || $SITE_INFO['disable_smart_decaching'] == '0') && (!isset($SITE_INFO['no_disk_sanity_checks']) || $SITE_INFO['no_disk_sanity_checks'] == '0') && url_is_local($path) && !is_file(get_custom_file_base() . '/' . rawurldecode($path))) {
            unset($IMG_CODES[$site][$id]);
            return find_theme_image($id, $silent_fail, $leave_local, $theme, $lang, $db, $pure_only);
        }
    }
    if (url_is_local($path) && !$leave_local && $path != '') {
        if ($db->connection_write != $GLOBALS['SITE_DB']->connection_write) {
            $base_url = get_forum_base_url();
        } else {
            global $SITE_INFO;
            $missing = !$pure_only && ((!isset($SITE_INFO['disable_smart_decaching']) || $SITE_INFO['disable_smart_decaching'] == '0') && (!isset($SITE_INFO['no_disk_sanity_checks']) || $SITE_INFO['no_disk_sanity_checks'] == '0') && (!is_file(get_file_base() . '/' . rawurldecode($path)) && !is_file(get_custom_file_base() . '/' . rawurldecode($path))));
            if (substr($path, 0, 22) == 'themes/default/images/' || $missing) {
                if ($missing) {
                    return find_theme_image($id, $silent_fail, $leave_local, $theme, $lang, $db, true);
                }
                $base_url = get_base_url();
            } else {
                $base_url = get_custom_base_url();
            }
        }
        $path = $base_url . '/' . $path;
    }
    return cdn_filter($path);
}
/**
 * Get form fields for adding/editing/finishing a member profile.
 *
 * @param  boolean			Whether we are only handling the essential details of a profile.
 * @param  ?MEMBER			The ID of the member we are handling (NULL: new member).
 * @param  ?array				A list of usergroups (NULL: default/current usergroups).
 * @param  SHORT_TEXT		The e-mail address.
 * @param  BINARY				Whether posts are previewed before they are made.
 * @param  ?integer			Day of date of birth (NULL: not known).
 * @param  ?integer			Month of date of birth (NULL: not known).
 * @param  ?integer			Year of date of birth (NULL: not known).
 * @param  ?ID_TEXT			The member timezone (NULL: site default).
 * @param  ?ID_TEXT			The members default theme (NULL: not known).
 * @param  BINARY				Whether the members age may be shown.
 * @param  BINARY				Whether the member sees signatures in posts.
 * @param  ?BINARY			Whether the member automatically is enabled for notifications for content they contribute to (NULL: get default from config).
 * @param  ?LANGUAGE_NAME	The members language (NULL: auto detect).
 * @param  BINARY				Whether the member allows e-mails via the site.
 * @param  BINARY				Whether the member allows e-mails from staff via the site.
 * @param  BINARY				Whether the profile has been validated.
 * @param  ?GROUP				The members primary (NULL: not known).
 * @param  SHORT_TEXT		The username.
 * @param  BINARY				Whether the member is permanently banned.
 * @param  ID_TEXT			The special type of profile this is (blank: not a special type).
 * @param  BINARY				Whether the member likes to view zones without menus, when a choice is available.
 * @param  BINARY				Whether the member username will be highlighted.
 * @param  SHORT_TEXT		Usergroups that may PT the member.
 * @param  LONG_TEXT			Rules that other members must agree to before they may start a PT with the member.
 * @param  ?TIME				When the member is on probation until (NULL: just finished probation / or effectively was never on it)
 * @return array				A pair: The form fields, Hidden fields (both Tempcode).
 */
function ocf_get_member_fields_settings($mini_mode = true, $member_id = NULL, $groups = NULL, $email_address = '', $preview_posts = 0, $dob_day = NULL, $dob_month = NULL, $dob_year = NULL, $timezone = NULL, $theme = NULL, $reveal_age = 1, $views_signatures = 1, $auto_monitor_contrib_content = NULL, $language = NULL, $allow_emails = 1, $allow_emails_from_staff = 1, $validated = 1, $primary_group = NULL, $username = '', $is_perm_banned = 0, $special_type = '', $zone_wide = 1, $highlighted_name = 0, $pt_allow = '*', $pt_rules_text = '', $on_probation_until = NULL)
{
    if (is_null($auto_monitor_contrib_content)) {
        $auto_monitor_contrib_content = get_value('no_auto_notifications') === '1' ? 0 : 1;
    }
    $hidden = new ocp_tempcode();
    if (has_actual_page_access(get_member(), 'admin_ocf_join')) {
        $dob_optional = true;
    } else {
        $dob_optional = get_option('no_dob_ask') == '2';
    }
    if ($member_id === $GLOBALS['OCF_DRIVER']->get_guest_id()) {
        fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
    }
    require_code('form_templates');
    require_code('encryption');
    if ($special_type == '' && !is_null($member_id)) {
        if (ocf_is_ldap_member($member_id)) {
            $special_type = 'ldap';
        }
        if (ocf_is_httpauth_member($member_id)) {
            $special_type = 'httpauth';
        }
        if ($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id, 'm_password_compat_scheme') == 'remote') {
            $special_type = 'remote';
        }
    }
    if (is_null($groups)) {
        $groups = is_null($member_id) ? ocf_get_all_default_groups(true) : $GLOBALS['OCF_DRIVER']->get_members_groups($member_id);
    }
    $fields = new ocp_tempcode();
    // Human name / Username
    if ($special_type != 'ldap' && $special_type != 'remote' && $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id, 'm_password_compat_scheme') != 'facebook') {
        if (is_null($member_id) || has_actual_page_access(get_member(), 'admin_ocf_join') || has_specific_permission($member_id, 'rename_self')) {
            if (get_option('signup_fullname') == '1') {
                $fields->attach(form_input_line(do_lang_tempcode('NAME'), do_lang_tempcode('_DESCRIPTION_NAME'), is_null($member_id) ? 'username' : 'edit_username', $username, true));
            } else {
                $prohibit_username_whitespace = get_option('prohibit_username_whitespace', true);
                if ($prohibit_username_whitespace == '1') {
                    $fields->attach(form_input_codename(do_lang_tempcode('USERNAME'), do_lang_tempcode('DESCRIPTION_USERNAME'), is_null($member_id) ? 'username' : 'edit_username', $username, true));
                } else {
                    $fields->attach(form_input_line(do_lang_tempcode('USERNAME'), do_lang_tempcode('DESCRIPTION_USERNAME'), is_null($member_id) ? 'username' : 'edit_username', $username, true));
                }
            }
        }
    }
    // Password
    if ($special_type == '') {
        if (is_null($member_id) || $member_id == get_member() || has_specific_permission(get_member(), 'assume_any_member')) {
            $fields->attach(form_input_password(do_lang_tempcode('PASSWORD'), do_lang_tempcode('DESCRIPTION_PASSWORD' . (!is_null($member_id) ? '_EDIT' : '')), is_null($member_id) ? 'password' : 'edit_password', $mini_mode));
            $fields->attach(form_input_password(do_lang_tempcode('CONFIRM_PASSWORD'), '', 'password_confirm', $mini_mode));
        }
    }
    // E-mail address
    if ($email_address == '') {
        $email_address = trim(get_param('email_address', ''));
    }
    if ($special_type != 'remote') {
        $fields->attach(form_input_email(do_lang_tempcode('EMAIL_ADDRESS'), get_option('skip_email_confirm_join') == '1' ? new ocp_tempcode() : do_lang_tempcode('MUST_BE_REAL_ADDRESS'), 'email_address', $email_address, !has_specific_permission(get_member(), 'member_maintenance')));
        if (is_null($member_id) && $email_address == '' && get_option('skip_email_confirm_join') == '0') {
            $fields->attach(form_input_email(do_lang_tempcode('CONFIRM_EMAIL_ADDRESS'), '', 'email_address_confirm', '', !has_specific_permission(get_member(), 'member_maintenance')));
        }
    }
    // DOB
    $default_time = is_null($dob_month) ? NULL : usertime_to_utctime(mktime(0, 0, 0, $dob_month, $dob_day, $dob_year));
    if (get_option('no_dob_ask') != '1') {
        $fields->attach(form_input_date(do_lang_tempcode(get_option('no_dob_ask') == '2' ? 'BIRTHDAY' : 'DATE_OF_BIRTH'), '', 'dob', $dob_optional, false, false, $default_time, -130));
        if (addon_installed('ocf_forum')) {
            $fields->attach(form_input_tick(do_lang_tempcode('RELATED_FIELD', do_lang_tempcode('REVEAL_AGE')), do_lang_tempcode('DESCRIPTION_REVEAL_AGE'), 'reveal_age', $reveal_age == 1));
        }
    }
    // Work out what options we need to present
    $doing_international = get_option('allow_international') == '1' && $special_type != 'remote';
    $_langs = find_all_langs();
    $doing_langs = multi_lang() && $special_type != 'remote';
    $doing_email_option = get_option('allow_email_disable') == '1';
    $doing_email_from_staff_option = get_option('allow_email_from_staff_disable') == '1';
    $unspecced_width_zone_exists = $GLOBALS['SITE_DB']->query_value_null_ok('zones', 'zone_name', array('zone_wide' => NULL));
    $unspecced_theme_zone_exists = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'zones WHERE ' . db_string_equal_to('zone_theme', '') . ' OR ' . db_string_equal_to('zone_theme', '-1'));
    $doing_wide_option = $special_type != 'remote' && !is_null($unspecced_width_zone_exists) && !$mini_mode;
    $doing_theme_option = $unspecced_theme_zone_exists != 0 && !$mini_mode;
    $doing_local_forum_options = addon_installed('ocf_forum') && $special_type != 'remote' && !$mini_mode;
    if ($doing_international || $doing_langs || $doing_email_option || $doing_wide_option || $doing_theme_option || $doing_local_forum_options) {
        $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('FORCE_OPEN' => is_null($member_id) ? true : NULL, 'TITLE' => do_lang_tempcode('SETTINGS'))));
    }
    require_lang('config');
    // Timezones, if enabled
    if ($doing_international) {
        $timezone_list = nice_get_timezone_list($timezone);
        $fields->attach(form_input_list(do_lang_tempcode('TIME_ZONE'), do_lang_tempcode('DESCRIPTION_TIMEZONE_MEMBER'), 'timezone', $timezone_list));
    }
    // Language choice, if we have multiple languages on site
    if ($doing_langs) {
        $lang_list = new ocp_tempcode();
        $no_lang_set = is_null($language) || $language == '';
        $allow_no_lang_set = get_value('allow_no_lang_selection') === '1';
        if ($allow_no_lang_set) {
            $lang_list->attach(form_input_list_entry('', $no_lang_set, do_lang_tempcode('UNSET')));
        } else {
            if ($no_lang_set) {
                $language = user_lang();
            }
        }
        $lang_list->attach(nice_get_langs($language));
        $fields->attach(form_input_list(do_lang_tempcode('LANGUAGE'), '', 'language', $lang_list, NULL, false, !$allow_no_lang_set));
    }
    // Email privacy
    if ($doing_email_option) {
        $fields->attach(form_input_tick(do_lang_tempcode('ALLOW_EMAILS'), do_lang_tempcode('DESCRIPTION_ALLOW_EMAILS'), 'allow_emails', $allow_emails == 1));
    }
    if ($doing_email_from_staff_option) {
        $fields->attach(form_input_tick(do_lang_tempcode('ALLOW_EMAILS_FROM_STAFF'), do_lang_tempcode('DESCRIPTION_ALLOW_EMAILS_FROM_STAFF'), 'allow_emails_from_staff', $allow_emails_from_staff == 1));
    }
    if (!$mini_mode) {
        // Wide-option, if we have any zones giving a choice
        require_lang('zones');
        if ($doing_wide_option) {
            $fields->attach(form_input_tick(do_lang_tempcode('WIDE'), do_lang_tempcode('DESCRIPTION_MEMBER_ZONE_WIDE'), 'zone_wide', $zone_wide == 1));
        }
        // Theme, if we have any zones giving a choice
        require_code('themes2');
        $entries = nice_get_themes($theme, false, false, 'RELY_SITE_DEFAULT');
        require_lang('themes');
        if ($doing_theme_option) {
            $fields->attach(form_input_list(do_lang_tempcode('THEME'), do_lang_tempcode('DESCRIPTION_THEME'), 'theme', $entries));
        }
        // Various forum options
        if (addon_installed('ocf_forum')) {
            if ($special_type != 'remote') {
                if (get_option('forced_preview_option') == '1') {
                    $fields->attach(form_input_tick(do_lang_tempcode('PREVIEW_POSTS'), do_lang_tempcode('DESCRIPTION_PREVIEW_POSTS'), 'preview_posts', $preview_posts == 1));
                }
                if (get_value('disable_views_sigs_option') !== '1') {
                    if (addon_installed('ocf_signatures')) {
                        $fields->attach(form_input_tick(do_lang_tempcode('VIEWS_SIGNATURES'), do_lang_tempcode('DESCRIPTION_VIEWS_SIGNATURES'), 'views_signatures', $views_signatures == 1));
                    }
                } else {
                    $hidden->attach(form_input_hidden('views_signatures', '1'));
                }
                //$fields->attach(form_input_tick(do_lang_tempcode('AUTO_NOTIFICATION_CONTRIB_CONTENT'),do_lang_tempcode('DESCRIPTION_AUTO_NOTIFICATION_CONTRIB_CONTENT'),'auto_monitor_contrib_content',$auto_monitor_contrib_content==1));
                $usergroup_list = new ocp_tempcode();
                $lgroups = $GLOBALS['OCF_DRIVER']->get_usergroup_list(true, true);
                foreach ($lgroups as $key => $val) {
                    if ($key != db_get_first_id()) {
                        $usergroup_list->attach(form_input_list_entry(strval($key), $pt_allow == '*' || count(array_intersect(array(strval($key)), explode(',', $pt_allow))) != 0, $val));
                    }
                }
                if (get_value('disable_pt_restrict') !== '1') {
                    $fields->attach(form_input_multi_list(do_lang_tempcode('PT_ALLOW'), addon_installed('chat') ? do_lang_tempcode('PT_ALLOW_DESCRIPTION_CHAT') : do_lang_tempcode('PT_ALLOW_DESCRIPTION'), 'pt_allow', $usergroup_list));
                    $fields->attach(form_input_text_comcode(do_lang_tempcode('PT_RULES_TEXT'), do_lang_tempcode('PT_RULES_TEXT_DESCRIPTION'), 'pt_rules_text', $pt_rules_text, false));
                }
            }
        }
        // Prepare list of usergroups, if maybe we are gonna let (a) usergroup-change field(s)
        $group_count = $GLOBALS['FORUM_DB']->query_value('f_groups', 'COUNT(*)');
        $rows = $GLOBALS['FORUM_DB']->query_select('f_groups', array('id', 'g_name', 'g_hidden', 'g_open_membership'), $group_count > 200 ? array('g_is_private_club' => 0) : NULL, 'ORDER BY g_order');
        $_groups = new ocp_tempcode();
        $default_primary_group = get_first_default_group();
        $current_primary_group = NULL;
        foreach ($rows as $group) {
            if ($group['id'] != db_get_first_id()) {
                $selected = $group['id'] == $primary_group || is_null($primary_group) && $group['id'] == $default_primary_group;
                if ($selected) {
                    $current_primary_group = $group['id'];
                }
                $_groups->attach(form_input_list_entry(strval($group['id']), $selected, get_translated_text($group['g_name'], $GLOBALS['FORUM_DB'])));
            }
        }
        // Some admin options...
        if (has_specific_permission(get_member(), 'member_maintenance')) {
            $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('MEMBER_ACCESS'))));
            // Probation
            if (has_specific_permission(get_member(), 'probate_members')) {
                $fields->attach(form_input_date(do_lang_tempcode('ON_PROBATION_UNTIL'), do_lang_tempcode('DESCRIPTION_ON_PROBATION_UNTIL'), 'on_probation_until', true, is_null($on_probation_until) || $on_probation_until <= time(), true, $on_probation_until, 2));
            }
            // Primary usergroup
            if ($special_type != 'ldap') {
                if (has_specific_permission(get_member(), 'assume_any_member')) {
                    if (is_null($member_id) || !$GLOBALS['FORUM_DRIVER']->is_super_admin($member_id) || count($GLOBALS['FORUM_DRIVER']->member_group_query($GLOBALS['FORUM_DRIVER']->get_super_admin_groups(), 2)) > 1) {
                        $fields->attach(form_input_list(do_lang_tempcode('PRIMARY_GROUP'), do_lang_tempcode('DESCRIPTION_PRIMARY_GROUP'), 'primary_group', $_groups));
                    }
                }
            }
        }
        // Secondary usergroups
        if ($special_type != 'ldap') {
            $_groups2 = new ocp_tempcode();
            $members_groups = is_null($member_id) ? array() : $GLOBALS['OCF_DRIVER']->get_members_groups($member_id, false, false);
            foreach ($rows as $group) {
                if ($group['g_hidden'] == 1 && !array_key_exists($group['id'], $members_groups) && !has_specific_permission(get_member(), 'see_hidden_groups')) {
                    continue;
                }
                if ($group['id'] != db_get_first_id() && $group['id'] != $current_primary_group && (array_key_exists($group['id'], $members_groups) || has_specific_permission(get_member(), 'assume_any_member') || $group['g_open_membership'] == 1)) {
                    $selected = array_key_exists($group['id'], $members_groups);
                    $_groups2->attach(form_input_list_entry(strval($group['id']), $selected, get_translated_text($group['g_name'], $GLOBALS['FORUM_DB'])));
                }
            }
            $sec_url = build_url(array('page' => 'groups', 'type' => 'misc'), get_module_zone('groups'));
            if (!$_groups2->is_empty()) {
                $fields->attach(form_input_multi_list(do_lang_tempcode('SECONDARY_GROUP_MEMBERSHIP'), do_lang_tempcode('DESCRIPTION_SECONDARY_GROUP', escape_html($sec_url->evaluate())), 'secondary_groups', $_groups2));
            }
        }
        // Special admin options
        if (has_specific_permission(get_member(), 'member_maintenance')) {
            if ($validated == 0) {
                $validated = get_param_integer('validated', 0);
                if ($validated == 1) {
                    attach_message(do_lang_tempcode('WILL_BE_VALIDATED_WHEN_SAVING'));
                }
            }
            if (addon_installed('unvalidated')) {
                $fields->attach(form_input_tick(do_lang_tempcode('VALIDATED'), do_lang_tempcode('DESCRIPTION_MEMBER_VALIDATED'), 'validated', $validated == 1));
            }
            if (get_value('disable_highlight_name') !== '1') {
                $fields->attach(form_input_tick(do_lang_tempcode('HIGHLIGHTED_NAME'), do_lang_tempcode(addon_installed('pointstore') ? 'DESCRIPTION_HIGHLIGHTED_NAME_P' : 'DESCRIPTION_HIGHLIGHTED_NAME'), 'highlighted_name', $highlighted_name == 1));
            }
            if (!is_null($member_id) && $member_id != get_member()) {
                // Can't ban someone new, and can't ban yourself
                $fields->attach(form_input_tick(do_lang_tempcode('_BANNED'), do_lang_tempcode('DESCRIPTION_MEMBER_BANNED'), 'is_perm_banned', $is_perm_banned == 1));
            }
        }
    }
    return array($fields, $hidden);
}
Example #13
0
/**
 * Insert a language entry into the translation table, and returns the id.
 *
 * @param  string				The text
 * @param  integer			The level of importance this language string holds
 * @set    1 2 3 4
 * @param  ?object			The database connection to use (NULL: standard site connection)
 * @param  boolean			Whether it is to be parsed as comcode
 * @param  ?integer			The id to use for the language entry (NULL: work out next available)
 * @param  ?LANGUAGE_NAME	The language (NULL: uses the current language)
 * @param  boolean			Whether to insert it as an admin (any comcode parsing will be carried out with admin privileges)
 * @param  ?string			The special identifier for this lang code on the page it will be displayed on; this is used to provide an explicit binding between languaged elements and greater templated areas (NULL: none)
 * @param  ?string			Assembled Tempcode portion (NULL: work it out)
 * @param  integer			Comcode parser wrap position
 * @param  boolean			Whether to generate a fatal error if there is invalid Comcode
 * @param  boolean			Whether we are saving as a 'volatile' file extension (used in the XML DB driver, to mark things as being non-syndicated to subversion)
 * @return integer			The id of the newly added language entry
 */
function _insert_lang($text, $level, $connection = NULL, $comcode = false, $id = NULL, $lang = NULL, $insert_as_admin = false, $pass_id = NULL, $text2 = NULL, $wrap_pos = 60, $preparse_mode = true, $save_as_volatile = false)
{
    if (is_null($connection)) {
        $connection = $GLOBALS['SITE_DB'];
    }
    if (get_page_name() == 'admin_import') {
        $comcode = false;
    }
    // For speed, and to avoid instantly showing Comcode errors from sloppy bbcode
    if (is_null($lang)) {
        $lang = user_lang();
    }
    $_text2 = NULL;
    if (running_script('stress_test_loader')) {
        $comcode = false;
    }
    if ($comcode) {
        if (is_null($text2)) {
            if (function_exists('get_member') && !$insert_as_admin) {
                $member = get_member();
            } else {
                $member = is_object($GLOBALS['FORUM_DRIVER']) ? $GLOBALS['FORUM_DRIVER']->get_guest_id() : 0;
                $insert_as_admin = true;
            }
            $_text2 = comcode_to_tempcode($text, $member, $insert_as_admin, $wrap_pos, $pass_id, $connection, false, $preparse_mode);
            $text2 = $_text2->to_assembly();
        }
    } else {
        $text2 = '';
    }
    $source_member = function_exists('get_member') ? get_member() : $GLOBALS['FORUM_DRIVER']->get_guest_id();
    if (is_null($id) && multi_lang()) {
        $id = $connection->query_value('translate', 'MAX(id)');
        $id = is_null($id) ? NULL : $id + 1;
    }
    if ($lang == 'Gibb') {
        if (is_null($id)) {
            $id = $connection->query_insert('translate', array('source_user' => $source_member, 'broken' => 0, 'importance_level' => $level, 'text_original' => 'EnglishEnglishWarningWrongLanguageWantGibberishLang', 'text_parsed' => '', 'language' => 'EN'), true, false, $save_as_volatile);
        } else {
            $connection->query_insert('translate', array('id' => $id, 'source_user' => $source_member, 'broken' => 0, 'importance_level' => $level, 'text_original' => 'EnglishEnglishWarningWrongLanguageWantGibberishLang', 'text_parsed' => '', 'language' => 'EN'), false, false, $save_as_volatile);
        }
    }
    if (is_null($id) || $id === 0) {
        $id = $connection->query_insert('translate', array('source_user' => $source_member, 'broken' => 0, 'importance_level' => $level, 'text_original' => $text, 'text_parsed' => $text2, 'language' => $lang), true, false, $save_as_volatile);
    } else {
        $connection->query_insert('translate', array('id' => $id, 'source_user' => $source_member, 'broken' => 0, 'importance_level' => $level, 'text_original' => $text, 'text_parsed' => $text2, 'language' => $lang), false, false, $save_as_volatile);
    }
    if (count($connection->text_lookup_cache) < 5000) {
        if (!is_null($_text2)) {
            $connection->text_lookup_cache[$id] = $_text2;
        } else {
            $connection->text_lookup_original_cache[$id] = $text;
        }
    }
    return $id;
}