summaryrefslogtreecommitdiffstats
path: root/wp-inst/wp-includes/create_smarty_template.php
blob: 7556a6889a2f150adb44150578690cff92cf090d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/php -q
<?php

/* $Id: create_smarty_template.php,v 1.7 2005/03/12 20:17:52 donncha Exp $ */


if (is_dir( "." )) 
{
	if ($dh = opendir( "." )) 
	{
		while (($file = readdir($dh)) !== false ) 
		{
			if( strpos( $file, "template-functions" ) !== false )
			{
				$files[] = $file;
			}
		}
		closedir($dh);
	}
}
$files[] = 'links.php';
$files[] = 'functions.php';
$files[] = 'wp-l10n.php';
$files[] = 'functions-formatting.php';
$files[] = 'functions-post.php';
$files[] = 'functions-user.php';
$files[] = 'feed-functions.php';
$files[] = 'comment-functions.php';


$buffer2 = '';
reset( $files );
while( list( $k, $file ) = each( $files ) )
{
	if( is_file( $file ) )
	{
		$fp = fopen( $file, "r" );
		while (!feof ($fp)) 
		{
			$buffer = fgets($fp, 4096);
			if( strpos( $buffer, "unction " ) == '1' )
			{
				if( strpos( $buffer, '{' ) === false )
				{
					// multi-line function call
					$buffer2 .= $buffer;
					while(!feof( $fp ) && strpos( $buffer, '{' ) === false )
					{
						$buffer = fgets($fp, 4096);
						$buffer2 .= $buffer;
					}
					$line[] = $buffer2;
					$buffer2 = '';
				}
				else
				{
					$line[] = $buffer;
					$buffer2 = '';
				}
			}

		}
		fclose ($fp);
	}
}
print '<'.'?'.'php'."\n".'
if( isset( $wpsmarty ) == false || is_object( $wpsmarty ) == false )
{       
        if( defined( ABSPATH ) == false )
            define( "ABSPATH", "../" );

	require_once( ABSPATH . "Smarty.class.php" );
	$wpsmarty = new Smarty;
}

';

reset( $line );
while( list( $key, $val ) = each( $line ) )
{
	$function = substr( $val, 9, strpos( $val, "(" ) - 9 );
	$bracket1 = strpos( $val, "(" ) + 1;
	$origargs = substr( $val, $bracket1, strpos( $val, ') {' ) - $bracket1 );
	$argslist = split( ",", $origargs );
	$args = '';
	$defineargs = '';
	reset( $argslist );
	while( list( $key, $val ) = each( $argslist ) )
	{
		if( strpos( $val, "=" ) )
		{
			$defineargs .= "    ".trim( $val ).";\n";
			$args .= trim( substr( $val, 0, strpos( $val, "=" ) ) ).", ";
		}
		else
		{
			$args .= $val.", ";
		}
	}
	$args = substr( $args, 0, -2 );
	print "/* $function( $origargs ) */\n";
	if( $function[0] == '&' )
	{
	    print "function &smarty_".substr( $function, 1 )."( \$params, &\$smarty )\n";
	}
	else
	{
	    print "function smarty_".$function."( \$params, &\$smarty )\n";
	}
	print "{\n";
	print "$defineargs\n";
	print "    extract( \$params );\n";
	if( $function[0] == '&' )
	{
	    print "    return ".substr( $function, 1 )."( $args );\n";
	}
	else
	{
	    print "    return $function( $args );\n";
	}
	print "}\n";
	if( $function[0] == '&' )
	{
	    print '$wpsmarty->register_function( "'.substr( $function, 1 ).'", "smarty_'.substr( $function, 1 ).'" );'."\n\n";
	}
	else
	{
	    print '$wpsmarty->register_function( "'.$function.'", "smarty_'.$function.'" );'."\n\n";
	}
}
print '
$wpsmarty->template_dir = ABSPATH."/wp-content/blogs/".$wpblog."/templates";
$wpsmarty->compile_dir  = ABSPATH."/wp-content/blogs/".$wpblog."/templates_c";
$wpsmarty->cache_dir    = ABSPATH."/wp-content/blogs/".$wpblog."/smartycache";
$wpsmarty->plugins_dir  = ABSPATH."/wp-content/smarty-plugins";
$wpsmarty->cache_lifetime = -1;
$wpsmarty->caching = true;
$wpsmarty->security = 1;
$wpsmarty->secure_dir = array( ABSPATH."/wp-content/blogs/".$wpblog."/templates", "wp-content/smarty-templates" );
if( isset( $_GET[ "clear" ] ) )
    $wpsmarty->clear_all_cache();
';
print "?".">";
?>