Created
October 11, 2015 14:48
-
-
Save fabd/1dc343b45adb8a6be7f3 to your computer and use it in GitHub Desktop.
Simple php script to extract all the MyBB templates used in the default theme, to a folder of your choice. This is mostly for reference, so that grep returns the template name when searching for variables and the like.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* A very simple command line php script to extract all the templates from the | |
* default MyBB theme into a given folder. | |
* | |
* This makes it easier to search the templates with grep and similar tools. | |
* | |
* The .html extension is added to the template names for proper syntax | |
* highlighting in most editors. | |
* | |
* Run the script from the root MyBB installation folder and create the folder | |
* beforehand, eg: | |
* | |
* $ mkdir templates | |
* $ chmod 777 templates | |
* $ php extract_mybb_templates.php -x | |
* | |
*/ | |
define("IN_MYBB", 1); | |
define("NO_ONLINE", 1); | |
define('THIS_SCRIPT', 'extract_templates.php'); | |
require_once "./inc/init.php"; | |
// chose a subdirectory where we edit stylesheets | |
define('TEMPLATES_PATH', MYBB_ROOT.'templates/'); | |
if ($argv[1] === '-x') | |
{ | |
$query = $db->query("SELECT tid, title, template FROM mybb_templates WHERE sid = -2 ORDER BY title ASC"); | |
echo sprintf("%d templates\n", $db->num_rows($query)); | |
$n = 0; | |
while ($row = $db->fetch_array($query)) | |
{ | |
$n++; | |
$tid = $row['tid']; | |
$title = $row['title']; | |
$template = $row['template']; | |
$file = TEMPLATES_PATH.$title.'.html'; | |
if (false !== ($length = file_put_contents($file, $template))) | |
{ | |
echo sprintf("%04d. Extracted '%s' (%d bytes)\n", $n, $title, $length); | |
} | |
} | |
} | |
else | |
{ | |
echo "Use -x to extract templates.\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment