News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Help migrating Ver. 1 mod to Ver. 2

Started by jjfeenix, November 26, 2014, 09:52:14 AM

Previous topic - Next topic

jjfeenix

I recently upgraded my SMF board from 1.19 to 2.09. I have successfully upgraded all the mods that were used to ver. 2 mods, except one.

The mod was custom made years ago (I didn't write it) to create eBay links encoded with my eBay referral info. The mod created bbc tags around the ebay item number, in the message box, and converted this to the correct hyper link when previewed/posted.

When I try to install the ver. 1 mod I get the following errors in the Package manager.

   Type    Action    Description
*    1.    Execute Modification    ./Sources/Subs.php    Test failed
      1.    Add Before    ./Sources/Subs.php    Test failed
*    2.    Execute Modification    ./Themes/default/Admin.template.php    Test failed
      1.    Add After    ./Themes/default/Admin.template.php    Test failed
*    3.    Execute Modification    ./Sources/ManagePosts.php    Test failed
      1.    Add After    ./Sources/ManagePosts.php    Test failed
*    4.    Execute Modification    ./Themes/default/Post.template.php    Test failed
      1.    Add After    ./Themes/default/Post.template.php    Test failed

I can see what mods are being asked for and in what files. I've looked into the ver. 1 files, but when I've searched the ver. 2 files, it looks like the structure of SMF ver 2 is so different, I don't know where to start looking to make the adjustments.

How can I find out where the old functions have been moved to? If they don't exist in ver. 2, where do I get specific info on what files/functions I need to get this up and running again.

Thanks in advance,
JohnS

Arantor

Well, what old functions is it changing?

Subs.php implies it's adding a bbcode, not sure why that would fail since the bbcode system has not significantly changed.

Post.template.php implies it's adding a button to the editor, this would now be accomplished by a change (and a different one at that) to Subs-Editor.php.

As for the admin template and manage posts, I don't know what it's trying to change or why it might be trying to change it... more information required.

jjfeenix

Arantor:

Thanks for the assistance. Unless you want me to upload all the files, here's the Find and Add code from the first failure in ./Sources/Subs.php:

Code: (Find) [Select]

array(
'tag' => 'email',
'type' => 'unparsed_content',
'content' => '<a href="mailto:$1">$1</a>',
// !!! Should this respect guest_hideContacts?
'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
),


Code: (Add Before) [Select]

// ICWEasyLinker for ebay
                // IF ID NOT SET, USE MINE ;)
                ($modSettings['campid'] = empty($modSettings['campid']) ? '5335842975' : $modSettings['campid']),
                ($modSettings['placementid'] = empty($modSettings['placementid']) ? '711-53200-19255-0' : $modSettings['placementid']),
                ($modSettings['toolid'] = empty($modSettings['toolid']) ? '10001' : $modSettings['toolid']),
                ($modSettings['customid'] = empty($modSettings['customid']) ? 'SMF' : $modSettings['customid']),
                array(
'tag' => 'ebay',
'type' => 'unparsed_content',
'content' => '<a href="http://rover.ebay.com/rover/1/' . $modSettings['placementid'] . '/1?type=2&campid=' . $modSettings['campid'] . '&toolid=' . $modSettings['toolid'] . '&customid=' . $modSettings['customid'] . '&ext=$1&item=$1" target="_blank">' . $txt['ebayitem'] . ' #$1</a>',
),
array (
'tag' => 'ebay',
'type' => 'unparsed_equals',
'before' => '<a href="http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=$1">',
'after' => '</a>',
),


I think I understand why the Find fails. The 3rd line of the array it's looking for:
'content' => '<a href="mailto:$1">$1</a>',
but in ver. 2 it's slightly changed to:
'content' => '<a href="mailto:$1" class="bbc_email">$1</a>',

So, I know where it goes, but does this difference mean that I have to change the inserted code in any way?

Thanks,
JohnS

Arantor

Ugh, that code is seriously icky on many, many levels.

But yes, if you change the 'content' => line in the mod to match what's in 2.0, I see no reason why that wouldn't work. Slightly amazed SMF doesn't choke on it entirely, since that's really not the venue to be handling such stuff.

I'd suggest the find code be changed as you've outlined, but the replace code be changed like so, if nothing else it will actually be faster.


// ICWEasyLinker for ebay
                // IF ID NOT SET, USE MINE ;)
                array(
'tag' => 'ebay',
'type' => 'unparsed_content',
'content' => '<a href="http://rover.ebay.com/rover/1/' . (empty($modSettings['placementid']) ? '711-53200-19255-0' : $modSettings['placementid']) . '/1?type=2&campid=' . (empty($modSettings['campid']) ? '5335842975' : $modSettings['campid']) . '&toolid=' . (empty($modSettings['toolid']) ? '10001' : $modSettings['toolid']) . '&customid=' . (empty($modSettings['customid']) ? 'SMF' : $modSettings['customid']) . '&ext=$1&item=$1" target="_blank">' . $txt['ebayitem'] . ' #$1</a>',
),
array (
'tag' => 'ebay',
'type' => 'unparsed_equals',
'before' => '<a href="http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=$1">',
'after' => '</a>',
),


The reason this is faster is because it won't have to go through each of the not-actually-bbcode items that get added to the list every time it evaluates the bbc list.

jjfeenix

Arantor:

QuoteUgh, that code is seriously icky on many, many levels.

But yes, if you change the 'content' => line in the mod to match what's in 2.0, I see no reason why that wouldn't work. Slightly amazed SMF doesn't choke on it entirely, since that's really not the venue to be handling such stuff.

Thanks for the improvements. I changed the install.xml to look for the ver. 2 code and replace it with what you wrote.

However, that still leaves me with 3 Code Executions that need to be rewritten or redirected to the correct file/function. The last two are small (modding  ./Sources/ManagePosts.php and ./Themes/default/Post.template.php), but the next one is substantial. It adds the mod settings to the ./Themes/default/Admin.template.php.

Before I go further, you said: "since that's really not the venue to be handling such stuff". Should I keep trying to upgrade this mod's code or should I be tackling this mod in a different manner?

TIA,
JohnS


Arantor

My comment was that splicing default values for $modSettings into the main bbc cache loader is not the way to do it, and I rewrote it in a way that didn't do that.

Yes, the other code executions need rewriting but even though I'm a PHP expert, even I can't rewrite code I haven't even seen... ;)

jjfeenix

Arantor:

QuoteMy comment was that splicing default values for $modSettings into the main bbc cache loader is not the way to do it, and I rewrote it in a way that didn't do that.

OK, I understand.

I did investigate another mod (phpbbc) that adds a custom bbc button, but it only touches the .Sources/Subs-Editors.php file. My mod doesn't touch that file. I thought that I might be wasting time trying to fit a square peg in what is now a round hole.

QuoteYes, the other code executions need rewriting but even though I'm a PHP expert, even I can't rewrite code I haven't even seen... ;)

I really didn't want to impose and have anyone rewrite it, I'd really like to know more about mods and what's what under the SMF hood. But being that you asked, here's the rest of the code from the install.xml file:

<!-- ADDS THE SETTINGS TO THE ADMIN SECTION TEMPLATE-->
<file name="$themedir/Admin.template.php">
<operation>
<search position="before"><![CDATA[<td valign="top">
<input type="checkbox" name="enableSpellChecking" id="enableSpellChecking_check"', empty($modSettings['enableSpellChecking']) ? '' : ' checked="checked"', ' class="check" />
</td>
</tr><tr class="windowbg2">
<td colspan="2"><hr /></td>
</tr><tr class="windowbg2">
]]></search>
<add><![CDATA[<th width="50%" align="right">
<label for="icweasylinker_check">', $txt['icweasylinker'], '</label>:
</th>
<td valign="top">
<input type="checkbox" name="icweasylinker" id="icweasylinker_check"' , empty($modSettings['icweasylinker']) ? '' : ' checked="checked"', ' class="check" />  <a href="a href="http://rover.ebay.com/rover/1/711-53200-19255-0/1?type=2&campid=5335842975&toolid=10001&customid=SMF&mpre=http://pages.ebay.com/" title="' . $txt['signupfor'] . ' ' . $txt['ebay'] . '"><b>'.$txt['signupfor'].' '.$txt['ebay'].'</b></a>
</td>
</tr>
            <tr class="windowbg2">
<th width="50%" align="right">
<label for="placementid_input">', $txt['placementid'], '</label>:
</th>
<td valign="top">
<input type="text" name="placementid" id="placementid_input" value="', !empty($modSettings['placementid']) ? $modSettings['placementid'] : '' , '" style="width:160px" maxlength="20"/>
</td>
</tr>
<tr class="windowbg2">
<th width="50%" align="right">
<label for="campid_input">', $txt['campid'], '</label>:
</th>
<td valign="top">
<input type="text" name="campid" id="campid_input" value="', !empty($modSettings['campid']) ? $modSettings['campid'] : '' , '" style="width:160px" maxlength="20"/>
</td>
</tr>
<tr class="windowbg2">
<th width="50%" align="right">
<label for="customid_input">', $txt['customid'], '</label>:
</th>
<td valign="top">
<input type="text" name="customid" id="customid_input" value="', !empty($modSettings['customid']) ? $modSettings['customid'] : '' , '" style="width:160px" maxlength="32"/>
</td>
</tr>
            <tr class="windowbg2">
<th width="50%" align="right">
<label for="toolid_input">', $txt['toolid'], '</label>:
</th>
<td valign="top">
<input type="text" name="toolid" id="toolid_input" value="', !empty($modSettings['toolid']) ? $modSettings['toolid'] : '' , '" style="width:160px" maxlength="32"/>
</td>
</tr>
<tr class="windowbg2">
<td colspan="2"><hr /></td>
</tr><tr class="windowbg2">
]]></add>
</operation>
</file>
<file name="$sourcedir/ManagePosts.php">
<operation>
<search position="before"><![CDATA[
'enableEmbeddedFlash' => empty($_POST['enableEmbeddedFlash']) ? '0' : '1',
]]></search>
<add><![CDATA[
'icweasylinker' => empty($_POST['icweasylinker']) ? '0' : '1',
'campid' => eregi('^[0-9]{20}$', $_POST['campid']) ? strtolower($_POST['campid']) : '',
            'toolid' => eregi('^[0-9]{20}$', $_POST['toolid']) ? strtolower($_POST['toolid']) : '',
'customid' => eregi('^[0-9a-zA-Z-]{250}$', $_POST['customid']) ? strtolower($_POST['customid']) : '',
            'placementid' => eregi('^[0-9a-zA-Z-]{20}$', $_POST['placementid']) ? strtolower($_POST['placementid']) : '',
]]></add>
</operation>
</file>

<file name="$themedir/Post.template.php">
<operation>
<search position="before" whitespace="loose" ><![CDATA['list' => array('code' => 'list', 'before' => '[list]\n[li]', 'after' => '[/li]\n[li][/li]\n[/list]', 'description' => $txt[261]),]]></search>
<add><![CDATA[
// ADD MY EBAY TAG
'ebay' => array('code' => 'ebay', 'before' => '[ebay]', 'after' => '[/ebay]','description' => $txt['ebayitem']),
]]></add>
</operation>
</file>

<file name="$themedir/languages/Modifications.english.php">
<operation>
<search position="after"><![CDATA[?>]]></search>
<add><![CDATA[$txt['icweasylinker'] = 'Convert Ebay Links';
$txt['ebayitem'] = 'Ebay Item Number';
$txt['toolid'] = 'ToolID (10001 -- FlexDest.)';
$txt['campid'] = 'CampID';
$txt['customid'] = 'CustomID (Optional)';
$txt['ebay'] = 'eBay!';
$txt['signupfor'] = 'Sign-Up for  ';
$txt['placementid'] = 'ePN (711-53200-19255-0  -- US)';
]]></add>
</operation>
</file>


As always, thanks for the assistance,
JohnS

Arantor

Sorry for being late on replying to this, been busy.

QuoteMy mod doesn't touch that file.

Of course it doesn't. As I already said:
QuotePost.template.php implies it's adding a button to the editor, this would now be accomplished by a change (and a different one at that) to Subs-Editor.php.

As in, the edit you have to Post.template.php would now be accomplished by a different change instead to Subs-Editor.php.

Like so:
$context['bbc_tags'][] = array(
array(
'image' => 'bold',
'code' => 'b',
'before' => '[b]',
'after' => '[/b]',
'description' => $txt['bold'],
),


After which you'd want something like:

array(
'image' => 'ebay',
'code' => 'ebay',
'before' => '[ebay]',
'after' => '[/ebay]',
'description' => $txt['ebayitem'],
),


The rest... I'd be inclined to move out of the manage posts area and into the dedicated area for modification settings.

In ManageSettings.php you'll find this:
$config_vars = array(
// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!


Under that line you would add:

array('check', 'icweasylinker'),
array('text', 'placementid'),
array('text', 'campid'),
array('text', 'customid'),
array('text', 'toolid'),


This won't be quite as pretty as the original mod by not including all the extra descriptions and stuff but that can be done if it's really needed (I just didn't bother doing it right now ;)) That part replaces the edit to the admin template.

Then further down you'll find this:
// Saving?
if (isset($_GET['save']))
{
checkSession();

$save_vars = $config_vars;

// This line is to help mod authors do a search/add after if you want to add something here. Keyword: FOOT TAPPING SUCKS!
saveDBSettings($save_vars);

// This line is to help mod authors do a search/add after if you want to add something here. Keyword: I LOVE TEA!
redirectexit('action=admin;area=modsettings;sa=general');
}


I'd suggest replacing it with:
// Saving?
if (isset($_GET['save']))
{
checkSession();

$save_vars = $config_vars;

if (empty($_POST['campid']) || !preg_match('~^[0-9]{1,20}$~', $_POST['campid']))
$_POST['campid'] = '';
if (empty($_POST['customid']) || !preg_match('~^[0-9a-z-]{0,250}$~i', $_POST['customid']))
$_POST['customid'] = '';
if (empty($_POST['toolid']) || !preg_match('~^[0-9]{1,20}$~', $_POST['toolid']))
$_POST['toolid'] = '';
if (empty($_POST['placementid']) || !preg_match('~^[0-9a-z-]{1,20}$~', $_POST['placementid']))
$_POST['placementid'] = '';

// This line is to help mod authors do a search/add after if you want to add something here. Keyword: FOOT TAPPING SUCKS!
saveDBSettings($save_vars);

// This line is to help mod authors do a search/add after if you want to add something here. Keyword: I LOVE TEA!
redirectexit('action=admin;area=modsettings;sa=general');
}


I haven't tested this, though, and my knowledge of ereg is limited (there's a reason it's been phased out and replaced with preg and the author originally did it wrong anyway since he's used eregi to indicate case insensitive and then done it manually anyway), and this part replaces the edit to ManagePosts.php.

jjfeenix

Arantor:

I think I've got this rewritten.

Is there any direction/tutorial on how to go about testing a mod without taking a live forum down?

Thanks,
JohnS

live627


jjfeenix

OK. I got the Mod uploaded to a test board and worked through all the mod errors. I thought I was making real progress. But then I got this error:

Fatal error: Call to undefined function db_query() in /data/29/2/96/30/2748030/user/3020587/htdocs/ibanezreview/forum/Packages/temp/install.php on line 20

Here's the contents of install,php

<?php
/*************************************************
ICWEasyLinker 2
**************************************************
INSTALL.PHP
**************************************************/

if (!defined('SMF'))
die('Hacking attempt...');

// ADDS THE SETTINGS FOR THE MOD - ONLY IF THEY DON'T ALREADY EXIST
$newSetting['icweasylinker'] = // enable mod
$newSetting['placementid'] = ''//  placementid - not optional - determines which ePN program you are promoting
$newSetting['campid'] = ''//  campid - not optional - ebay generated
$newSetting['customid'] = ''// customid - 256 char limit (Optional)
$newSetting['toolid'] = ''//  toolid - not optional - not clear on where this gets encoded   >>  type?=

// CYCLE THROUGH ARRAY ADDING EACH NEW SETTING - IF ALREADY EXISTS, IGNORE
foreach ($newSetting as $key => $value) {
db_query("
INSERT IGNORE
INTO 
{$db_prefix}settings (`variable`, `value`)
VALUES ('
$key', '$value')
"
__FILE____LINE__);
}

?>


TIA,
JohnS

Arantor

You actually don't need any of that code. All that does is set default values - but the way it's been written, none of that is actually necessary.

jjfeenix

So, I can remove the install.php file from the zip file?

Arantor

Yes. All it's doing is setting default values but all the code I've provided will quite happily work safely without errors without having default values being in the database.

jjfeenix

Sorry to be a pain, but here's the latest error:
Fatal error: require() [function.require]: Failed opening required '/data/29/2/96/30/2748030/user/3020587/htdocs/ibanezreview/forum/Packages/temp/install.php' (include_path='.:/usr/share/php:/usr/services/vux/lib/php') in /data/29/2/96/30/2748030/user/3020587/htdocs/ibanezreview/forum/Sources/Packages.php on line 939

Arantor

That would be because you removed the file without removing the reference in package-info.xml to tell it to run install.php.

jjfeenix

Thanks for all the help. Got the mod to install successfully. When I went to test it, starting with viewing Mod Settings, started to get errors.

1. After choosing Admin>Features and Options, get the following error:

Parse error: syntax error, unexpected ',' in /data/29/2/96/30/2748030/user/3020587/htdocs/ibanezreview/forum/Sources/ManageSettings.php on line 2023

Here's the section of ManageSttings.php. Line 2023 starts with: array('check', icweasylinker'),:

$config_vars = array(
// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
);

array('check', 'icweasylinker'),
array('text', 'placementid'),
array('text', 'campid'),
array('text', 'customid'),
array('text', 'toolid'),


I decided to see if the Ebay button was appearing/operational in the Post Messages screen--it was there. Pressing the eBay button inserts the correct BBC open/close tags. Immediately after entering an ebay item number between the "ebay" tags, I get following error inserted, rather than the pasted item#:
[ebay]
Parse error: syntax error, unexpected ',' in /data/29/2/96/30/2748030/user/3020587/htdocs/ibanezreview/forum/Sources/ManageSettings.php on line 2023
[/ebay]


I checked the contents of the SMF Error Log and found this error (multiples times):
Type of error: Undefined
http://www.ibanezreview.com/forum/index.php?action=admin
8: Undefined index: ebayitem
File: /data/29/2/96/30/2748030/user/3020587/htdocs/ibanezreview/forum/Sources/Subs.php
Line: 1177


Line 1177 in Subs.php is one of the added array pieces of code (line 1177 starts with 'content' => ):

// ICWEasyLinker for ebay
                // IF ID NOT SET, USE MINE ;)
                array(
'tag' => 'ebay',
'type' => 'unparsed_content',
'content' => '<a href="http://rover.ebay.com/rover/1/' . (empty($modSettings['placementid']) ? '711-53200-19255-0' : $modSettings['placementid']) . '/1?type=2&campid=' . (empty($modSettings['campid']) ? '5335842975' : $modSettings['campid']) . '&toolid=' . (empty($modSettings['toolid']) ? '10001' : $modSettings['toolid']) . '&customid=' . (empty($modSettings['customid']) ? 'SMF' : $modSettings['customid']) . '&ext=$1&item=$1" target="_blank">' . $txt['ebayitem'] . ' #$1</a>',
),
               

Another entry in Error log (only 1 occurrence), refers to Subs-Editor:
Type of error: Undefined
http://www.ibanezreview.com/forum/index.php?action=post;topic=13.0;last_msg=25
8: Undefined index: ebayitem
File: /data/29/2/96/30/2748030/user/3020587/htdocs/ibanezreview/forum/Sources/Subs-Editor.php
Line: 1582


Line 1582 in Subs-Editor.php is another added array (line starts with 'description' => )

array(
'image' => 'ebay',
'code' => 'ebay',
'before' => '[ebay]',
'after' => '[/ebay]',
'description' => $txt['ebayitem'],
)


So, I'd say that 'ebayitem' is problem...I'm back to being stumped.

TIA
JohnS

Kindred

you need to make sure that $txt['ebayitem'] is defined in modifications.english.php
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

1. is because you did not follow my instructions correctly. The change to ManageSettings is supposed to go *inside* the brackets, not after them. As in following the comment: 'after this line'.

This also affects the other page where you get the error to ManageSettings.php.

As for the missing ebayitem, this is because your mod does not appear to be putting in the definition of $txt['ebayitem'] inside Modifications.english.php (or you are using a different language)

jjfeenix

Arantor:

Quote
1. is because you did not follow my instructions correctly. The change to ManageSettings is supposed to go *inside* the brackets, not after them. As in following the comment: 'after this line'.

So, it should look like this:
$config_vars = array(
// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
array('check', 'icweasylinker'),
array('text', 'placementid'),
array('text', 'campid'),
array('text', 'customid'),
array('text', 'toolid'),
);


QuoteThis also affects the other page where you get the error to ManageSettings.php.


QuoteAs for the missing ebayitem, this is because your mod does not appear to be putting in the definition of $txt['ebayitem'] inside Modifications.english.php (or you are using a different language)

Like this:
$txt['ebayitem'] = 'ebayitem';

JohnS

Advertisement: