/** * Find how to store a field in the database. * * @param ID_TEXT The field type. * @return array A pair: the DB field type, whether to index. */ function get_cpf_storage_for($type) { require_code('fields'); $ob = get_fields_hook($type); list(, , $storage_type) = $ob->get_field_value_row_bits(array('id' => NULL, 'cf_type' => $type, 'cf_default' => '')); $_type = 'SHORT_TEXT'; switch ($storage_type) { case 'short_trans': $_type = 'SHORT_TRANS'; break; case 'long_trans': $_type = 'LONG_TRANS'; break; case 'long': $_type = 'LONG_TEXT'; break; } $index = true; switch ($type) { case 'short_trans': case 'short_trans_multi': case 'long_trans': case 'posting_field': case 'tick': case 'integer': case 'float': case 'color': case 'content_link': case 'date': case 'just_date': case 'just_time': case 'picture': case 'password': case 'page_link': case 'upload': $index = false; break; } return array($_type, $index); }
/** * Show value statistics for a custom profile field (choose). * * @return tempcode The UI */ function stats() { $title = get_page_title('CUSTOM_PROFILE_FIELD_STATS'); breadcrumb_set_parents(array()); $fields = new ocp_tempcode(); $rows = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_name', 'cf_type')); require_code('form_templates'); require_code('fields'); $list = new ocp_tempcode(); $_list = array(); foreach ($rows as $row) { $ob = get_fields_hook($row['cf_type']); list(, , $storage_type) = $ob->get_field_value_row_bits(NULL); if (strpos($storage_type, '_trans') === false) { $id = $row['id']; $text = get_translated_text($row['cf_name'], $GLOBALS['FORUM_DB']); $_list[$id] = $text; } } asort($_list); foreach ($_list as $id => $text) { $list->attach(form_input_list_entry(strval($id), false, $text)); } if ($list->is_empty()) { return inform_screen($title, do_lang_tempcode('NO_ENTRIES')); } require_lang('dates'); $fields->attach(form_input_list(do_lang_tempcode('NAME'), '', 'id', $list)); $fields->attach(form_input_date(do_lang_tempcode('FROM'), do_lang_tempcode('DESCRIPTION_MEMBERS_JOINED_FROM'), 'start', true, false, false, time() - 60 * 60 * 24 * 30, 10, intval(date('Y')) - 10)); $fields->attach(form_input_date(do_lang_tempcode('TO'), do_lang_tempcode('DESCRIPTION_MEMBERS_JOINED_TO'), 'end', true, false, false, time(), 10, intval(date('Y')) - 10)); $post_url = build_url(array('page' => '_SELF', 'type' => '_stats'), '_SELF', NULL, false, true); $submit_name = do_lang_tempcode('CUSTOM_PROFILE_FIELD_STATS'); return do_template('FORM_SCREEN', array('_GUID' => '393bac2180c9e135ae9c31565ddf7761', 'GET' => true, 'SKIP_VALIDATION' => true, 'TITLE' => $title, 'HIDDEN' => '', 'FIELDS' => $fields, 'TEXT' => '', 'URL' => $post_url, 'SUBMIT_NAME' => $submit_name)); }
/** * Standard modular run function for search results. * * @param string Search string * @param boolean Whether to only do a META (tags) search * @param ID_TEXT Order direction * @param integer Start position in total results * @param integer Maximum results to return in total * @param boolean Whether only to search titles (as opposed to both titles and content) * @param string Where clause that selects the content according to the main search string (SQL query fragment) (blank: full-text search) * @param SHORT_TEXT Username/Author to match for * @param ?MEMBER Member-ID to match for (NULL: unknown) * @param TIME Cutoff date * @param string The sort type (gets remapped to a field in this function) * @set title add_date * @param integer Limit to this number of results * @param string What kind of boolean search to do * @set or and * @param string Where constraints known by the main search code (SQL query fragment) * @param string Comma-separated list of categories to search under * @param boolean Whether it is a boolean search * @return array List of maps (template, orderer) */ function run($content, $only_search_meta, $direction, $max, $start, $only_titles, $content_where, $author, $author_id, $cutoff, $sort, $limit_to, $boolean_operator, $where_clause, $search_under, $boolean_search) { unset($limit_to); if (get_forum_type() != 'ocf') { return array(); } require_code('ocf_members'); $remapped_orderer = ''; switch ($sort) { case 'title': $remapped_orderer = 'm_username'; break; case 'add_date': $remapped_orderer = 'm_join_time'; break; case 'relevance': case 'rating': break; default: $remapped_orderer = preg_replace('#[^\\w]#', '', $sort); break; } require_lang('ocf'); // Calculate our where clause (search) if ($author != '') { $where_clause .= ' AND '; $where_clause .= db_string_equal_to('m_username', $author); } if (!is_null($cutoff)) { $where_clause .= ' AND '; $where_clause .= 'm_join_time>' . strval($cutoff); } $raw_fields = array('m_username'); $trans_fields = array(); $rows = ocf_get_all_custom_fields_match(NULL, 1, 1); $table = ''; require_code('fields'); $non_trans_fields = 0; foreach ($rows as $i => $row) { $ob = get_fields_hook($row['cf_type']); list(, , $storage_type) = $ob->get_field_value_row_bits($row); if (strpos($storage_type, '_trans') === false) { $non_trans_fields++; } } $index_issue = $non_trans_fields > 16; foreach ($rows as $i => $row) { $ob = get_fields_hook($row['cf_type']); list(, , $storage_type) = $ob->get_field_value_row_bits($row); $param = get_param('option_' . strval($row['id']), ''); if ($param != '') { $where_clause .= ' AND '; if (db_has_full_text($GLOBALS['SITE_DB']->connection_read) && method_exists($GLOBALS['SITE_DB']->static_ob, 'db_has_full_text_boolean') && $GLOBALS['SITE_DB']->static_ob->db_has_full_text_boolean() && !is_under_radar($param)) { $temp = db_full_text_assemble('"' . $param . '"', true); } else { $temp = db_like_assemble($param); } if ($row['cf_type'] == 'short_trans' || $row['cf_type'] == 'long_trans') { $where_clause .= preg_replace('#\\?#', 't' . strval(count($trans_fields) + 1) . '.text_original', $temp); } else { $where_clause .= preg_replace('#\\?#', 'field_' . strval($row['id']), $temp); } } if (strpos($storage_type, '_trans') === false) { $raw_fields[] = 'field_' . strval($row['id']); } else { $trans_fields[] = 'field_' . strval($row['id']); } } $age_range = get_param('option__age_range', get_param('option__age_range_from', '') . '-' . get_param('option__age_range_to', '')); if ($age_range != '' && $age_range != '-') { $bits = explode('-', $age_range); if (count($bits) == 2) { $lower = strval(intval(date('Y', utctime_to_usertime())) - intval($bits[0])); $upper = strval(intval(date('Y', utctime_to_usertime())) - intval($bits[1])); $where_clause .= ' AND '; $where_clause .= '(m_dob_year<' . $lower . ' OR m_dob_year=' . $lower . ' AND (m_dob_month<' . date('m') . ' OR m_dob_month=' . date('m') . ' AND m_dob_day<=' . date('d') . '))'; $where_clause .= ' AND '; $where_clause .= '(m_dob_year>' . $upper . ' OR m_dob_year=' . $upper . ' AND (m_dob_month>' . date('m') . ' OR m_dob_month=' . date('m') . ' AND m_dob_day>=' . date('d') . '))'; } if (either_param_integer('option__photo_thumb_url', 0) == 1) { $where_clause .= ' AND '; $where_clause .= db_string_not_equal_to('m_photo_thumb_url', ''); } } $user_group = get_param('option__user_group', ''); if ($user_group != '') { $bits = explode(',', $user_group); $where_clause .= ' AND '; $group_where_clause = ''; foreach ($bits as $i => $bit) { $group = intval($bit); $table .= ' LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_group_members g' . strval($i) . ' ON (g' . strval($i) . '.gm_group_id=' . strval($group) . ' AND g' . strval($i) . '.gm_member_id=r.id)'; if ($group_where_clause != '') { $group_where_clause .= ' OR '; } $group_where_clause .= 'g' . strval($i) . '.gm_validated=1 OR m_primary_group=' . strval($group); } $where_clause .= '(' . $group_where_clause . ')'; } if (!has_specific_permission(get_member(), 'see_unvalidated')) { $where_clause .= ' AND '; $where_clause .= 'm_validated=1'; } // Calculate and perform query $rows = get_search_rows(NULL, NULL, $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, 'f_members r JOIN ' . get_table_prefix() . 'f_member_custom_fields a ON r.id=a.mf_member_id' . $table, array('!', 'm_signature') + $trans_fields, $where_clause, $content_where, $remapped_orderer, 'r.*,a.*,r.id AS id', $raw_fields); $out = array(); foreach ($rows as $i => $row) { /*if ($user_group!='') { $bits=explode(',',$user_group); $ok=false; $groups=$GLOBALS['FORUM_DRIVER']->get_members_groups($row['id']); foreach ($bits as $bit) { if (in_array($user_group,$groups)) $ok=true; } if (!$ok) continue; }*/ if (!is_guest($row['id'])) { $out[$i]['data'] = $row; if ($remapped_orderer != '' && array_key_exists($remapped_orderer, $row)) { $out[$i]['orderer'] = $row[$remapped_orderer]; } elseif (substr($remapped_orderer, 0, 7) == '_rating') { $out[$i]['orderer'] = $row['compound_rating']; } } else { $out[$i]['data'] = NULL; } unset($rows[$i]); } return $out; }
/** * Get the values for the specified fields, for the stated catalogue entry. * * @param ?ID_TEXT The catalogue name we are getting an entry in (NULL: lookup) * @param mixed The ID of the entry we are getting OR the row * @param ?array A list of fields that we are limiting ourselves to (NULL: get ALL fields) * @param ?array The database rows for the fields for this catalogue (NULL: find them) * @param boolean Whether to order the fields in their natural database order * @param ID_TEXT The view type we're doing * @set PAGE SEARCH CATEGORY * @return array A list of maps (each field for the entry gets a map), where each map contains 'effective_value' (the value for the field). Some maps get additional fields (effective_value_nontrans, effective_value_pure), depending on the field type */ function get_catalogue_entry_field_values($catalogue_name, $entry_id, $only_fields = NULL, $fields = NULL, $natural_order = false, $view_type = 'PAGE') { global $CAT_FIELDS_CACHE; if (is_null($fields)) { if (isset($CAT_FIELDS_CACHE[$catalogue_name]) && !$natural_order) { $fields = $CAT_FIELDS_CACHE[$catalogue_name]; } else { if (is_null($catalogue_name)) { $catalogue_name = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'c_name', array('id' => $entry_id)); } $fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $catalogue_name), 'ORDER BY ' . ($natural_order ? 'id' : 'cf_order')); } } if (!$natural_order) { $CAT_FIELDS_CACHE[$catalogue_name] = $fields; } require_code('fields'); // Work out an ID filter for what fields to show $only_field_ids = mixed(); if (get_value('catalogue_limit_cat_field_load__' . $catalogue_name) === '1') { $only_field_ids = array(); foreach ($fields as $i => $field) { $field_id = $field['id']; if (!is_null($only_fields) && !in_array($i, $only_fields)) { continue; } if ($field['cf_defines_order'] == 0) { if ($view_type == 'CATEGORY' && $field['cf_put_in_category'] == 0) { continue; } if ($view_type == 'SEARCH' && $field['cf_put_in_search'] == 0) { continue; } } $only_field_ids[] = $field_id; } } foreach ($fields as $i => $field) { $field_id = $field['id']; if (!is_null($only_fields) && !in_array($i, $only_fields)) { continue; } $ob = get_fields_hook($field['cf_type']); list($raw_type, , $type) = $ob->get_field_value_row_bits($field); if (is_null($raw_type)) { $raw_type = $field['cf_type']; } switch ($raw_type) { case 'short_trans': $fields[$i]['effective_value_nontrans'] = _get_catalogue_entry_field($field_id, $entry_id, 'short_trans', $only_field_ids); if (is_null($fields[$i]['effective_value_nontrans'])) { $fields[$i]['effective_value'] = do_lang_tempcode('INTERNAL_ERROR'); $fields[$i]['effective_value_pure'] = do_lang('INTERNAL_ERROR'); break; } $fields[$i]['effective_value'] = get_translated_tempcode(intval($fields[$i]['effective_value_nontrans'])); $fields[$i]['effective_value_pure'] = get_translated_text(intval($fields[$i]['effective_value_nontrans'])); break; case 'long_trans': $fields[$i]['effective_value_nontrans'] = _get_catalogue_entry_field($field_id, $entry_id, 'long_trans', $only_field_ids); if (is_null($fields[$i]['effective_value_nontrans'])) { $fields[$i]['effective_value'] = do_lang_tempcode('INTERNAL_ERROR'); $fields[$i]['effective_value_pure'] = do_lang('INTERNAL_ERROR'); break; } $fields[$i]['effective_value'] = get_translated_tempcode(intval($fields[$i]['effective_value_nontrans'])); $fields[$i]['effective_value_pure'] = get_translated_text(intval($fields[$i]['effective_value_nontrans'])); break; case 'long_text': $fields[$i]['effective_value_pure'] = _get_catalogue_entry_field($field_id, $entry_id, 'long', $only_field_ids); $fields[$i]['effective_value'] = $fields[$i]['effective_value_pure']; if (is_null($fields[$i]['effective_value'])) { $fields[$i]['effective_value'] = do_lang_tempcode('INTERNAL_ERROR'); $fields[$i]['effective_value_pure'] = do_lang('INTERNAL_ERROR'); break; } break; case 'short_text': $fields[$i]['effective_value_pure'] = _get_catalogue_entry_field($field_id, $entry_id, 'short', $only_field_ids); $fields[$i]['effective_value'] = $fields[$i]['effective_value_pure']; if (is_null($fields[$i]['effective_value'])) { $fields[$i]['effective_value'] = do_lang_tempcode('NA_EM'); $fields[$i]['effective_value_pure'] = do_lang('NA'); break; } break; case 'long_unescaped': $fields[$i]['effective_value'] = _get_catalogue_entry_field($field_id, $entry_id, 'long', $only_field_ids); if (is_null($fields[$i]['effective_value'])) { $fields[$i]['effective_value'] = do_lang_tempcode('NA_EM'); $fields[$i]['effective_value_pure'] = do_lang('NA'); break; } break; case 'short_unescaped': case 'float_unescaped': case 'integer_unescaped': $fields[$i]['effective_value'] = _get_catalogue_entry_field($field_id, $entry_id, $type, $only_field_ids); if (is_null($fields[$i]['effective_value'])) { $fields[$i]['effective_value'] = do_lang_tempcode('NA_EM'); $fields[$i]['effective_value_pure'] = do_lang('NA'); break; } break; default: warn_exit(do_lang_tempcode('INTERNAL_ERROR')); } } return $fields; }
/** * Standard modular run function for search results. * * @param string Search string * @param boolean Whether to only do a META (tags) search * @param ID_TEXT Order direction * @param integer Start position in total results * @param integer Maximum results to return in total * @param boolean Whether only to search titles (as opposed to both titles and content) * @param string Where clause that selects the content according to the main search string (SQL query fragment) (blank: full-text search) * @param SHORT_TEXT Username/Author to match for * @param ?MEMBER Member-ID to match for (NULL: unknown) * @param TIME Cutoff date * @param string The sort type (gets remapped to a field in this function) * @set title add_date * @param integer Limit to this number of results * @param string What kind of boolean search to do * @set or and * @param string Where constraints known by the main search code (SQL query fragment) * @param string Comma-separated list of categories to search under * @param boolean Whether it is a boolean search * @return array List of maps (template, orderer) */ function run($content, $only_search_meta, $direction, $max, $start, $only_titles, $content_where, $author, $author_id, $cutoff, $sort, $limit_to, $boolean_operator, $where_clause, $search_under, $boolean_search) { unset($limit_to); if (!module_installed('catalogues')) { return array(); } $remapped_orderer = ''; switch ($sort) { case 'rating': $remapped_orderer = '_rating:catalogues:id'; break; case 'title': $remapped_orderer = 'b_cv_value'; break; case 'add_date': $remapped_orderer = 'ce_add_date'; break; case 'relevance': break; default: $remapped_orderer = preg_replace('#[^\\w]#', '', $sort); break; } require_code('catalogues'); require_lang('catalogues'); // Calculate our where clause (search) $sq = build_search_submitter_clauses('ce_submitter', $author_id, $author); if (is_null($sq)) { return array(); } else { $where_clause .= $sq; } if (!is_null($cutoff)) { $where_clause .= ' AND '; $where_clause .= 'r.ce_add_date>' . strval($cutoff); } if (!$GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) { $where_clause .= ' AND '; $where_clause .= 'z.category_name IS NOT NULL'; $where_clause .= ' AND '; $where_clause .= 'p.category_name IS NOT NULL'; } if (!has_specific_permission(get_member(), 'see_unvalidated')) { $where_clause .= ' AND '; $where_clause .= 'ce_validated=1'; } $g_or = _get_where_clause_groups(get_member()); // Calculate and perform query $catalogue_name = get_param('catalogue_name', ''); $ranges = array(); if ($catalogue_name != '') { $extra_select = ''; $rows = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id', 'cf_name', 'cf_type', 'cf_default'), array('c_name' => $catalogue_name, 'cf_searchable' => 1), 'ORDER BY cf_order'); $table = 'catalogue_entries r'; $trans_fields = array('!'); $nontrans_fields = array(); $title_field = mixed(); require_code('fields'); foreach ($rows as $i => $row) { $ob = get_fields_hook($row['cf_type']); $temp = $ob->inputted_to_sql_for_search($row, $i); if (is_null($temp)) { list(, , $row_type) = $ob->get_field_value_row_bits($row); switch ($row_type) { case 'long_trans': $trans_fields[] = 'f' . strval($i) . '.cv_value'; $table .= ' JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_efv_long_trans f' . strval($i) . ' ON (f' . strval($i) . '.ce_id=r.id AND f' . strval($i) . '.cf_id=' . strval($row['id']) . ')'; $search_field = 't' . strval(count($trans_fields) - 1) . '.text_original'; //$extra_select.=',t'.strval(count($trans_fields)-1).'.text_original AS f'.strval($i).'_actual_value'; break; case 'short_trans': $trans_fields[] = 'f' . strval($i) . '.cv_value'; $table .= ' JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_efv_short_trans f' . strval($i) . ' ON (f' . strval($i) . '.ce_id=r.id AND f' . strval($i) . '.cf_id=' . strval($row['id']) . ')'; $search_field = 't' . strval(count($trans_fields) - 1) . '.text_original'; //$extra_select.=',t'.strval(count($trans_fields)-1).'.text_original AS f'.strval($i).'_actual_value'; break; case 'long': $nontrans_fields[] = 'f' . strval($i) . '.cv_value'; $table .= ' JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_efv_long f' . strval($i) . ' ON (f' . strval($i) . '.ce_id=r.id AND f' . strval($i) . '.cf_id=' . strval($row['id']) . ')'; $search_field = 'f' . strval($i) . '.cv_value'; //$extra_select.=',f'.strval($i).'.cv_value AS f'.strval($i).'_actual_value'; break; case 'short': $nontrans_fields[] = 'f' . strval($i) . '.cv_value'; $table .= ' JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_efv_short f' . strval($i) . ' ON (f' . strval($i) . '.ce_id=r.id AND f' . strval($i) . '.cf_id=' . strval($row['id']) . ')'; $search_field = 'f' . strval($i) . '.cv_value'; //$extra_select.=',f'.strval($i).'.cv_value AS f'.strval($i).'_actual_value'; break; case 'float': //$nontrans_fields[]='f'.strval($i).'.cv_value'; $table .= ' JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_efv_float f' . strval($i) . ' ON (f' . strval($i) . '.ce_id=r.id AND f' . strval($i) . '.cf_id=' . strval($row['id']) . ')'; $search_field = 'f' . strval($i) . '.cv_value'; //$extra_select.=',f'.strval($i).'.cv_value AS f'.strval($i).'_actual_value'; break; case 'integer': //$nontrans_fields[]='f'.strval($i).'.cv_value'; $table .= ' JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_efv_integer f' . strval($i) . ' ON (f' . strval($i) . '.ce_id=r.id AND f' . strval($i) . '.cf_id=' . strval($row['id']) . ')'; $search_field = 'f' . strval($i) . '.cv_value'; //$extra_select.=',f'.strval($i).'.cv_value AS f'.strval($i).'_actual_value'; break; } $param = get_param('option_' . strval($row['id']), ''); if ($param != '') { $where_clause .= ' AND '; if (substr($param, 0, 1) == '=') { $where_clause .= db_string_equal_to($search_field, substr($param, 1)); } elseif ($row_type == 'integer' || $row_type == 'float') { if (is_numeric($param)) { $where_clause .= $search_field . '=' . $param; } else { $where_clause .= db_string_equal_to($search_field, $param); } } else { if (db_has_full_text($GLOBALS['SITE_DB']->connection_read) && method_exists($GLOBALS['SITE_DB']->static_ob, 'db_has_full_text_boolean') && $GLOBALS['SITE_DB']->static_ob->db_has_full_text_boolean() && !is_under_radar($param)) { $temp = db_full_text_assemble($param, true); } else { $temp = db_like_assemble($param); } $where_clause .= preg_replace('#\\?#', $search_field, $temp); } } else { $param = get_param('option_' . strval($row['id']) . '_ranged', ''); if ($param != '') { $ranges[$row['id']] = $param; } } } else { $table .= $temp[2]; $search_field = $temp[3]; if ($temp[4] != '') { $where_clause .= ' AND '; $where_clause .= $temp[4]; } else { $trans_fields = array_merge($trans_fields, $temp[0]); $non_trans_fields = array_merge($nontrans_fields, $temp[1]); } } if ($i == 0) { $title_field = $search_field; } } $where_clause .= ' AND '; $where_clause .= db_string_equal_to('r.c_name', $catalogue_name); if (is_null($title_field)) { return array(); } // No fields in catalogue -- very odd if ($g_or == '') { $rows = get_search_rows('catalogue_entry', 'id', $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, $table, $trans_fields, $where_clause, $content_where, str_replace('b_cv_value', $title_field, $remapped_orderer), 'r.*,r.id AS id,r.cc_id AS r_cc_id,' . $title_field . ' AS b_cv_value' . $extra_select, $nontrans_fields); } else { $rows = get_search_rows('catalogue_entry', 'id', $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, $table . ' LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'group_category_access z ON (' . db_string_equal_to('z.module_the_name', 'catalogues_category') . ' AND z.category_name=r.cc_id AND ' . str_replace('group_id', 'z.group_id', $g_or) . ') LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'group_category_access p ON (' . db_string_equal_to('p.module_the_name', 'catalogues_catalogue') . ' AND p.category_name=r.c_name AND ' . str_replace('group_id', 'p.group_id', $g_or) . ')', $trans_fields, $where_clause, $content_where, str_replace('b_cv_value', $title_field, $remapped_orderer), 'r.*,r.id AS id,r.cc_id AS r_cc_id,' . $title_field . ' AS b_cv_value' . $extra_select, $nontrans_fields); } } else { if ($GLOBALS['SITE_DB']->query_value('translate', 'COUNT(*)') > 10000) { $trans_fields = array(); $join = ' JOIN ' . get_table_prefix() . 'catalogue_efv_short c ON (r.id=c.ce_id AND f.id=c.cf_id)'; $_remapped_orderer = str_replace('b_cv_value', 'c.cv_value', $remapped_orderer); $extra_select = ''; $non_trans_fields = array('c.cv_value'); } else { $join = ' LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_short_trans a ON (r.id=a.ce_id AND f.id=a.cf_id) LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_long_trans b ON (r.id=b.ce_id AND f.id=b.cf_id) LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_long d ON (r.id=d.ce_id AND f.id=d.cf_id) LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_short c ON (r.id=c.ce_id AND f.id=c.cf_id)'; //' LEFT JOIN '.get_table_prefix().'catalogue_efv_float g ON (r.id=g.ce_id AND f.id=g.cf_id) LEFT JOIN '.get_table_prefix().'catalogue_efv_integer h ON (r.id=h.ce_id AND f.id=h.cf_id)'; $trans_fields = array('a.cv_value', 'b.cv_value'); $_remapped_orderer = str_replace('b_cv_value', 'b.cv_value', $remapped_orderer); $extra_select = ',b.cv_value AS b_cv_value'; $non_trans_fields = array('c.cv_value', 'd.cv_value'); } $where_clause .= ' AND '; $where_clause .= 'r.c_name NOT LIKE \'\\_%\''; // Don't want results drawn from the hidden custom-field catalogues if ($g_or == '') { $rows = get_search_rows('catalogue_entry', 'id', $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, 'catalogue_fields f LEFT JOIN ' . get_table_prefix() . 'catalogue_entries r ON (r.c_name=f.c_name)' . $join, $trans_fields, $where_clause, $content_where, $_remapped_orderer, 'r.*,r.id AS id,r.cc_id AS r_cc_id' . $extra_select, $non_trans_fields); } else { $rows = get_search_rows('catalogue_entry', 'id', $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, 'catalogue_fields f LEFT JOIN ' . get_table_prefix() . 'catalogue_entries r ON (r.c_name=f.c_name)' . $join . ' LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'group_category_access z ON (' . db_string_equal_to('z.module_the_name', 'catalogues_category') . ' AND z.category_name=r.cc_id AND ' . str_replace('group_id', 'z.group_id', $g_or) . ') LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'group_category_access p ON (' . db_string_equal_to('p.module_the_name', 'catalogues_catalogue') . ' AND p.category_name=r.c_name AND ' . str_replace('group_id', 'p.group_id', $g_or) . ')', $trans_fields, $where_clause, $content_where, $_remapped_orderer, 'r.*,r.id AS id,r.cc_id AS r_cc_id' . $extra_select, $non_trans_fields); } } $out = array(); if (count($rows) == 0) { return array(); } global $SEARCH_CATALOGUE_ENTRIES_CATALOGUES; $query = 'SELECT c.* FROM ' . get_table_prefix() . 'catalogues c'; if (can_arbitrary_groupby()) { $query .= ' JOIN ' . get_table_prefix() . 'catalogue_entries e ON e.c_name=c.c_name GROUP BY c.c_name'; } $_catalogues = $GLOBALS['SITE_DB']->query($query); foreach ($_catalogues as $catalogue) { $SEARCH_CATALOGUE_ENTRIES_CATALOGUES[$catalogue['c_name']] = $catalogue; } if (count($ranges) != 0) { foreach ($rows as $i => $row) { $out[$i]['data'] = $row; unset($rows[$i]); $catalogue_name = $row['c_name']; $tpl_set = $catalogue_name; $display = get_catalogue_entry_map($row, $SEARCH_CATALOGUE_ENTRIES_CATALOGUES[$catalogue_name], 'PAGE', $tpl_set, -1); foreach ($ranges as $range_id => $range_key) { $bits = explode('-', $display['_FIELD_' . strval($range_id)]); if (count($bits) == 2) { if (intval($bits[0]) >= intval($range_key) || intval($bits[1]) <= intval($range_key)) { $out[$i]['restricted'] = true; continue 2; } } } //$out[$i]['template']=do_template('CATALOGUE_'.$tpl_set.'_ENTRY_EMBED',$display,NULL,false,'CATALOGUE_DEFAULT_ENTRY_EMBED');//put_in_table(hyperlink($url,do_lang('_HERE')),'internal','middle','WIDE',1,do_lang('CATALOGUE_ENTRY').' ('.do_lang('IN',get_translated_text($catalogue['c_title'])).')'); if ($remapped_orderer != '' && array_key_exists($remapped_orderer, $row)) { $out[$i]['orderer'] = $row[$remapped_orderer]; } elseif (substr($remapped_orderer, 0, 7) == '_rating') { $out[$i]['orderer'] = $row['compound_rating']; } } } else { foreach ($rows as $i => $row) { $out[$i]['data'] = $row; unset($rows[$i]); if ($remapped_orderer != '' && array_key_exists($remapped_orderer, $row)) { $out[$i]['orderer'] = $row[$remapped_orderer]; } elseif (substr($remapped_orderer, 0, 7) == '_rating') { $out[$i]['orderer'] = $row['compound_rating']; } } } return $out; }
/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { $catalogue_name = array_key_exists('param', $map) ? $map['param'] : ''; if ($catalogue_name == '') { $catalogue_name = $GLOBALS['SITE_DB']->query_value('catalogues', 'c_name'); } // Random/arbitrary (first one that comes out of the DB) $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title')); if (post_param('subject', '') != '') { require_code('mail'); $to_email = array_key_exists('to', $map) ? $map['to'] : ''; if ($to_email == '') { $to_email = NULL; } form_to_email(NULL, '', NULL, $to_email); attach_message(do_lang_tempcode('SUCCESS')); } require_code('form_templates'); $fields = new ocp_tempcode(); $special_fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $catalogue_name), 'ORDER BY cf_order'); $field_groups = array(); $hidden = new ocp_tempcode(); require_code('fields'); foreach ($special_fields as $field_num => $field) { $ob = get_fields_hook($field['cf_type']); $default = $field['cf_default']; $_cf_name = get_translated_text($field['cf_name']); $field_cat = ''; $matches = array(); if (strpos($_cf_name, ': ') !== false) { $field_cat = substr($_cf_name, 0, strpos($_cf_name, ': ')); if ($field_cat . ': ' == $_cf_name) { $_cf_name = $field_cat; // Just been pulled out as heading, nothing after ": " } else { $_cf_name = substr($_cf_name, strpos($_cf_name, ': ') + 2); } } if (!array_key_exists($field_cat, $field_groups)) { $field_groups[$field_cat] = new ocp_tempcode(); } $_cf_description = escape_html(get_translated_text($field['cf_description'])); $GLOBALS['NO_DEBUG_MODE_FULLSTOP_CHECK'] = true; $result = $ob->get_field_inputter($_cf_name, $_cf_description, $field, $default, true, !array_key_exists($field_num + 1, $special_fields)); $GLOBALS['NO_DEBUG_MODE_FULLSTOP_CHECK'] = false; if (is_null($result)) { continue; } if (is_array($result)) { $field_groups[$field_cat]->attach($result[0]); } else { $field_groups[$field_cat]->attach($result); } $hidden->attach(form_input_hidden('label_for__field_' . strval($field['id']), $_cf_name)); unset($result); unset($ob); } if (array_key_exists('', $field_groups)) { $field_groups_blank = $field_groups['']; unset($field_groups['']); $field_groups = array_merge(array($field_groups_blank), $field_groups); } foreach ($field_groups as $field_group_title => $extra_fields) { if (is_integer($field_group_title)) { $field_group_title = $field_group_title == 0 ? '' : strval($field_group_title); } if ($field_group_title != '') { $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => $field_group_title))); } $fields->attach($extra_fields); } $hidden->attach(form_input_hidden('subject', $catalogue_title)); $url = get_self_url(); return do_template('FORM', array('FIELDS' => $fields, 'HIDDEN' => $hidden, 'SUBMIT_NAME' => do_lang_tempcode('SEND'), 'URL' => $url, 'TEXT' => '')); }
/** * Returns a list of all field values for user. Doesn't take translation into account. Doesn't take anything permissive into account. * * @param MEMBER The member. * @return array The list. */ function ocf_get_custom_field_mappings($member_id) { require_code('fields'); global $MEMBER_CACHE_FIELD_MAPPINGS; if (!array_key_exists($member_id, $MEMBER_CACHE_FIELD_MAPPINGS)) { $query = $GLOBALS['FORUM_DB']->query_select('f_member_custom_fields', array('*'), array('mf_member_id' => $member_id), '', 1); if (!array_key_exists(0, $query)) { $all_fields_regardless = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_type')); $row = array('mf_member_id' => $member_id); foreach ($all_fields_regardless as $field) { $ob = get_fields_hook($field['cf_type']); list(, $default, $storage_type) = $ob->get_field_value_row_bits($field, false, '', $GLOBALS['FORUM_DB']); if (strpos($storage_type, '_trans') !== false) { $row['field_' . strval($field['id'])] = intval($default); } else { $row['field_' . strval($field['id'])] = $default; } } $GLOBALS['FORUM_DB']->query_insert('f_member_custom_fields', $row); $query = array($row); } $MEMBER_CACHE_FIELD_MAPPINGS[$member_id] = $query[0]; } return $MEMBER_CACHE_FIELD_MAPPINGS[$member_id]; }
/** * Get a entry-id=>value map of what a submitted catalogue entry form has set * * @param ID_TEXT The name of the catalogue that was used * @param ?AUTO_LINK ID of entry being edited (NULL: not being edited) * @return array The map */ function get_set_field_map($catalogue_name, $editing_id = NULL) { // Get field values $fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $catalogue_name), 'ORDER BY cf_order'); $map = array(); require_code('fields'); require_code('catalogues'); foreach ($fields as $field) { $object = get_fields_hook($field['cf_type']); list(, , $storage_type) = $object->get_field_value_row_bits($field); $value = $object->inputted_to_field_value(!is_null($editing_id), $field, 'uploads/catalogues', is_null($editing_id) ? NULL : _get_catalogue_entry_field($field['id'], $editing_id, $storage_type)); $map[$field['id']] = $value; } return $map; }
/** * Set a custom profile field for a member. * * @param MEMBER The member. * @param AUTO_LINK The field being set. * @param mixed The value of the field. For a trans-type field, this can be either a lang-ID to be copied (from forum DB), or an actual string. * @param ?ID_TEXT The field type (NULL: look it up). * @param boolean Whether to defer the change, by returning a result change rather than doing it right away. * @return ?array Mapping change (NULL: none / can't defer). */ function ocf_set_custom_field($member_id, $field, $value, $type = NULL, $defer = false) { if (is_null($type)) { $type = $GLOBALS['FORUM_DB']->query_value('f_custom_fields', 'cf_type', array('id' => $field)); } ocf_get_custom_field_mappings($member_id); // This will do an auto-repair if CPF storage row is missing global $ANY_FIELD_ENCRYPTED; if ($ANY_FIELD_ENCRYPTED === NULL) { $ANY_FIELD_ENCRYPTED = !is_null($GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields', 'cf_encrypted', array('cf_encrypted' => 1))); } if ($ANY_FIELD_ENCRYPTED) { $encrypted = $GLOBALS['FORUM_DB']->query_value('f_custom_fields', 'cf_encrypted', array('id' => $field)); if ($encrypted) { require_code('encryption'); $current = $GLOBALS['FORUM_DB']->query_value('f_member_custom_fields', 'field_' . strval(intval($field)), array('mf_member_id' => $member_id)); if (remove_magic_encryption_marker($value) == remove_magic_encryption_marker($current) && is_data_encrypted($current)) { return NULL; } $value = encrypt_data($value); } } else { $encrypted = false; } require_code('fields'); $ob = get_fields_hook($type); list(, , $storage_type) = $ob->get_field_value_row_bits(array('id' => $field, 'cf_default' => '', 'cf_type' => $type)); if (strpos($storage_type, '_trans') !== false) { if (is_integer($value)) { $value = get_translated_text($value, $GLOBALS['FORUM_DB']); } $current = $GLOBALS['FORUM_DB']->query_value('f_member_custom_fields', 'field_' . strval(intval($field)), array('mf_member_id' => $member_id)); if (is_null($current)) { if ($type == 'posting_field') { require_code('attachments2'); $current = insert_lang_comcode_attachments(3, $value, 'null', strval($member_id), $GLOBALS['FORUM_DB']); } else { $current = insert_lang_comcode($value, 3, $GLOBALS['FORUM_DB']); } $GLOBALS['FORUM_DB']->query_update('f_member_custom_fields', array('field_' . strval(intval($field)) => $current), array('mf_member_id' => $member_id), '', 1); } else { if ($type == 'posting_field') { require_code('attachments2'); require_code('attachments3'); update_lang_comcode_attachments($current, $value, 'null', strval($member_id), $GLOBALS['FORUM_DB'], false, $member_id); } else { lang_remap_comcode($current, $value, $GLOBALS['FORUM_DB']); } } } else { $change = array('field_' . strval(intval($field)) => $value); if (!$defer) { $GLOBALS['FORUM_DB']->query_update('f_member_custom_fields', $change, array('mf_member_id' => $member_id), '', 1); } return $change; } return NULL; }
/** * Get a list of all field types to choose from. * * @param ID_TEXT Field type to select * @param boolean Whether to only show options in the same storage set as $type * @return tempcode List of field types */ function nice_get_field_type($type = '', $limit_to_storage_set = false) { require_lang('fields'); $all_types = find_all_hooks('systems', 'fields'); if ($limit_to_storage_set) { $ob = get_fields_hook($type); $types = array(); list(, , $db_type) = $ob->get_field_value_row_bits(NULL); foreach ($all_types as $this_type => $hook_type) { $ob = get_fields_hook($this_type); list(, , $this_db_type) = $ob->get_field_value_row_bits(NULL); if ($this_db_type == $db_type) { $types[$this_type] = $hook_type; } } } else { $types = $all_types; } $orderings = array(do_lang_tempcode('FIELD_TYPES__TEXT'), 'short_trans', 'short_trans_multi', 'short_text', 'short_text_multi', 'long_trans', 'long_text', 'posting_field', 'codename', 'password', 'email', do_lang_tempcode('FIELD_TYPES__NUMBERS'), 'integer', 'float', do_lang_tempcode('FIELD_TYPES__CHOICES'), 'list', 'radiolist', 'tick', 'multilist', 'tick_multi', do_lang_tempcode('FIELD_TYPES__UPLOADSANDURLS'), 'upload', 'picture', 'video', 'url', 'page_link', 'theme_image', 'theme_image_multi', do_lang_tempcode('FIELD_TYPES__MAGIC'), 'auto_increment', 'random', 'guid', do_lang_tempcode('FIELD_TYPES__REFERENCES'), 'isbn', 'reference', 'content_link', 'content_link_multi', 'user', 'user_multi', 'author'); $_types = array(); $done_one_in_section = true; foreach ($orderings as $o) { if (is_object($o)) { if (!$done_one_in_section) { array_pop($_types); } $_types[] = $o; $done_one_in_section = false; } else { if (array_key_exists($o, $types)) { $_types[] = $o; unset($types[$o]); $done_one_in_section = true; } } } if (!$done_one_in_section) { array_pop($_types); } if (count($types) != 0) { $types = array_merge($_types, array(do_lang_tempcode('FIELD_TYPES__OTHER')), array_keys($types)); } else { $types = $_types; } $type_list = new ocp_tempcode(); foreach ($types as $_type) { if (is_object($_type)) { if (!$type_list->is_empty()) { $type_list->attach(form_input_list_entry('', false, escape_html(''), false, true)); } $type_list->attach(form_input_list_entry('', false, $_type, false, true)); } else { $ob = get_fields_hook($_type); if (method_exists($ob, 'get_field_types')) { $sub_types = $ob->get_field_types(); } else { $sub_types = array($_type => do_lang_tempcode('FIELD_TYPE_' . $_type)); } foreach ($sub_types as $__type => $_title) { $type_list->attach(form_input_list_entry($__type, $__type == $type, $_title)); } } } return make_string_tempcode($type_list->evaluate()); // XHTMLXHTML }
/** * Delete a catalogue entry. * * @param AUTO_LINK The ID of the entry to delete */ function actual_delete_catalogue_entry($id) { $old_category_id = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'cc_id', array('id' => $id)); $catalogue_name = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'c_name', array('id' => $id)); require_code('fields'); require_code('catalogues'); $fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $catalogue_name)); $title = NULL; foreach ($fields as $field) { $object = get_fields_hook($field['cf_type']); list(, , $storage_type) = $object->get_field_value_row_bits($field); $value = _get_catalogue_entry_field($field['id'], $id, $storage_type); if (method_exists($object, 'cleanup')) { $object->cleanup($value); } if (is_null($title)) { if ($storage_type == 'long_trans' || $storage_type == 'short_trans') { $title = get_translated_text(intval($value)); } else { $title = $value; } } } $lang1 = $GLOBALS['SITE_DB']->query_select('catalogue_efv_long_trans', array('cv_value'), array('ce_id' => $id)); $lang2 = $GLOBALS['SITE_DB']->query_select('catalogue_efv_short_trans', array('cv_value'), array('ce_id' => $id)); $lang = array_merge($lang1, $lang2); foreach ($lang as $lang_to_delete) { if (true) { require_code('attachments2'); require_code('attachments3'); delete_lang_comcode_attachments($lang_to_delete['cv_value'], 'catalogue_entry', strval($id)); } else { delete_lang($lang_to_delete['cv_value']); } } $GLOBALS['SITE_DB']->query_delete('catalogue_efv_long_trans', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_short_trans', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_long', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_short', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_float', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_integer', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_entries', array('id' => $id), '', 1); $GLOBALS['SITE_DB']->query_delete('trackbacks', array('trackback_for_type' => 'catalogues', 'trackback_for_id' => $id)); $GLOBALS['SITE_DB']->query_delete('rating', array('rating_for_type' => 'catalogues', 'rating_for_id' => $id)); require_code('seo2'); seo_meta_erase_storage('catalogue_entry', strval($id)); calculate_category_child_count_cache($old_category_id); decache('main_recent_cc_entries'); decache('main_cc_embed'); if ($catalogue_name[0] != '_') { log_it('DELETE_CATALOGUE_ENTRY', strval($id), $title); } }