MyBB Community Forums

Full Version: Patches 1.5
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8
Is this plugin able to identify core edits that were made previously to installing the plugin?
(2012-05-12, 12:03 AM)winds Wrote: [ -> ]Is this plugin able to identify core edits that were made previously to installing the plugin?

No.

It can only undo edits made by itself.

It also sees edits made by other plugins (as long as they were done with PluginLibrary's edit_core() function), but that is only used to prevent editing conflicts between plugins.

In order to actually produce edits, you have to define a patch in the plugin itself, either manually or by importing a previously exported Patches XML file. So while the plugin can undo its own edits, it can not reproduce them if those rules are missing for some reason.

If you don't remember which changes you made, you can use a file comparison tool like GNU diff, use it to compare your file with the original file. Then create a Patch in the Patches plugin for each individual change.
Should there be a language file in the main English directory (inc/languages/english)? For some reason, when trying to manually create a user it gives me an error about this file (I checked and it doesn't exist in my file that I uploaded).
I think that is caused by plugins using $lang->load('foo', true, false); (loading lang files as data handler lang files) when they shouldn't really do so.
MyBB's lang->load is buggered

Workaround 1: put another copy of the language file in that folder
Workaround 2: https://github.com/frostschutz/Patches/c...7a8e8179f6

This fix will be in the next release whenever that might be
Patches 1.4:
- works around the language load bug
- support for multi/none matches (for sake of completeness, as PluginLibrary offers these features)
- it now asks for confirmation when you try to uninstall
- requires PluginLibrary 11 or newer

Import/Export will work between 1.4 and 1.3/older, but 1.3 does not understand the multi/none setting so it will discard these settings.

Due to database changes, you'll have to deactivate/activate the plugin after updating. Failure to do so will yield SQL errors in the patches tab.
Hello frostschuz,

Could you let me know how to fix Patches plugin to not display the comment

/*  */

Because, I want to patch something inside the print <<<EOF ... EOF; . So after the patches. It will displays the comment automatically.

How to remove them?


For example, it is the code before apply the patch :

print <<<EOF
		<p>{$lang->enter_username_and_password}</p>
		<form method="post" action="{$_SERVER['PHP_SELF']}{$query_string}">
		<div class="form_container">

			<div class="label"{$login_label_width}><label for="username">{$lang_username}</label></div>
			<div class="field"><input type="text" name="username" id="username" class="text_input initial_focus" /></div>

			<div class="label"{$login_label_width}><label for="password">{$lang->password}</label></div>
			<div class="field"><input type="password" name="password" id="password" class="text_input" /></div>

			<div class="label"{$login_label_width}><label for="pin">Secret PIN</label></div>
			<div class="field"><input type="password" name="pin" id="pin" class="text_input" /></div>
		</div>
		<p class="submit">
			<span class="forgot_password">
				<a href="../member.php?action=lostpw">{$lang->lost_password}</a>
			</span>

			<input type="submit" value="{$lang->login}" />
			<input type="hidden" name="do" value="login" />
		</p>
		</form>
	</div>
</div>
</body>
</html>
EOF;


And this is after apply the patch

print <<<EOF
		<p>{$lang->enter_username_and_password}</p>
		<form method="post" action="{$_SERVER['PHP_SELF']}{$query_string}">
		<div class="form_container">

			<div class="label"{$login_label_width}><label for="username">{$lang_username}</label></div>

			<div class="field"><input type="text" name="username" id="username" class="text_input initial_focus" /></div>

/* - LCL:patches - /* 			<div class="label"{$login_label_width}><label for="password">{$lang->password}</label></div>
/* - LCL:patches - /* 			<div class="field"><input type="password" name="password" id="password" class="text_input" /></div>
/* + LCL:patches + */ <div class="label"{$login_label_width}><label for="password">{$lang->password}</label></div>

/* + LCL:patches + */ <div class="field"><input type="password" name="password" id="password" class="text_input" /></div>

/* + LCL:patches + */ <div class="label"{$login_label_width}><label for="pin">Secret PIN</label></div>

/* + LCL:patches + */ <div class="field"><input type="password" name="pin" id="pin" class="text_input" /></div>
		</div>
		<p class="submit">
			<span class="forgot_password">
				<a href="../member.php?action=lostpw">{$lang->lost_password}</a>
			</span>

			<input type="submit" value="{$lang->login}" />
			<input type="hidden" name="do" value="login" />
		</p>
		</form>
	</div>
</div>
</body>
</html>
EOF;
It's not possible. The Patches plugin uses the comments to mark the original and inserted code. Those markers are necessary in order to be able to revert and reapply the patch later on. If you have a section in your PHP code that does not handle /* */ as a comment, because it's in the middle of the string, you'll have to replace the entire string instead, or find another way to apply your modification.

Example:

Search string:
print <<<EOF
<div class="label"{$login_label_width}><label for="password">{$lang->password}</label></div>
<div class="field">
EOF;

That search string will match the entire print block. So now you can insert code before and after that block.

Insert before:

ob_start();

Insert after:

$obc = ob_get_contents();
ob_end_clean();
$obc = preg_replace('@\\Q<input type="password" name="password" id="password" class="text_input" /></div>\\E@m',
    '\\0 <div class="label"{$login_label_width}><label for="pin">Secret PIN</label></div><div class="field"><input type="password" name="pin" id="pin" class="text_input" /></div>',
    $obc);
print $obc;

Haven't tested this code but you get the idea. Instead of modifying the string directly in the code, catch it using PHP's output buffer mechanism, then modify the string using preg_replace or any other suitable string replacement function. Then print it.
I'm thinking about it. Thanks you frostschuz.

How could I remove the print <<<EOF ?

I mean, what should I do to replace print <<<EOF in the admin/inc/class_page.php ?


I'm quite new to MyBB, I'm not sure if I remove the print <<<EOF will broke the mybb admin login page or not.

P/S: Anyway, your code will display MyBB warning error. Smile
You don't remove it (select replace: No in Patches); you let it stay as is but change its result afterwards.

Read on php.net about ob_start(), ob_get_contents().
Pages: 1 2 3 4 5 6 7 8