Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Big Game on September 11, 2016, 03:37:48 PM

Title: Please Advise Me On My First Mod
Post by: Big Game on September 11, 2016, 03:37:48 PM
I have an idea for a mod and I was going to try to code it myself.
My plan was to get help here as I go along, tackling small tasks at a time and after I learn the basics I believe I'll be alright.
I'm fairly fluent in Javascript and very in HTML and CSS.
PHP, I probably need to read some tutorials.

My mod is going to be customizing the poll form.
First, I copied the default theme to create a new one, which I have called "themetester1".
I then copied the content of Poll.template.php from the default theme folder in Filezilla and pasted it into my Notepad editor. I then saved it as Poll.template.php and uploaded it to my new themetester1 folder using Filezilla.

Here is a copy of the Poll.template.php file:

<?php
/**
 * Simple Machines Forum (SMF)
 *
 * @package SMF
 * @author Simple Machines
 * @copyright 2011 Simple Machines
 * @license http://www.simplemachines.org/about/smf/license.php BSD
 *
 * @version 2.0
 */

function template_main()
{
global $context$settings$options$txt$scripturl;

// Some javascript for adding more options.
echo '
<script type="text/javascript"><!-- // --><![CDATA[
var pollOptionNum = 0;

function addPollOption()
{
if (pollOptionNum == 0)
{
for (var i = 0; i < document.forms.postmodify.elements.length; i++)
if (document.forms.postmodify.elements[i].id.substr(0, 8) == "options-")
pollOptionNum++;
}
pollOptionNum++

setOuterHTML(document.getElementById("pollMoreOptions"), \'<li><label for="options-\' + pollOptionNum + \'" '
, (isset($context['poll_error']['no_question']) ? ' class="error"' ''), '>'$txt['option'], ' \' + pollOptionNum + \'</label>: <input type="text" name="options[\' + (pollOptionNum - 1) + \']" id="options-\' + (pollOptionNum - 1) + \'" value="" size="80" maxlength="255" class="input_text" /></li><li id="pollMoreOptions"></li\');
}
// ]]></script>'
;

// Start the main poll form.
echo '
<div id="edit_poll">
<form action="' 
$scripturl '?action=editpoll2'$context['is_edit'] ? '' ';add'';topic=' $context['current_topic'] . '.' $context['start'] . '" method="post" accept-charset="'$context['character_set'], '" onsubmit="submitonce(this); smc_saveEntities(\'postmodify\', [\'question\'], \'options-\');" name="postmodify" id="postmodify">
<div class="cat_bar">
<h3 class="catbg">'
$context['page_title'], '</h3>
</div>'
;

if (!empty($context['poll_error']['messages']))
echo '
<div class="errorbox">
<dl class="poll_error">
<dt>
'
$context['is_edit'] ? $txt['error_while_editing_poll'] : $txt['error_while_adding_poll'], ':
</dt>
<dt>
'
, empty($context['poll_error']['messages']) ? '' implode('<br />'$context['poll_error']['messages']), '
</dt>
</dl>
</div>'
;

echo '
<div>
<span class="upperframe"><span></span></span>
<div class="roundframe">
<input type="hidden" name="poll" value="'
$context['poll']['id'], '" />
<fieldset id="poll_main">
<legend><span '
, (isset($context['poll_error']['no_question']) ? ' class="error"' ''), '>'$txt['poll_question'], ':</span></legend>
<input type="text" name="question" size="80" value="'
$context['poll']['question'], '" class="input_text" />
<ul class="poll_main">'
;

foreach ($context['choices'] as $choice)
{
echo '
<li>
<label for="options-'
$choice['id'], '" ', (isset($context['poll_error']['poll_few']) ? ' class="error"' ''), '>'$txt['option'], ' '$choice['number'], '</label>:
<input type="text" name="options['
$choice['id'], ']" id="options-'$choice['id'], '" value="'$choice['label'], '" class="input_text" size="80" maxlength="255" />';

// Does this option have a vote count yet, or is it new?
if ($choice['votes'] != -1)
echo ' ('$choice['votes'], ' '$txt['votes'], ')';

echo '
</li>'
;
}

echo '
<li id="pollMoreOptions"></li>
</ul>
<strong><a href="javascript:addPollOption(); void(0);">('
$txt['poll_add_option'], ')</a></strong>
</fieldset>
<fieldset id="poll_options">
<legend>'
$txt['poll_options'], ':</legend>
<dl class="settings poll_options">'
;

if ($context['can_moderate_poll'])
{
echo '
<dt>
<label for="poll_max_votes">'
$txt['poll_max_votes'], ':</label>
</dt>
<dd>
<input type="text" name="poll_max_votes" id="poll_max_votes" size="2" value="'
$context['poll']['max_votes'], '" class="input_text" />
</dd>
<dt>
<label for="poll_expire">'
$txt['poll_run'], ':</label><br />
<em class="smalltext">'
$txt['poll_run_limit'], '</em>
</dt>
<dd>
<input type="text" name="poll_expire" id="poll_expire" size="2" value="'
$context['poll']['expiration'], '" onchange="this.form.poll_hide[2].disabled = isEmptyText(this) || this.value == 0; if (this.form.poll_hide[2].checked) this.form.poll_hide[1].checked = true;" maxlength="4" class="input_text" /> '$txt['days_word'], '
</dd>
<dt>
<label for="poll_change_vote">'
$txt['poll_do_change_vote'], ':</label>
</dt>
<dd>
<input type="checkbox" id="poll_change_vote" name="poll_change_vote"'
, !empty($context['poll']['change_vote']) ? ' checked="checked"' ''' class="input_check" />
</dd>'
;

if ($context['poll']['guest_vote_allowed'])
echo '
<dt>
<label for="poll_guest_vote">'
$txt['poll_guest_vote'], ':</label>
</dt>
<dd>
<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"'
, !empty($context['poll']['guest_vote']) ? ' checked="checked"' ''' class="input_check" />
</dd>'
;
}

echo '
<dt>
'
$txt['poll_results_visibility'], ':
</dt>
<dd>
<input type="radio" name="poll_hide" id="poll_results_anyone" value="0"'
$context['poll']['hide_results'] == ' checked="checked"' ''' class="input_radio" /> <label for="poll_results_anyone">'$txt['poll_results_anyone'], '</label><br />
<input type="radio" name="poll_hide" id="poll_results_voted" value="1"'
$context['poll']['hide_results'] == ' checked="checked"' ''' class="input_radio" /> <label for="poll_results_voted">'$txt['poll_results_voted'], '</label><br />
<input type="radio" name="poll_hide" id="poll_results_expire" value="2"'
$context['poll']['hide_results'] == ' checked="checked"' '', empty($context['poll']['expiration']) ? 'disabled="disabled"' ''' class="input_radio" /> <label for="poll_results_expire">'$txt['poll_results_after'], '</label>
</dd>
</dl>
</fieldset>'
;
// If this is an edit, we can allow them to reset the vote counts.
if ($context['is_edit'])
echo '
<fieldset id="poll_reset">
<legend>'
$txt['reset_votes'], '</legend>
<input type="checkbox" name="resetVoteCount" value="on" class="input_check" /> ' 
$txt['reset_votes_check'] . '
</fieldset>'
;
echo '
<div class="righttext padding">
<input type="submit" name="post" value="'
$txt['save'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit" />
</div>
</div>
<span class="lowerframe"><span></span></span>
</div>
<input type="hidden" name="seqnum" value="'
$context['form_sequence_number'], '" />
<input type="hidden" name="' 
$context['session_var'] . '" value="' $context['session_id'] . '" />
</form>
</div>
<br class="clear" />'
;
}

?>



I have added an image of a default poll form which you can see below in this posts attachments.
(Just in case you need to quickly and visibly see the poll post form for any reason)


I have spent all night trying to complete a simple task of; filling the "Question" input text field, with readonly text. (http://www.w3schools.com/tags/att_input_readonly.asp)

I would like for the question in the "Question" text input field to always remain the same and not be able for the user to edit.

If you are curious, the question is: "Who do you think won?".

I have tried editing this part of the code in several areas, but nothing ever changes,

<div>
<span class="upperframe"><span></span></span>
<div class="roundframe">
<input type="hidden" name="poll" value="', $context['poll']['id'], '" />
<fieldset id="poll_main">
<legend><span ', (isset($context['poll_error']['no_question']) ? ' class="error"' : ''), '>', $txt['poll_question'], ':</span></legend>
<input type="text" name="question" size="80" value="', $context['poll']['question'], '" class="input_text" />
<ul class="poll_main">';

foreach ($context['choices'] as $choice)
{
echo '


I'm not sure if I'm inserting the question into the correct section of code, or if I need to use "echo".
Can somebody please lend me some knowledge to get started here?
After I get the basics of this down, I think I will be good to go.
Thanks!
Title: Re: Please Advise Me On My First Mod
Post by: Big Game on September 11, 2016, 09:26:24 PM
so ....... no help on this?
Title: Re: Please Advise Me On My First Mod
Post by: d3vcho on September 12, 2016, 04:00:15 AM
Hello!

Please, be patient... We're all volunteers here and somebody will help you sooner or later.

And also, don't bump your topic when 24 hours haven't passed.

Regards :)
Title: Re: Please Advise Me On My First Mod
Post by: Big Game on September 13, 2016, 09:34:25 AM
Lol .. only post is somebody trying to mod me.
Imagine that.


Bump .....
Title: Re: Please Advise Me On My First Mod
Post by: Big Game on September 14, 2016, 07:09:45 PM
Well if there is anything I've learned about smf, it is that they have a crappy support forum.
Title: Re: Please Advise Me On My First Mod
Post by: Shambles on September 14, 2016, 07:17:42 PM
You just have to ignore the "mod wannabes" and have some patience.
Title: Re: Please Advise Me On My First Mod
Post by: Suki on September 14, 2016, 07:31:15 PM
 What would your mod do? what do you want to achieve?  a mod generally involves more than a template edit, specially if you want to modify the way the poll system works.

Whats your ultimate goal for this mod?

I'm afraid to be able to create a mod you will have to know the very basics about PHP, basic syntax and var declarations will greatly help. Another option is to look at mods already created, specially mods that modifies the very same parts you are planning to modify yourself.
Title: Re: Please Advise Me On My First Mod
Post by: Kindred on September 14, 2016, 07:34:59 PM
well, hang on a second here...

Big Game, you did not actually ask for SUPPORT with the product features. You asked for help in coding something new, special and particular...  and THAT only has a limited number of folks who understand the code well enough to really give you instruction. And we are all volunteers...  we have limited time here, and most of the specialized knowledge (aka developers) are busy trying to get a release done.

As for "mod wannabes", Shambles....  that was inappropriate, because d3vcho was exactly correct - bumping a topic in less than 24 hours is inappropriate -- even more so when the topic involves a very specific coding knowledge.

And now that you have Suki's attention, you have actually reached someone who can possibly instruct you.
Title: Re: Please Advise Me On My First Mod
Post by: Big Game on September 16, 2016, 12:10:36 AM
Well thank you :)

And my mod is going to be a pre-made poll.

my site is a rap battle forum.
I want the rap battles to be judged by polls.

So essentially, there would only be 2 poll options, with a predefined question inside the 'question input text field'. That question will be "Who won this battle?

In the first poll option, I will have it automate already filled out with the OP's username.
And the OP is to type his opponents name in the second poll option.

All of this I think I can learn quickly.
The tricky part will be what I want next, which will be:
As the OP is filling out the second poll question text box, (typing his opponents name) a mention drop box pop up.



That's pretty much it.
Well and finally, I want it to say "Start a battle" instead of "add poll".

Last time I messed with it, I couldn't get NOTHING to change on the pages after editing their template.
I think it may have been because i wasn't caching.

Side question: Is it really necessary to cache after every single edit?? Isn't there an alternative?

and thanks for responding.


Title: Re: Please Advise Me On My First Mod
Post by: Suki on September 17, 2016, 11:21:33 AM
OK, but thats basically all view/template edits, the real work would be behind the scenes, to put it an analogy, what you are describing its the tip of the iceberg but theres a lot more below it.

The template edits are, most of the times, the last thing been added, so try not to worry about those and instead focus on how this pre poll will be saved, on a separate table or the messages or topics table.

Theres also the custom from mod, have you tried that?