farleyknight-ionize 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +59 -0
- data/Rakefile +5 -0
- data/bin/ionize +47 -0
- data/lib/ionize.rb +75 -0
- data/lib/ionize/environment.rb +56 -0
- data/lib/ionize/environment/application.rb +58 -0
- data/lib/ionize/environment/php_array.rb +95 -0
- data/lib/ionize/parser.rb +272 -0
- data/lib/ionize/tokenizer.rb +544 -0
- data/lib/ionize/translate.rb +34 -0
- data/lib/ionize/translate/composite_string_statements.rb +79 -0
- data/lib/ionize/translate/debug.rb +16 -0
- data/lib/ionize/translate/ext.rb +47 -0
- data/lib/ionize/translate/function_args.rb +132 -0
- data/lib/ionize/translate/if_statements.rb +42 -0
- data/lib/ionize/translate/multiple_statements.rb +22 -0
- data/lib/ionize/translate/php_to_ruby.rb +40 -0
- data/lib/ionize/translate/rails_for_php.rb +191 -0
- data/lib/ionize/translate/rewritable.rb +133 -0
- data/lib/ionize/translate/rewrites.rb +51 -0
- data/lib/ionize/translate/statements.rb +622 -0
- data/lib/ionize/translate/switch_case_statements.rb +52 -0
- data/lib/ionize/translate/term_statements.rb +76 -0
- data/lib/ionize/translate/translator.rb +52 -0
- data/lib/ionize/version.rb +9 -0
- data/spec/fixtures/array_lookup.php +10 -0
- data/spec/fixtures/boolean_operators.php +5 -0
- data/spec/fixtures/boolean_operators.rb +6 -0
- data/spec/fixtures/class_def.php +34 -0
- data/spec/fixtures/class_def.rb +34 -0
- data/spec/fixtures/dangling_else.php +8 -0
- data/spec/fixtures/dangling_else.rb +12 -0
- data/spec/fixtures/drupal_1.php +663 -0
- data/spec/fixtures/drupal_2.php +1152 -0
- data/spec/fixtures/empty_string.php +12 -0
- data/spec/fixtures/for_loop.php +17 -0
- data/spec/fixtures/for_loop2.php +13 -0
- data/spec/fixtures/for_loop3.php +16 -0
- data/spec/fixtures/for_loop3.rb +17 -0
- data/spec/fixtures/for_loop4.php +5 -0
- data/spec/fixtures/for_loop4.rb +6 -0
- data/spec/fixtures/foreach.php +9 -0
- data/spec/fixtures/foreach2.php +8 -0
- data/spec/fixtures/foreach3.php +7 -0
- data/spec/fixtures/foreach3.rb +7 -0
- data/spec/fixtures/fun_def.php +9 -0
- data/spec/fixtures/fun_def2.php +30 -0
- data/spec/fixtures/fun_def2.rb +30 -0
- data/spec/fixtures/fun_def3.php +33 -0
- data/spec/fixtures/fun_def4.php +43 -0
- data/spec/fixtures/fun_def4.rb +37 -0
- data/spec/fixtures/fun_def5.php +36 -0
- data/spec/fixtures/fun_with_if.php +6 -0
- data/spec/fixtures/fun_with_if.rb +6 -0
- data/spec/fixtures/fun_with_ifs.php +12 -0
- data/spec/fixtures/fun_with_ifs.rb +14 -0
- data/spec/fixtures/hello_world.php +6 -0
- data/spec/fixtures/heredoc.php +6 -0
- data/spec/fixtures/heredoc.rb +5 -0
- data/spec/fixtures/if.php +6 -0
- data/spec/fixtures/if.rb +7 -0
- data/spec/fixtures/if_boolean.php +5 -0
- data/spec/fixtures/if_boolean.rb +5 -0
- data/spec/fixtures/if_else.php +11 -0
- data/spec/fixtures/if_else1.php +17 -0
- data/spec/fixtures/if_else2.php +8 -0
- data/spec/fixtures/if_else3.php +15 -0
- data/spec/fixtures/if_else_nested.php +14 -0
- data/spec/fixtures/if_else_nested.rb +15 -0
- data/spec/fixtures/if_else_series.php +12 -0
- data/spec/fixtures/if_else_series.rb +12 -0
- data/spec/fixtures/if_not.php +5 -0
- data/spec/fixtures/if_not.rb +5 -0
- data/spec/fixtures/if_with_brackets.php +7 -0
- data/spec/fixtures/if_with_brackets.rb +7 -0
- data/spec/fixtures/long_if_else.php +10 -0
- data/spec/fixtures/long_if_else.rb +9 -0
- data/spec/fixtures/oo.php +16 -0
- data/spec/fixtures/php_nuke/sql_layer.php +527 -0
- data/spec/fixtures/postop.php +3 -0
- data/spec/fixtures/preop.php +7 -0
- data/spec/fixtures/simple_fun_def.php +4 -0
- data/spec/fixtures/switch_case.php +13 -0
- data/spec/fixtures/switch_case.rb +14 -0
- data/spec/fixtures/switch_case2.php +25 -0
- data/spec/fixtures/switch_case3.php +40 -0
- data/spec/fixtures/switch_case3.rb +42 -0
- data/spec/fixtures/switch_case4.php +56 -0
- data/spec/fixtures/switch_case5.php +71 -0
- data/spec/fixtures/switch_case_with_rescue_nil.php +43 -0
- data/spec/fixtures/switch_case_with_rescue_nil.rb +35 -0
- data/spec/fixtures/tertiary.php +3 -0
- data/spec/helper.rb +17 -0
- data/spec/php_environment_spec.rb +83 -0
- data/spec/php_parser_spec.rb +121 -0
- data/spec/php_translator_spec.rb +358 -0
- data/spec/rails_for_php_spec.rb +303 -0
- metadata +191 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
switch ($op) {
|
3
|
+
// update.php ops
|
4
|
+
case 'info':
|
5
|
+
$output = update_info_page();
|
6
|
+
break;
|
7
|
+
|
8
|
+
case 'selection':
|
9
|
+
$output = update_selection_page();
|
10
|
+
break;
|
11
|
+
|
12
|
+
case 'Update':
|
13
|
+
update_batch();
|
14
|
+
break;
|
15
|
+
|
16
|
+
case 'results':
|
17
|
+
$output = update_results_page();
|
18
|
+
break;
|
19
|
+
|
20
|
+
// Regular batch ops : defer to batch processing API
|
21
|
+
default:
|
22
|
+
update_task_list('run');
|
23
|
+
$output = _batch_page();
|
24
|
+
break;
|
25
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
$mode = 'reply';
|
3
|
+
$res = "res";
|
4
|
+
$nr = "nr";
|
5
|
+
$lang = "lang";
|
6
|
+
|
7
|
+
switch( $mode ) {
|
8
|
+
case 'reply':
|
9
|
+
case 'quote':
|
10
|
+
$is_auth_type = 'auth_reply';
|
11
|
+
break;
|
12
|
+
case 'editpost':
|
13
|
+
$is_auth_type = 'auth_edit';
|
14
|
+
break;
|
15
|
+
case 'delete':
|
16
|
+
case 'poll_delete':
|
17
|
+
$is_auth_type = 'auth_delete';
|
18
|
+
break;
|
19
|
+
case 'vote':
|
20
|
+
$is_auth_type = 'auth_vote';
|
21
|
+
break;
|
22
|
+
case 'topicreview':
|
23
|
+
$is_auth_type = 'auth_read';
|
24
|
+
break;
|
25
|
+
case "ODBC":
|
26
|
+
$row = array();
|
27
|
+
$result = array();
|
28
|
+
$result = odbc_fetch_row($res, $nr);
|
29
|
+
$nf = odbc_num_fields($res); /* Field numbering starts at 1 */
|
30
|
+
for($count=1; $count < $nf+1; $count++) {
|
31
|
+
$field_name = odbc_field_name($res, $count);
|
32
|
+
$field_value = odbc_result($res, $field_name);
|
33
|
+
$row[$field_name] = $field_value;
|
34
|
+
}
|
35
|
+
return $row;
|
36
|
+
break;
|
37
|
+
default:
|
38
|
+
message_die(GENERAL_MESSAGE, $lang['No_post_mode']);
|
39
|
+
break;
|
40
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
mode = 'reply'
|
3
|
+
res = "res"
|
4
|
+
nr = "nr"
|
5
|
+
lang = "lang"
|
6
|
+
|
7
|
+
case mode
|
8
|
+
when 'reply'
|
9
|
+
when 'quote'
|
10
|
+
is_auth_type = 'auth_reply'
|
11
|
+
break
|
12
|
+
when 'editpost'
|
13
|
+
is_auth_type = 'auth_edit'
|
14
|
+
break
|
15
|
+
when 'delete'
|
16
|
+
when 'poll_delete'
|
17
|
+
is_auth_type = 'auth_delete';
|
18
|
+
break
|
19
|
+
when 'vote'
|
20
|
+
is_auth_type = 'auth_vote'
|
21
|
+
break
|
22
|
+
when 'topicreview'
|
23
|
+
is_auth_type = 'auth_read'
|
24
|
+
break
|
25
|
+
when 'ODBC'
|
26
|
+
row = array()
|
27
|
+
result = array()
|
28
|
+
result = odbc_fetch_row(res, nr)
|
29
|
+
nf = odbc_num_fields(res)
|
30
|
+
count = 1
|
31
|
+
while count < nf + 1
|
32
|
+
field_name = odbc_field_name(res, count)
|
33
|
+
field_value = odbc_result(res, field_name)
|
34
|
+
row[field_name] = field_value
|
35
|
+
count += 1
|
36
|
+
end
|
37
|
+
return row
|
38
|
+
break
|
39
|
+
else
|
40
|
+
message_die(GENERAL_MESSAGE, lang['No_post_mode'])
|
41
|
+
break
|
42
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
/*
|
3
|
+
* sql_query($query, $id)
|
4
|
+
* executes an SQL statement, returns a result identifier
|
5
|
+
*/
|
6
|
+
|
7
|
+
function sql_query($query, $id)
|
8
|
+
{
|
9
|
+
global $dbtype, $sql_debug;
|
10
|
+
$sql_debug = 0;
|
11
|
+
|
12
|
+
if($sql_debug) echo "SQL query: ".str_replace(",",", ",$query)."<BR>";
|
13
|
+
|
14
|
+
switch ($dbtype) {
|
15
|
+
|
16
|
+
case "MySQL":
|
17
|
+
$res=@mysql_query($query, $id);
|
18
|
+
return $res;
|
19
|
+
break;;
|
20
|
+
|
21
|
+
case "mSQL":
|
22
|
+
$res=@msql_query($query, $id);
|
23
|
+
return $res;
|
24
|
+
break;;
|
25
|
+
|
26
|
+
case "postgres":
|
27
|
+
case "postgres_local":
|
28
|
+
$res=pg_exec($id,$query);
|
29
|
+
$result_set = new ResultSet;
|
30
|
+
$result_set->set_result( $res );
|
31
|
+
$result_set->set_total_rows( sql_num_rows( $result_set ) );
|
32
|
+
$result_set->set_fetched_rows( 0 );
|
33
|
+
return $result_set;
|
34
|
+
break;;
|
35
|
+
|
36
|
+
case "ODBC":
|
37
|
+
case "ODBC_Adabas":
|
38
|
+
$res=@odbc_exec($id,$query);
|
39
|
+
return $res;
|
40
|
+
break;;
|
41
|
+
|
42
|
+
case "Interbase":
|
43
|
+
$res=@ibase_query($id,$query);
|
44
|
+
return $res;
|
45
|
+
break;;
|
46
|
+
|
47
|
+
case "Sybase":
|
48
|
+
$res=@sybase_query($query, $id);
|
49
|
+
return $res;
|
50
|
+
break;;
|
51
|
+
|
52
|
+
default:
|
53
|
+
break;;
|
54
|
+
|
55
|
+
}
|
56
|
+
}
|
@@ -0,0 +1,71 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
function sql_fetch_array(&$res, $nr=0)
|
4
|
+
{
|
5
|
+
global $dbtype;
|
6
|
+
switch ($dbtype)
|
7
|
+
{
|
8
|
+
case "MySQL":
|
9
|
+
$row = array();
|
10
|
+
$row = mysql_fetch_array($res);
|
11
|
+
return $row;
|
12
|
+
break;;
|
13
|
+
|
14
|
+
case "mSQL":
|
15
|
+
$row = array();
|
16
|
+
$row = msql_fetch_array($res);
|
17
|
+
return $row;
|
18
|
+
break;;
|
19
|
+
|
20
|
+
case "postgres":
|
21
|
+
case "postgres_local":
|
22
|
+
if( $res->get_total_rows() > $res->get_fetched_rows() ) {
|
23
|
+
$row = array();
|
24
|
+
$row = pg_fetch_array($res->get_result(), $res->get_fetched_rows() );
|
25
|
+
$res->increment_fetched_rows();
|
26
|
+
return $row;
|
27
|
+
} else {
|
28
|
+
return false;
|
29
|
+
}
|
30
|
+
break;;
|
31
|
+
|
32
|
+
case "ODBC":
|
33
|
+
$row = array();
|
34
|
+
$result = array();
|
35
|
+
$result = odbc_fetch_row($res, $nr);
|
36
|
+
$nf = odbc_num_fields($res); /* Field numbering starts at 1 */
|
37
|
+
for($count=1; $count < $nf+1; $count++) {
|
38
|
+
$field_name = odbc_field_name($res, $count);
|
39
|
+
$field_value = odbc_result($res, $field_name);
|
40
|
+
$row[$field_name] = $field_value;
|
41
|
+
}
|
42
|
+
return $row;
|
43
|
+
break;;
|
44
|
+
|
45
|
+
case "ODBC_Adabas":
|
46
|
+
$row = array();
|
47
|
+
$result = array();
|
48
|
+
$result = odbc_fetch_row($res, $nr);
|
49
|
+
|
50
|
+
$nf = count($result)+2; /* Field numbering starts at 1 */
|
51
|
+
for($count=1; $count < $nf; $count++) {
|
52
|
+
$field_name = odbc_field_name($res, $count);
|
53
|
+
$field_value = odbc_result($res, $field_name);
|
54
|
+
$row[$field_name] = $field_value;
|
55
|
+
}
|
56
|
+
return $row;
|
57
|
+
break;;
|
58
|
+
|
59
|
+
case "Interbase":
|
60
|
+
$orow=ibase_fetch_object($res);
|
61
|
+
$row=get_object_vars($orow);
|
62
|
+
return $row;
|
63
|
+
break;;
|
64
|
+
|
65
|
+
case "Sybase":
|
66
|
+
$row = sybase_fetch_array($res);
|
67
|
+
return $row;
|
68
|
+
break;;
|
69
|
+
|
70
|
+
}
|
71
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
function sql_logout($id)
|
4
|
+
{
|
5
|
+
global $dbtype;
|
6
|
+
switch ($dbtype) {
|
7
|
+
|
8
|
+
case "MySQL":
|
9
|
+
$dbi=@mysql_close($id);
|
10
|
+
return $dbi;
|
11
|
+
break;;
|
12
|
+
|
13
|
+
case "mSQL":
|
14
|
+
$dbi=@msql_close($id);
|
15
|
+
return $dbi;
|
16
|
+
break;;
|
17
|
+
|
18
|
+
case "postgres":
|
19
|
+
case "postgres_local":
|
20
|
+
$dbi=@pg_close($id);
|
21
|
+
return $dbi;
|
22
|
+
break;;
|
23
|
+
|
24
|
+
case "ODBC":
|
25
|
+
case "ODBC_Adabas":
|
26
|
+
$dbi=@odbc_close($id);
|
27
|
+
return $dbi;
|
28
|
+
break;;
|
29
|
+
|
30
|
+
case "Interbase":
|
31
|
+
$dbi=@ibase_close($id);
|
32
|
+
return $dbi;
|
33
|
+
break;;
|
34
|
+
|
35
|
+
case "Sybase":
|
36
|
+
$dbi=@sybase_close($id);
|
37
|
+
return $dbi;
|
38
|
+
break;;
|
39
|
+
|
40
|
+
default:
|
41
|
+
break;;
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
def sql_logout(id)
|
3
|
+
$dbtype
|
4
|
+
|
5
|
+
case $dbtype
|
6
|
+
when "MySQL"
|
7
|
+
dbi = mysql_close(id) rescue nil
|
8
|
+
return dbi
|
9
|
+
break
|
10
|
+
when "mSQL"
|
11
|
+
dbi = msql_close(id) rescue nil
|
12
|
+
return dbi
|
13
|
+
break
|
14
|
+
when "postgres"
|
15
|
+
when"postgres_local"
|
16
|
+
dbi = pg_close(id) rescue nil
|
17
|
+
return dbi
|
18
|
+
break
|
19
|
+
when "ODBC"
|
20
|
+
when "ODBC_Adabas"
|
21
|
+
dbi = odbc_close(id) rescue nil
|
22
|
+
return dbi
|
23
|
+
break
|
24
|
+
when "Interbase"
|
25
|
+
dbi = ibase_close(id) rescue nil
|
26
|
+
return dbi
|
27
|
+
break
|
28
|
+
when "Sybase"
|
29
|
+
dbi = sybase_close(id) rescue nil
|
30
|
+
return dbi
|
31
|
+
break
|
32
|
+
else
|
33
|
+
break
|
34
|
+
end
|
35
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module SpecHelperMethods
|
4
|
+
# teh php codez
|
5
|
+
def php_ast(text)
|
6
|
+
Ionize::Php.to_sexp(text)
|
7
|
+
end
|
8
|
+
|
9
|
+
# teh ruby codez
|
10
|
+
def ruby_ast(text)
|
11
|
+
ParseTree.translate(text)
|
12
|
+
end
|
13
|
+
|
14
|
+
def php_to_ruby_eval(text)
|
15
|
+
eval(Ionize::Php.to_ruby(text))
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
|
2
|
+
require 'spec'
|
3
|
+
require 'spec/helper'
|
4
|
+
require 'lib/ionize'
|
5
|
+
|
6
|
+
describe "Transforms Php for posix regex" do
|
7
|
+
include Ionize::Php::Environment, SpecHelperMethods
|
8
|
+
|
9
|
+
it "rewrites ereg" do
|
10
|
+
php_ast(%Q{ $date = "2008-08-09"; $result = ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $matches); }).should ==
|
11
|
+
ruby_ast(%Q{ date = "2008-08-09"; result, matches = date.match(/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/) })
|
12
|
+
end
|
13
|
+
|
14
|
+
it "rewrites eregi" do
|
15
|
+
php_ast(%Q{ $date = "2008-08-09"; $result = eregi("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $matches); }).should ==
|
16
|
+
ruby_ast(%Q{ date = "2008-08-09"; result, matches = date.match(/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/i) })
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Transforms Php for miscellaneous functions" do
|
21
|
+
include Ionize::Php::Environment, SpecHelperMethods
|
22
|
+
|
23
|
+
it "rewites var_dump" do
|
24
|
+
php_ast(%Q{ a = "something"; var_dump($a); }).should ==
|
25
|
+
ruby_ast(%Q{ a = "something"; puts a })
|
26
|
+
end
|
27
|
+
|
28
|
+
it "rewrites isset" do
|
29
|
+
php_ast(%Q{ $a = "something"; isset($a); }).should ==
|
30
|
+
ruby_ast(%Q{ a = "something"; a.not_nil? })
|
31
|
+
end
|
32
|
+
|
33
|
+
it "rewrites function_exists" do
|
34
|
+
php_ast(%Q{ function_exists('file_get_contents'); }).should ==
|
35
|
+
ruby_ast(%Q{ respond_to? 'file_get_contents' })
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "Transforms Php for miscellaneous functions" do
|
40
|
+
include Ionize::Php::Environment, SpecHelperMethods
|
41
|
+
|
42
|
+
it "evaluates gethostbyaddr to the domain name" do
|
43
|
+
php_to_ruby_eval(%Q{ gethostbyaddr("127.0.0.1"); }).should == "localhost"
|
44
|
+
php_to_ruby_eval(%Q{ gethostbyaddr("75.127.96.35"); }).should == "li22-35.members.linode.com"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
describe "Transforms Php for arrays" do
|
50
|
+
include Ionize::Php::Environment, SpecHelperMethods
|
51
|
+
|
52
|
+
|
53
|
+
it "rewrites array_intersect" do
|
54
|
+
php_ast(%Q{
|
55
|
+
$array1 = array("a" => "green", "red", "blue");
|
56
|
+
$array2 = array("b" => "green", "yellow", "red");
|
57
|
+
$result = array_intersect($array1, $array2);
|
58
|
+
}).should == ruby_ast(%Q{
|
59
|
+
array1 = array({"a" => "green"}, "red", "blue")
|
60
|
+
array2 = array({"b" => "green"}, "yellow", "red")
|
61
|
+
result = array1.intersect(array2)
|
62
|
+
})
|
63
|
+
end
|
64
|
+
|
65
|
+
it "finds common hash values from the first array in the rest of the arrays" do
|
66
|
+
php_to_ruby_eval(%Q{
|
67
|
+
$array1 = array("a" => "green", "red", "blue");
|
68
|
+
$array2 = array("b" => "green", "yellow", "red");
|
69
|
+
$result = array_intersect($array1, $array2);
|
70
|
+
$result;
|
71
|
+
}).should == array("a" => "green", 0 => "red")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "creates a 1-based array" do
|
75
|
+
php_to_ruby_eval(%Q{ array(1 => 'January', 'February', 'March'); }).should ==
|
76
|
+
array(1=>"January", 2=>"February", 3=>"March")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "evaluates the order of arguments for array() similar to Php" do
|
80
|
+
php_to_ruby_eval(%Q{ array(1, 1, 1, 1, 1, 8 => 1, 4 => 1, 19, 3 => 13); }).should ==
|
81
|
+
array(0 => 1, 1 => 1, 2 => 1, 3 => 13, 4 => 1, 8 => 1, 9 => 19)
|
82
|
+
end
|
83
|
+
end
|