function photoplog_doadd_doedit_worker($new_fielddata, $catid, $fieldtype, $current_fielddata) { global $vbulletin, $vbphrase; $doadd = empty($current_fielddata); $new_fielddata_name = $doadd ? trim($new_fielddata['name']) : $current_fielddata['name']; $new_fielddata_groupid = $doadd ? intval(trim($new_fielddata['groupid'])) : $current_fielddata['groupid']; $all_groups = photoplog_get_all_groups(); if ($doadd) { if ($new_fielddata_groupid) { if ($new_fielddata_name) { if ($all_groups[$new_fielddata_groupid] != $new_fielddata_name) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_name_inconsistent']); } } else { $new_fielddata_name = trim($all_groups[$new_fielddata_groupid]); } } else { if (in_array($new_fielddata_name, $all_groups)) { foreach ($all_groups as $gid => $gname) { if ($new_fielddata_name == $gname) { $new_fielddata_groupid = intval($gid); break; } } } } } $new_fielddata_title = trim($new_fielddata['title']); $new_fielddata_description = trim($new_fielddata['description']); $new_fielddata_maxlength = intval(trim($new_fielddata['maxlength'])); $new_fielddata_default = trim($new_fielddata['default']); $new_fielddata_size = intval(trim($new_fielddata['size'])); $new_fielddata_height = intval(trim($new_fielddata['height'])); $new_fielddata_options = trim($new_fielddata['options']); $new_fielddata_options = explode("\n", $new_fielddata_options); if (is_array($new_fielddata_options)) { foreach ($new_fielddata_options as $option_key => $option_value) { $new_fielddata_options[$option_key] = trim($option_value); } } else { $new_fielddata_options = array(); } $new_fielddata_limit = intval(trim($new_fielddata['limit'])); $new_fielddata_perline = intval(trim($new_fielddata['perline'])); $new_fielddata_active = intval(trim($new_fielddata['active'])); $new_fielddata_hidden = intval(trim($new_fielddata['hidden'])); $new_fielddata_required = intval(trim($new_fielddata['required'])); $new_fielddata_inherited = intval(trim($new_fielddata['inherited'])); $info = array(); $info['type'] = $fieldtype; if (vbstrlen($new_fielddata_name) < 3 || vbstrlen($new_fielddata_name) > 50) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_name'], 3, 50)); } if (vbstrlen($new_fielddata_title) > 50) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_title'], 50)); } else { $info['title'] = $new_fielddata_title; } if (vbstrlen($new_fielddata_description) > 250) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_description'], 250)); } else { $info['description'] = $new_fielddata_description; } if ($fieldtype <= 1) { if ($new_fielddata_maxlength < 1 || $new_fielddata_maxlength > 1024) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_maxlength'], 1, 1024)); } else { $info['maxlength'] = $new_fielddata_maxlength; } if (vbstrlen($new_fielddata_default) > $new_fielddata_maxlength) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_default_exceeds_maxlength']); } else { $info['default'] = $new_fielddata_default; } if ($new_fielddata_size < 1 || $new_fielddata_size > 100) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_size'], 1, 100)); } else { $info['size'] = $new_fielddata_size; } } if ($fieldtype >= 2) { if (count($new_fielddata_options) < 1 || count($new_fielddata_options) > 256) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_options'], 1, 256)); } else { $info['options'] = $new_fielddata_options; } if (!($new_fielddata_default == '0' || $new_fielddata_default == '1')) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_default']); } else { $info['default'] = $new_fielddata_default; } } if ($fieldtype == 1) { if ($new_fielddata_height < 2 || $new_fielddata_height > 1000) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_height'], 2, 1000)); } else { $info['height'] = $new_fielddata_height; } } if ($fieldtype == 4 || $fieldtype == 2) { if ($new_fielddata_height < 1 || $new_fielddata_height > 1000) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_height'], 0, 1000)); } else { $info['height'] = $new_fielddata_height; } } if ($fieldtype >= 4) { if ($new_fielddata_limit < 0 || $new_fielddata_limit > 1000) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_limit'], 0, 1000)); } else { $info['limit'] = $new_fielddata_limit; } } if ($fieldtype == 5 || $fieldtype == 3) { if ($new_fielddata_perline < 0 || $new_fielddata_perline > 1000) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_perline'], 1000)); } else { $info['perline'] = $new_fielddata_perline; } } if (!($new_fielddata_active == 0 || $new_fielddata_active == 1)) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_active']); } if (!($new_fielddata_hidden == 0 || $new_fielddata_hidden == 1)) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_hidden']); } if (!($new_fielddata_required == 0 || $new_fielddata_required == 1)) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_required']); } else { $info['required'] = $new_fielddata_required; } if (!($new_fielddata_inherited == 0 || $new_fielddata_inherited == 1)) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_inherited']); } $child_list = array(); $parent_list = array(); photoplog_child_list($child_list, $parent_list, $catid); $displayorder = 0; if ($doadd) { $name_in_use = false; $fields = $vbulletin->db->query_read("SELECT displayorder, groupid\r\n\t\t\tFROM " . PHOTOPLOG_PREFIX . "photoplog_customfields\r\n\t\t\tWHERE catid = " . intval($catid) . "\r\n\t\t\tORDER BY displayorder ASC\r\n\t\t"); while ($field = $vbulletin->db->fetch_array($fields)) { $displayorder = $field['displayorder']; if ($field['groupid'] == $new_fielddata_groupid) { $name_in_use = true; break; } } $vbulletin->db->free_result($fields); if ($name_in_use) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_name_in_use']); } $displayorder += 10; if ($new_fielddata_inherited == 1 && !empty($child_list)) { // check subcategories to see if there is a problem with the name! $check_subcats = $vbulletin->db->query_first("SELECT COUNT(*) AS cnt\r\n\t\t\t\tFROM " . PHOTOPLOG_PREFIX . "photoplog_customfields\r\n\t\t\t\tWHERE catid IN (" . implode(",", $child_list) . ")\r\n\t\t\t\tAND groupid = " . intval($new_fielddata_groupid) . "\r\n\t\t\t"); if (!$check_subcats || !isset($check_subcats['cnt']) || $check_subcats['cnt'] > 0) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_name_in_use_inherited']); } } } else { $displayorder = intval($current_fielddata['displayorder']); if ($new_fielddata_inherited == 1 && intval($current_fielddata['inherited']) > -1 && !empty($child_list)) { // check subcategories to see if there is a problem with the name! $check_subcats = $vbulletin->db->query_first("SELECT COUNT(*) AS cnt\r\n\t\t\t\tFROM " . PHOTOPLOG_PREFIX . "photoplog_customfields\r\n\t\t\t\tWHERE catid IN (" . implode(",", $child_list) . ")\r\n\t\t\t\tAND groupid = " . intval($new_fielddata_groupid) . "\r\n\t\t\t\tAND parentid != " . intval($catid) . "\r\n\t\t\t"); if (!$check_subcats || !isset($check_subcats['cnt']) || $check_subcats > 0) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_name_in_use_inherited']); } } } // be careful to not move the below two lines up!!! $new_fielddata_inherited = -1 * $new_fielddata_inherited; $new_fielddata_protected = 0; $info = serialize($info); if ($doadd) { if (!$new_fielddata_groupid) { $new_fielddata_groupid = photoplog_insert_customfield_group($new_fielddata_name); } if ($new_fielddata_groupid) { photoplog_insert_custom_field_recursive($child_list, $catid, $new_fielddata_groupid, $displayorder, $new_fielddata_hidden, $new_fielddata_active, $new_fielddata_protected, $new_fielddata_inherited, $catid, $info); } } else { photoplog_update_custom_field_recursive($child_list, $current_fielddata['fieldid'], $catid, $current_fielddata['groupid'], $current_fielddata['displayorder'], $new_fielddata_hidden, $new_fielddata_active, $new_fielddata_inherited, $catid, $info); } }
function photoplog_make_available_groups($catid) { global $vbphrase; $catid = intval($catid); $all_groups = photoplog_get_all_groups(); $groups_by_catid = photoplog_get_groups_by_catid($catid); $groups_and_cats = photoplog_get_groups_and_cats(); $result = array(); foreach ($all_groups as $id => $name) { if (!in_array($id, $groups_by_catid)) { $catlist = $vbphrase['photoplog_none']; if (isset($groups_and_cats[$id]) && is_array($groups_and_cats[$id])) { $catlist = implode(", ", $groups_and_cats[$id]); } $result[$id] = "<strong>" . $name . "</strong> (" . $vbphrase['photoplog_used_by_categories'] . " " . $catlist . ")"; } } return $result; }
function photoplog_make_customfield_rows($fielddata, $title, $description, $catid, $admin = '') { global $vbulletin, $vbphrase, $photoplog; $photoplog['padright'] = intval($photoplog['padright']); $customfields = ''; $all_groups = photoplog_get_all_groups(); $hidden = ''; if (!$admin) { $hidden = "AND f2.hidden = 0"; } $fields = $vbulletin->db->query_read("SELECT\r\n\t\tf1.inherited AS inherited1, f1.fieldid AS fieldid1, f1.groupid AS groupid1,\r\n\t\tf1.info AS info1 ,f2.info AS info2\r\n\t\tFROM " . PHOTOPLOG_PREFIX . "photoplog_customfields AS f1\r\n\t\tLEFT JOIN " . PHOTOPLOG_PREFIX . "photoplog_customfields AS f2\r\n\t\tON (f1.parentid = f2.catid AND f1.groupid = f2.groupid)\r\n\t\tWHERE f1.catid = " . intval($catid) . "\r\n\t\tAND f1.active = 1\r\n\t\t{$hidden}\r\n\t\tORDER BY f1.displayorder ASC\r\n\t"); while ($field = $vbulletin->db->fetch_array($fields)) { $name = isset($all_groups[$field['groupid1']]) ? $all_groups[$field['groupid1']] : ''; $fieldtitle = ''; $fieldtext = ''; if ($name == 'Title') { $fieldtitle = $vbphrase['photoplog_title']; $fieldtext = $title; } else { if ($name == 'Description') { $fieldtitle = $vbphrase['photoplog_description']; $fieldtext = $description; } else { $info = $field['inherited1'] < 1 ? $field['info1'] : $field['info2']; $info = empty($info) ? '' : unserialize($info); $fieldtitle = htmlspecialchars_uni(trim($info['title'])); $type = intval($info['type']); if ($type < 0 || $type > 5) { $type = 0; } if (isset($fielddata[$name])) { if ($type <= 3) { if (trim($fielddata[$name]) == '') { $fieldtext = $vbphrase['photoplog_not_available']; } else { $maxlength = intval($info['maxlength']); $fieldtext = trim($fielddata[$name]); if ($maxlength > 0) { $fieldtext = fetch_trimmed_title($fieldtext, $maxlength); } $fieldtext = nl2br(htmlspecialchars_uni(fetch_censored_text($fieldtext))); } } else { if (is_array($fielddata[$name])) { if (empty($fielddata[$name])) { $fieldtext = $vbphrase['photoplog_not_available']; } else { $field_options = $fielddata[$name]; foreach ($field_options as $option_key => $option_text) { $field_options[$option_key] = htmlspecialchars_uni(fetch_censored_text(trim($option_text))); } $fieldtext = implode("<br />", $field_options); } } else { $fieldtext = $vbphrase['photoplog_not_available']; } } } else { $fieldtext = $vbphrase['photoplog_not_available']; } } } $photoplog_custom_field = array('key' => $fieldtitle, 'value' => $fieldtext); eval('$customfields .= "' . fetch_template('photoplog_view_file_field') . '";'); } return $customfields; }