Skip to content

Instantly share code, notes, and snippets.

@pwqw
Forked from kasparsd/index.php
Created October 27, 2016 02:33
Show Gist options
  • Save pwqw/d8df1528a2ab8d839236f23b0d5c51f4 to your computer and use it in GitHub Desktop.
Save pwqw/d8df1528a2ab8d839236f23b0d5c51f4 to your computer and use it in GitHub Desktop.
Convert .mo to .po and .po to .mo
<?php
session_start();
$_SESSION['last_post'] = time();
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Online Tools for WordPress Developers</title>
<meta name="description" content="Convert .mo to/from .po translation files; Optimize (optipng) PNG files" />
<style>
body { font:16px/1.3 helvetica, sans-serif; color:#333; width:90%; max-width:468px; margin:2em auto; }
section { margin:3em 0; }
form { padding:0.5em; border:1px solid #ddd; background:#eee; border-radius:4px; }
code { background:#eee; }
code, pre { font-family: Consolas, Monaco, monospace; }
input[type=submit] { float:right; }
footer { margin-top:2em; font-size:smaller; color:#666; border-top:1px solid #ddd; }
iframe { max-width:100%; }
</style>
</head>
<body>
<section>
<h1>Convert <code>.mo</code> to <code>.po</code></h1>
<p>Uses <code>msgunfmt</code> from <code>gettext-tools</code></p>
<form action="msgunfmt.php" method="post" enctype="multipart/form-data">
<input type="file" name="mo_file" />
<input type="submit" value="Convert" />
</form>
</section>
<section>
<h1>Convert <code>.po</code> to <code>.mo</code></h1>
<p>Uses <code>msgfmt</code> from <code>gettext-tools</code></p>
<form action="msgfmt.php" method="post" enctype="multipart/form-data">
<input type="file" name="po_file" />
<input type="submit" value="Convert" />
</form>
</section>
<section>
<h1>Optimize PNG files</h1>
<p>Uses <code>optipng -o5</code> and will take a few seconds to complete.</p>
<form action="optipng.php" method="post" enctype="multipart/form-data">
<input type="file" name="png" />
<input type="submit" value="Convert" />
</form>
</section>
<section>
<h1>Optimize JPEG / JPG files</h1>
<p>Uses <code>jpegtran -optimise -progressive -copy none</code></p>
<form action="jpegtran.php" method="post" enctype="multipart/form-data">
<input type="file" name="jpeg" />
<input type="submit" value="Convert" />
</form>
</section>
<footer>
<p>Created by Kaspars Dambis &mdash; Twitter: <a href="http://twitter.com/konstruktors">@konstruktors</a> / Blog: <a href="http://kaspars.net">kaspars.net</a></p>
</footer>
</body>
</html>
<?php
session_start();
if (!$_SESSION['ip'] || !$_SESSION['last_post'])
die();
if (empty($_FILES['jpeg']))
die();
$source = $_FILES['jpeg']['tmp_name'];
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="'. $_FILES['jpeg']['name'] .'"');
passthru('jpegtran -optimise -progressive -copy none ' . $source);
unlink($source);
<?php
session_start();
if (!$_SESSION['ip'] || !$_SESSION['last_post'])
die();
if (empty($_FILES['po_file']))
die();
$source = $_FILES['po_file']['tmp_name'];
$result = substr($_FILES['po_file']['name'], 0, strrpos($_FILES['po_file']['name'], '.'));
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="'. $result .'.mo"');
passthru('msgfmt -o - ' . $source);
unlink($source);
<?php
session_start();
if (!$_SESSION['ip'] || !$_SESSION['last_post'])
die();
if (empty($_FILES['mo_file']))
die();
$source = $_FILES['mo_file']['tmp_name'];
$result = substr($_FILES['mo_file']['name'], 0, strrpos($_FILES['mo_file']['name'], '.'));
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="'. $result .'.po"');
passthru('msgunfmt ' . $source);
unlink($source);
<?php
session_start();
if (!$_SESSION['ip'] || !$_SESSION['last_post'])
die();
if (empty($_FILES['png']))
die();
$source = $_FILES['png']['tmp_name'];
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="'. $_FILES['png']['name'] .'"');
exec('optipng -o9 -quiet ' . $source);
echo file_get_contents($source);
unlink($source);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment