X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=namespacify.sh;fp=namespacify.sh;h=f7bc6f06beb2d51f185b7e62f7279074647f02df;hb=13cee08524dc328f40f089631ef9efa1fc13e251;hp=0000000000000000000000000000000000000000;hpb=7a16207b28e113674dfc56846c2971086b34cd0e;p=wfpl.git diff --git a/namespacify.sh b/namespacify.sh new file mode 100644 index 0000000..f7bc6f0 --- /dev/null +++ b/namespacify.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# This script is designed to make it easier to use wfpl in other projects, and +# not worry about include paths or name collisions. +# +# This script packs most of wfpl into a single stream (to stdout) and makes it +# work inside the \wfpl namespace +# +# Run like so: bash ./namespacify > wfpl.php +# +# or: bash ./namespacify wordpress > wfpl.php +# +# The "wordpress" option breaks/obsoletes db_connect and makes db_*() use the +# wordpress database and automatically prepends the wordpress table name prefix +# +# And use in your project like so: +# +# require_once('/path/to/wfpl.php'); +# $template = new \wfpl\tem(); +# $records = \wfpl\db_get_assocs('records', 'name,quantity,date'); + +wfpl_rev="" +if [ -d .git ]; then + wfpl_rev="-$(git rev-parse HEAD)" + if ! git diff --quiet; then + wfpl_rev="$wfpl_rev-dirty" + fi +fi + +echo ',' +echo '# 2008,2009 Joshua Grams ' +echo '#' +echo "# This file is generated from wfpl$wfpl_rev" +echo '#' +# output license +head -n 16 "template.php" | tail -n +5 +echo +echo 'namespace wfpl;' +wordpress_regex='' +if [ "$1" = 'wordpress' ]; then + echo + echo '# wordpress tables are supposed to have a prefix.' + echo 'function add_wp_table_prefix($table) {' + echo ' # only add the wordpress table prefix once, just in case.' + echo ' if (substr($table, 0, strlen($GLOBALS['\''wpdb'\'']->prefix)) == $GLOBALS['wpdb']->prefix) {' + echo ' return $table;' + echo ' } else {' + echo ' return $GLOBALS['\''wpdb'\'']->prefix . $table;' + echo ' }' + echo '}' + wordpress_regex='s/function db_\(send_get\|insert_ish\|update\|delete\|\)(.*{/\0\n\t$table = add_wp_table_prefix($table);/; s/\$GLOBALS\['\''wfpl_db_handle'\''\]/$GLOBALS['\''wpdb'\'']->dbh/g;' +fi +cat atexit.php csv.php db.php email.php encode.php file.php file_run.php format.php http.php messages.php misc.php template.php time.php | grep -v -e '' -e '^\s*//' -e 'require_once' -e '^\s*$' | grep -v -P -e '^\s*#\s*((?!NAMESPACIFY).)*$' | sed -e "$wordpress_regex"'s/\(register_shutdown_function\|function_exists\|call_user_func_array\)(/\0'\''\\\\wfpl\\\\'\'' . /; s/^\(\s*\)# NAMESPACIFY \(.*\)/\1\2 = '\''\\\\wfpl\\\\'\'' . \2;/'