3 # This program is in the public domain within the United States. Additionally,
4 # we waive copyright and related rights in the work worldwide through the CC0
5 # 1.0 Universal public domain dedication, which can be found at
6 # http://creativecommons.org/publicdomain/zero/1.0/
8 # This script is designed to make it easier to use wfpl in other projects, and
9 # not worry about include paths or name collisions.
11 # This script packs most of wfpl into a single stream (to stdout) and makes it
12 # work inside the \wfpl namespace
14 # Run like so: bash ./namespacify > wfpl.php
16 # or: bash ./namespacify wordpress > wfpl.php
18 # The "wordpress" option breaks/obsoletes db_connect and makes db_*() use the
19 # wordpress database and automatically prepends the wordpress table name prefix
21 # And use in your project like so:
23 # require_once('/path/to/wfpl.php');
24 # $template = new \wfpl\tem();
25 # $records = \wfpl\db_get_assocs('records', 'name,quantity,date');
29 wfpl_rev="-$(git rev-parse HEAD)"
30 if ! git diff --quiet; then
31 wfpl_rev="$wfpl_rev-dirty"
37 echo '# Copyright (C) 2005,2013 Jason Woofenden <jason@jasonwoof.com>,'
38 echo '# 2008,2009 Joshua Grams <josh@qualdan.com>'
40 echo "# This file is generated from wfpl$wfpl_rev"
43 head -n 16 "template.php" | tail -n +5
45 echo 'namespace wfpl;'
47 if [ "$1" = 'wordpress' ]; then
49 echo '# wordpress tables are supposed to have a prefix.'
50 echo 'function add_wp_table_prefix($table) {'
51 echo ' # only add the wordpress table prefix once, just in case.'
52 echo ' if (substr($table, 0, strlen($GLOBALS['\''wpdb'\'']->prefix)) == $GLOBALS['wpdb']->prefix) {'
53 echo ' return $table;'
55 echo ' return $GLOBALS['\''wpdb'\'']->prefix . $table;'
58 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;'
60 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 '<?php' -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;/'