RC2 additional posting field oddity.

Started by zushiba, June 04, 2020, 05:39:05 PM

Previous topic - Next topic

zushiba

Okay bare with me. I'm working on updating a mod that wasn't designed for RC2. I've gotten every part of the mod to work fantastically except for one thing and for the life of me I cannot track it down.

The mod allows one to post as different "characters", this is my wifes RP forum. This is not the subaccount mod it's something different so I'm not breaking a license here.

The mod was made for 2.1 Beta 3

Here it is working on Beta 3


Here is it not working on RC2



But here's the weird thing, it's in the $context['posting_fields'] array, and working. It's just not printing to the actual page, and I cannot figure out why!


I'm at a loss as to where to go from here. The field exists in posting_fields, it's just not getting to the interface for some reason.

Deaks

Firstly what changes did you make to the mod? need to see code to be better to help
~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

zushiba

#2
Most changes were issues where the newer version of post.php had additional tabs so the search function wasn't able to find the line in the install process.

Non-working post.php on RC2

Working post.php from install of beta 3

Clean copy of Post.php from RC2

RC2 Original Post.php Diff vs Modded RC2 Post.php

Changes made during install.


Find
m.icon, m.approved,
Add After
m.id_character,



Find
m.poster_time, log.id_action
Add After
, t.date_month, t.date_day, t.date_year, t.topic_description



Find
$context['use_smileys'] = !empty($row['smileys_enabled']);
$context['icon'] = $row['icon'];

Add After
$context['id_character'] = !empty($row['id_character']) ? $row['id_character'] : 0;
$context['current_poster'] = !empty($row['id_character']) ? $row['id_character'] : 0;
$context['description'] = !empty($row['topic_description']) ? $row['topic_description'] : '';
$context['date'] = array(
'month' => !empty($row['date_month']) ? $row['date_month'] : 0,
'day' => !empty($row['date_day']) ? $row['date_day'] : 0,
'year' => !empty($row['date_year']) ? $row['date_year'] : 0,
);




Find
addInlineJavaScript('
var current_board = '. (empty($context['current_board']) ? 'null' : $context['current_board']) . ';', false);

Add After

// Can we pull NPCs?
$non_player = array();
if(allowedTo('cmod_post_npc_any'))
{
// This pulls all NPCs on the site.
$request = $smcFunc['db_query']('','
SELECT
id_character, name_first, name_last
FROM {db_prefix}acm_characters
WHERE is_npc = 1',
array(
)
);
$non_player = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$non_player[] = array(
'id' => $row['id_character'],
'name' => array(
'first' => $row['name_first'],
'last' => $row['name_last'],
)
);
}
$smcFunc['db_free_result']($request);
}
elseif(allowedTo('cmod_post_npc_own'))
{
// Admin said only your own NPCs.
$request = $smcFunc['db_query']('','
SELECT
id_character, name_first, name_last
FROM {db_prefix}acm_characters
WHERE is_npc = 1
AND id_member = {int:id_member}',
array(
'id_member' => $context['user']['id'],
)
);
$non_player = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$non_player[] = array(
'id' => $row['id_character'],
'name' => array(
'first' => $row['name_first'],
'last' => $row['name_last'],
)
);
}
$smcFunc['db_free_result']($request);
}




Find
$context['posting_fields'] = array();
Add After

// Set up the character post selector.
// This is the dumbest way to do this, but whatever.
if(!empty($context['user']['characters']) && allowedTo('cmod_post'))
{
$select_box_string = '<select name="id_character">
<option value="0">'.$txt['acm_post_as_user'].'</option>';
foreach($context['user']['characters'] as $character)
{
$select_box_string .= '
<option value="'.$character['id'].'"'.(!empty($context['current_poster']) && $context['current_poster'] == $character['id'] ? ' selected' : '').'>';
if(!empty($modSettings['acmOrderCharsBy']))
{
if($modSettings['acmOrderCharsBy'] == 1 && !empty($character['name']['last']))
$select_box_string .= $character['name']['last'].' '.$character['name']['first'];
elseif($modSettings['acmOrderCharsBy'] == 2 && !empty($character['name']['last']))
$select_box_string .= $character['name']['last'].', '.$character['name']['first'];
}
else
$select_box_string .= $character['name']['first']. (!empty($character['name']['last']) ? ' '.$character['name']['last'] : '');
$select_box_string .= '
</option>';
}
// Create the optgroup loop.
if(!empty($non_player) && (allowedTo('cmod_post_npc_own') || allowedTo('cmod_post_npc_any')))
{
$select_box_string .= '
<optgroup label="'.$txt['acm_label_npcs'].'">';
foreach($non_player as $character)
{
$select_box_string .= '
<option value="'.$character['id'].'"'.(!empty($context['current_poster']) && $context['current_poster'] == $character['id'] ? ' selected' : '').'>';
if(!empty($modSettings['acmOrderCharsBy']))
{
if($modSettings['acmOrderCharsBy'] == 1 && !empty($character['name']['last']))
$select_box_string .= $character['name']['last'].' '.$character['name']['first'];
elseif($modSettings['acmOrderCharsBy'] == 2 && !empty($character['name']['last']))
$select_box_string .= $character['name']['last'].', '.$character['name']['first'];
}
else
$select_box_string .= $character['name']['first']. (!empty($character['name']['last']) ? ' '.$character['name']['last'] : '');
$select_box_string .= '
</option>';
}
$select_box_string .= '
</optgroup>';
}
$select_box_string .= '</select>';
}
$context['posting_fields']['id_character'] = array(
'dt' => '<span id="caption_id_character">' . $txt['acm_label_post_as'] . '</span>',
'dd' => !empty($select_box_string) ? $select_box_string : '<select name="id_character"><option value="0">'.$txt['acm_post_as_user'].'</option></select>',
);




Find
// Gotta have a subject.
$context['posting_fields']['subject'] = array(
'dt' => '<span id="caption_subject"' . (isset($context['post_error']['no_subject']) ? ' class="error"' : '') . '>' . $txt['subject'] . '</span>',
'dd' => '<input type="text" name="subject" value="' . $context['subject'] . '" size="80" maxlength="80" class="input_text" required>',
);

Add After

// These set up extra topic parameters if a new topic is being posted.
if($context['is_first_post'])
{
// This is for thread descriptions. Packages and turns on by default.
$context['posting_fields']['description'] = array(
'dt' => '<span id="caption_description">' . $txt['acm_label_description'] . '</span>',
'dd' => '<input type="text" name="description" value="'.(!empty($context['description']) ? $context['description'] : '').'" size="80" maxlength="80" class="input_text">',
);

// This is for dating, if it's on.
if(!empty($modSettings['acmEnableDates']))
{
$context['posting_fields']['incharacter_date'] = array(
'dt' => '<span id="caption_incharacter_date">' . $txt['acm_label_date'] . '</span>',
'dd' => '',
);
$context['posting_fields']['incharacter_date']['dd'] = '<select name="date_month"><option value="0"></option>';
foreach($txt['months'] as $number => $title)
$context['posting_fields']['incharacter_date']['dd'] .= '<option value="'.$number.'"'.(!empty($context['date']['month']) && $context['date']['month'] == $number ? ' selected' : '').'>'.$title.'</option>';
$context['posting_fields']['incharacter_date']['dd'] .= '</select> <input type="text" name="date_day" value="'.(!empty($context['date']['day']) ? $context['date']['day'] : '').'" size="5" maxlength="2" class="input_text"> <input type="text" name="date_year" value="'.(!empty($context['date']['year']) ? $context['date']['year'] : '').'" size="10" maxlength="10" class="input_text">';
}
}




Find
'smileys_enabled' => !isset($_POST['ns']),
'attachments' => empty($attachIDs) ? array() : $attachIDs,
'approved' => $becomesApproved,

Add After
'id_character' => !empty($_POST['id_character']) ? $_POST['id_character'] : 0,
'current_poster' => !empty($_POST['current_poster']) ? $_POST['current_poster'] : 0,




Find
'mark_as_read' => true,
'is_approved' => !$modSettings['postmod_active'] || empty($topic) || !empty($board_info['cur_topic_approved']),

Add After
'description' => !empty($_POST['description']) ? $_POST['description'] : '',
'month' => !empty($_POST['date_month']) ? (int) $_POST['date_month'] : 0,
'day' => !empty($_POST['date_day']) ? (int) $_POST['date_day'] : 0,
'year' => !empty($_POST['date_year']) ? (int) $_POST['date_year'] : 0,




Find
// If you're modifying, get only those posts before the current one. (otherwise get all.)
$request = $smcFunc['db_query']('', '
SELECT
COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
m.body, m.smileys_enabled, m.id_msg, m.id_member
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)

Replace
// If you're modifying, get only those posts before the current one. (otherwise get all.)
$request = $smcFunc['db_query']('', '
SELECT
COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
m.body, m.smileys_enabled, m.id_msg, m.id_member, m.id_character, ch.name_first, ch.name_last
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}acm_characters AS ch ON (m.id_character = ch.id_character)




Find
$context['previous_posts'][] = array(
Add Before
if(!empty($modSettings['acmOrderCharsBy']) && !empty($row['id_character']))
{
if($modSettings['acmOrderCharsBy'] == 1)
$character_name = (!empty($row['name_last']) ? $row['name_last'].' ' : ''). $row['name_first'];
elseif($modSettings['acmOrderCharsBy'] == 2)
$character_name = (!empty($row['name_last']) ? $row['name_last'].', ' : ''). $row['name_first'];
}
elseif(!empty($row['id_character']))
$character_name = $row['name_first']. (!empty($row['name_last']) ? ' '.$row['name_last'] : '');




Find
'poster' => $row['poster_name'],
Replace
'poster' => !empty($row['id_character']) ? $character_name : $row['poster_name'],




SychO

posting fields array structure was changed since the beta, read here to understand how you need to adapt it for it to work with RC

https://github.com/SimpleMachines/SMF2.1/blob/073c8081adff8abd6056ca064202c06469bd1440/Sources/Post.php#L1302-L1423
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

zushiba

Thanks SychO, I think I can adapt the code to the new structure.

zushiba

SychO (or anyone who might be in the know)

The example code doesn't appear to respect many of the input values. I don't know if this is by design or if the function simply isn't finished yet. Here is an example of the issue.

$context['posting_fields']['bar'] = array(
'label' => array(
'text' => 'Example Code', // required
'class' => 'bar', // optional
),
'input' => array(
'type' => 'select', // required
'attributes' => array(
'name' => 'bar', // optional, defaults to posting field's key
),
'options' => array(
'option_1' => array(
'label' => $txt['option_1'],
'value' => '1',
'selected' => false,
),
'option_2' => array(
'label' => $txt['option_2'],
'value' => '2',
'selected' => false,
),
'opt_group_1' => array(
'label' => $txt['opt_group_1'],
'options' => array(
'option_3' => array(
'label' => $txt['option_3'],
'value' => '3',
'selected' => true,
),
'option_4' => array(
'label' => $txt['option_4'],
'value' => '4',
'selected' => false,
),
),
),
),
),
);


Should produce a dropdown with the options (option_1, option_2, option_3 option_4) with option_3 being auto selected on load and each of the selections having a value of 1, 2, 3 & 4 respectively.  However the code that's actually produced is as follows.
<dt class="clear pf_bar">
<label for="bar" id="caption_bar" class="bar">Example Code</label>
</dt>
<dd class="pf_bar">
<select name="bar" tabindex="2">
<option>option_1</option>
<option>option_2</option>
<optgroup label="opt_group_1" "="">
<option>option_3</option>
<option>option_4</option>
</optgroup>
</select>
</dd>


No select option has it's associated value and option 3 is not selected.

SychO

It looks like an issue with RC2, however it has been fixed for the upcoming RC3
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

Advertisement: