Custom fields and filters of post

Started by davidhs, February 21, 2014, 01:53:17 PM

Previous topic - Next topic

davidhs

Before install my mod

Edit MessageIndex.php again:

1. Fix error 5.4. Line 91. Search


$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : '') , $_REQUEST['start'], $board_info['total_topics'], $maxindex, true);

replace by

$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $maxindex, true);

(after (isset($_REQUEST['desc']) ? ';desc' : '') there is an extra space, Why? I do not know...)

2. Fix error 5.5. Line 93. Search

$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d' , $_REQUEST['start'], $board_info['total_topics'], $maxindex, true);

replace by

$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $maxindex, true);

(after '?board=' . $board . '.%1$d' there is an extra space, Why? I do not know...)

3. Line 354. Important error! Search

LEFT JOIN {db_prefix}best_answer AS `ba` ON `t`.`id_topic` = `ba`.`id_topic`
ORDER BY ' . (!empty($modSettings['enableStickyTopics']) ? 'is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' : '') . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') . '

replace by (also this fix error 5.8 )

LEFT JOIN {db_prefix}best_answer AS `ba` ON `t`.`id_topic` = `ba`.`id_topic`' . '
WHERE t.id_board = {int:current_board}' . (!$modSettings['postmod_active'] || $context['can_approve_posts'] ? '' : '
AND (t.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR t.id_member_started = {int:current_member}') . ')') . '
ORDER BY ' . (!empty($modSettings['enableStickyTopics']) ? 'is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' : '') . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') . '


4. Line 377. Important error! Search

$result = $smcFunc['db_query']('substring', '
t.id_topic, t.num_replies, t.locked, t.num_views, t.is_sticky, t.id_poll, t.id_previous_board,

and write a "SELECT" between (also this fix error 5.10)

$result = $smcFunc['db_query']('substring', '
SELECT
t.id_topic, t.num_replies, t.locked, t.num_views, t.is_sticky, t.id_poll, t.id_previous_board,


5. Fix error 5.15. Line 561. Search

determineTopicClass($context['topics'][$row['id_topic']]);

and put 3 tabs at begin of line

determineTopicClass($context['topics'][$row['id_topic']]);


Instal my mod (1.2)

Error 5.14 can not be fix. It is because Best Answer and my mod modify same line.

Install my mod with error 5.14

After install my mod

Edit MessageIndex.php. Fix error 5.14. Line 555. Search

'best_answer' => array(
'id_msg' => $row['best_answer'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['best_answer'] . '#msg' . $row['best_answer']
),
);

and add text after, replace by

'best_answer' => array(
'id_msg' => $row['best_answer'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['best_answer'] . '#msg' . $row['best_answer']
),
);

// BEGIN MOD CustomFieldFilterPost
$id_msg_array[] = $context['topics'][$row['id_topic']]['first_post']['id'];
$context['cffp']['data_msg_topic'][$row['id_first_msg']] = array(
'sticky' => $context['topics'][$row['id_topic']]['is_sticky'] ? 1 : 0,
'locked' => $context['topics'][$row['id_topic']]['is_locked'] ? 1 : 0,
'id_msg' => $context['topics'][$row['id_topic']]['first_post']['id'],
'first_msg' => 1,
'subject' => $context['topics'][$row['id_topic']]['subject'],
);
// END MOD CustomFieldFilterPost


I expect now works!

NOTE: Use tab character (no space character) for indent text, is important! You make sure that Notepad++ not replace tab for space when write or save file.

margarett

Easy on the language, yes? ;)

SMF  is perfectly able to find patterns of code. The problem is that the search pattern isn't exactly the same as the one in code (eg, 1 extra space, etc) and that causes it to fail. You, while searching manually, instinctively select just the text out of the search pattern ;)

Nice one, davidhs :-)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

MrMike

davidhs,

I'm looking at mods that might be suitable for creating a recipe site and I'm wondering if you think your mod might lend itself to that?

Would your mod be a practical way to add specific form fields to a post form, such a 'recipe title', 'ingredients', recipe instructions', and so on?

The mod looks amazing but I'm wondering if it might be overkill for my application, which is basically just a simple recipe form with a only a few inputs. (??)


davidhs

Quote from: MrMike on December 24, 2014, 12:13:48 PM
davidhs,

I'm looking at mods that might be suitable for creating a recipe site and I'm wondering if you think your mod might lend itself to that?

Would your mod be a practical way to add specific form fields to a post form, such a 'recipe title', 'ingredients', recipe instructions', and so on?

The mod looks amazing but I'm wondering if it might be overkill for my application, which is basically just a simple recipe form with a only a few inputs. (??)


Yes, I think you can use my mod.

You can create a group of fields (Recipe) with some fields: Title (text), ingredients (long text), instructions (long text),... image (text, for write url of image), type (select box with options: dessert,...),...

Also, you can create a board Recipes and allow only here create recipes, add filters or a search page and search recipes,...

MrMike

Quote from: davidhs on December 24, 2014, 12:44:29 PM
Yes, I think you can use my mod.

You can create a group of fields (Recipe) with some fields: Title (text), ingredients (long text), instructions (long text),... image (text, for write url of image), type (select box with options: dessert,...),...

Also, you can create a board Recipes and allow only here create recipes, add filters or a search page and search recipes,...

I'll have a look. It seems like the learning curve is a bit steep, but I'll try it on a test site and see what I can do.

davidhs

Quote from: MrMike on December 24, 2014, 01:03:46 PM
Quote from: davidhs on December 24, 2014, 12:44:29 PM
Yes, I think you can use my mod.

You can create a group of fields (Recipe) with some fields: Title (text), ingredients (long text), instructions (long text),... image (text, for write url of image), type (select box with options: dessert,...),...

Also, you can create a board Recipes and allow only here create recipes, add filters or a search page and search recipes,...

I'll have a look. It seems like the learning curve is a bit steep, but I'll try it on a test site and see what I can do.
Yes, at the beginning it is complicated. If you have doubts, ask here.

MESWEB

How modify this code:

document.getElementById("cffp_1_column_1").onchange = function (event)
{
document.getElementsByName("subject")[0].value = "[" + this.value + "]";
}


To not deleting words entered already in subject?

davidhs

Quote from: MESWEB on December 24, 2014, 03:59:10 PM
How modify this code:

document.getElementById("cffp_1_column_1").onchange = function (event)
{
document.getElementsByName("subject")[0].value = "[" + this.value + "]";
}


To not deleting words entered already in subject?
See this post, point 2 ;)
http://www.simplemachines.org/community/index.php?topic=518886.msg3722447#msg3722447

MESWEB

Quote from: davidhs on July 21, 2014, 12:33:36 PM
2. This change subject only if is empty.
document.getElementById("cffp_X_column_Y").onchange = function (event)
{
if ("" == document.getElementsByName("subject")[0].value)
document.getElementsByName("subject")[0].value = "[" + this.value + "]";
}

I want to put this value at the beginning of the subject when it has already been written , or not

davidhs

Quote from: MESWEB on December 27, 2014, 12:15:43 PM
I want to put this value at the beginning of the subject when it has already been written , or not
Test this code
document.getElementById("cffp_X_column_Y").onchange = function (event)
{
var subject = document.getElementsByName("subject")[0].value;

document.getElementsByName("subject")[0].value = "[" + this.value + "]";
if ("" != subject)
document.getElementsByName("subject")[0].value += " " + subject;
}

MESWEB

Yeahhh!!!! It's working. But when I still change the value from the select box then I have lot of the value like:
[value][value][value][value][value]subject
Should be better when next values are not added if any one value are added from the select box.

davidhs

Quote from: MESWEB on December 28, 2014, 07:40:37 AM
Yeahhh!!!! It's working. But when I still change the value from the select box then I have lot of the value like:
[value][value][value][value][value]subject
Should be better when next values are not added if any one value are added from the select box.
Yes, it is a problem :(

Perhaps... if first character is a "[" do nothing, else write at begining.

document.getElementById("cffp_X_column_Y").onchange = function (event)
{
var subject = document.getElementsByName("subject")[0].value;
var write = "" == subject || "[" != subject.charAt(0);

if (write)
{
document.getElementsByName("subject")[0].value = "[" + this.value + "]";
if ("" != subject)
document.getElementsByName("subject")[0].value += " " + subject;
}
}


MESWEB

This code not working property. When I select one value then has been added to subject correctly but when I change value it's nothing happened and still showing first value without change effect.

I think this would be helpful:
If some value has been added then don't increment by adding next one. $i = 1

davidhs

Test this

document.getElementById("cffp_X_column_Y").onchange = function (event)
{
var subject = document.getElementsByName("subject")[0].value;
var match = subject.match(/^\[.+\](.*)/);

document.getElementsByName("subject")[0].value = "[" + this.value + "]";
if (null == match)
{
if ("" != subject)
document.getElementsByName("subject")[0].value += " " + subject;
}
else
document.getElementsByName("subject")[0].value += match[1];
}

If subject contains a "[option]" at begining, replace with "[new_option]"

MESWEB

Working Perfect.  :D . How to use require function to this select box? Example - info or popup where is "You need select value from selectbox before post new message". Can You insert more useful java codes to Your mod with select box to use them? That would be powerful mod here.

By the way. I found error incoming from this mod:
/index.php?pretty;action=admin&area=logs;c4d57f882=9b2477f037b2c6cba8d42fae4ca2abc1
8: Undefined variable: smf_version_1
File: /Themes/default/languages/Modifications.english.php
Line: 477


Line 477:
$txt['cffp_records'] = 'Records';
if (!$smf_version_1)
$txt['cffp_moderation_area'] = 'Groups of fields on posts';
else
$txt['cffp_moderation_area'] = 'Moderate groups of fields on posts';

I change:
if (!$smf_version_1)
To
if (empty($smf_version_1))

Now I testing this. Here is solution - http://www.simplemachines.org/community/index.php?topic=531723.msg3777045#msg3777045

davidhs

Quote from: MESWEB on December 29, 2014, 05:44:07 PM
How to use require function to this select box? Example - info or popup where is "You need select value from selectbox before post new message". Can You insert more useful java codes to Your mod with select box to use them? That would be powerful mod here.
JavaScript and popup not is necesary for this. In SMF if you saves a post without subject or body, you see a warning in red color. This mod do same. Just do this
Quote from: davidhs on July 21, 2014, 12:33:36 PM
3. Edit field settings in Administrator Panel. Check Advanced settings > Not empty value.


Quote from: MESWEB on December 29, 2014, 05:44:07 PM
By the way. I found error incoming from this mod:
/index.php?pretty;action=admin&area=logs;c4d57f882=9b2477f037b2c6cba8d42fae4ca2abc1
8: Undefined variable: smf_version_1
File: /home/messiah/domains/obeznany.pl/public_html/Themes/default/languages/Modifications.english.php
Line: 477


Line 477:
$txt['cffp_records'] = 'Records';
if (!$smf_version_1)
$txt['cffp_moderation_area'] = 'Groups of fields on posts';
else
$txt['cffp_moderation_area'] = 'Moderate groups of fields on posts';

I change:
if (!$smf_version_1)
To
if (empty($smf_version_1))

Now I testing this. Here is solution - http://www.simplemachines.org/community/index.php?topic=531723.msg3777045#msg3777045
Thanks. This is an important bug. :(

Your solution is valid only in SMF 2.0.x, but in SMF 1.1.x it do not work.

Before line
if (!$smf_version_1)
must write
global $forum_version;
$smf_version_1 = 0 === strpos($forum_version, 'SMF 1');


I will fix this bug in next update.

Arantor

You should not have such things in the language files. Should really have both strings, pick which one you need in the main code.

Biology Forums

Could someone explain what this modification does in a nutshell? I'm looking at this and it's like reading Chinese.

MESWEB

I have next errors:
/index.php?pretty;board=a.40&sort=replies;desc
8: Undefined index: cffp
File:/Themes/havvo/MessageIndex.template.php
Line: 272 and 273


Line 272 & 273:

270:// BEGIN MOD CustomFieldFilterPost
271:// Show custom post fields.
272:$context['cffp']['message_index'] = $topic['first_post']['cffp']['message_index'];
==>273:$context['cffp']['message_index_member'] = $topic['first_post']['cffp']['message_index_member'];
274:template_cffp_show('message_index');
275:template_cffp_show('message_index_member');
276:// END MOD CustomFieldFilterPost

davidhs

Quote from: Arantor on December 29, 2014, 06:51:21 PM
You should not have such things in the language files. Should really have both strings, pick which one you need in the main code.
I will see this, but I do not want duplicate more language files... :(

Quote from: Shuban on December 29, 2014, 07:01:56 PM
Could someone explain what this modification does in a nutshell? I'm looking at this and it's like reading Chinese.
Now, a message have two fields (subject and body). This mod allow add more fields.

Quote from: MESWEB on December 30, 2014, 04:17:49 AM
I have next errors:
/index.php?pretty;board=a.40&sort=replies;desc
8: Undefined index: cffp
File:/Themes/havvo/MessageIndex.template.php
Line: 272 and 273


Line 272 & 273:

270:// BEGIN MOD CustomFieldFilterPost
271:// Show custom post fields.
272:$context['cffp']['message_index'] = $topic['first_post']['cffp']['message_index'];
==>273:$context['cffp']['message_index_member'] = $topic['first_post']['cffp']['message_index_member'];
274:template_cffp_show('message_index');
275:template_cffp_show('message_index_member');
276:// END MOD CustomFieldFilterPost

:( :( I will see and fix in next update, soon.

Advertisement: