--- /dev/null
+#!/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 '<?php'
+echo
+echo '# Copyright (C) 2005,2013 Jason Woofenden <jason@jasonwoof.com>,'
+echo '# 2008,2009 Joshua Grams <josh@qualdan.com>'
+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 '<?php' -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;/'
if(count($tem['args'])) {
$auto_func = "tem_auto_" . $tem['args'][0];
- function_exists($auto_func)
- or die("ERROR: template auto function '$auto_func' not found.<br>\n");
+ if (!function_exists($auto_func)) {
+ die("ERROR: template auto function '$auto_func' not found.<br>\n");
+ }
+ # NAMESPACIFY $auto_func
+ }
+ if ($auto_func) {
+ $value = $auto_func($scope['data'][$key], $key, $scope, $tem['args']);
}
- if($auto_func) $value = $auto_func($scope['data'][$key], $key, $scope, $tem['args']);
else $value = $scope['data'][$key];
$rows = tem_data_as_rows($value, $key);
$value = tem_get_data($key, $context);
foreach($tag['args'] as $encoding) {
$func = "enc_$encoding";
- if(function_exists($func)) $value = $func($value, $key);
- else die("ERROR: encoder function '$func' not found.<br>\n");
+ if (function_exists($func)) {
+ # NAMESPACIFY $func
+ $value = $func($value, $key);
+ } else {
+ die("ERROR: encoder function '$func' not found.<br>\n");
+ }
}
return $value;
}