-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabra_test.php
154 lines (117 loc) · 4.07 KB
/
abra_test.php
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
145
146
147
148
149
150
151
152
153
154
<?
global $ITEM_TABLE; # in case abra.php is included in a larger script
$ITEM_TABLE = 'rcatdb_items';
function abra_connect () {
$sql_link = mysql_connect("localhost","rcats","meoow");
mysql_select_db("rcats");
}
function output_catitems_by_cid($cid, $format, $cols, $separator) {
$catitems = array();
get_catitems ($cid, $catitems);
output_array($catitems, $format, $cols, $separator);
}
function output_catitems($handle, $format, $cols, $separator) {
//TODO: resolve ambiguous handles
$cid = resolve_handle($handle);
output_catitems_by_cid($cid, $format, $cols, $separator);
}
function mysqltimetodate ($timestamp) {
$q = "select date_format('$timestamp','%m/%d/%y')";
$result = mysql_query($q) or print("Error: ".mysql_error()." query was $q");
list ($date) = mysql_fetch_row($result);
return $date;
}
//#############################################################
function resolve_handle($handle) {
$esch = mysql_real_escape_string($handle);
$q = "select ID, TYPE from handles where handle = '$esch'";
$result = mysql_query($q);
list($id, $type) = mysql_fetch_row($result);
return $id;
}
//#############################################################
function output_array($catitems, $format, $num_columns, $column_separator) {
# Set Number of Columns to sensible value if undefined
if (! $num_columns) {
$num_columns = 1;
}
preg_match_all('/\|([^\|]+)\|/', $format, $matches);
$numitems = count($catitems);
$column_width = (int) $numitems / $num_columns; # integer division
$j = 0;
foreach ($catitems as $ref) {
print "<!-- ID: ".$ref['ID'].$ref['id']." -->";
$line = $format;
foreach ($matches[1] as $key) {
$rvalue = $ref[$key];
$line = preg_replace("/\|$key\|/", $rvalue, $line);
}
$line = preg_replace('/\|([^\|]+)\|/','',$line);
print $line;
$j++;
if ((($j % $column_width) == 0) && ($j != 0) && ($numitems - $j >= $column_width)) {
print $column_separator;
}
}
return '';
}
//###################################################################
// returns all subcategories of given category as array of hashes
function get_catitems($curcat, &$items) {
global $ITEM_TABLE;
// return array of hashes w/ID,NAME,VALUE,QUALIFIER
// @$itemref = $obj->find('search'=>$curcat,'by'=>'CID','sort'=>'NAME','filter'=>'ITEMS','multiple');
$q = "select * from $ITEM_TABLE where CID = $curcat order by ENTERED desc";
get_query_results($items, $q);
// values->urls if match
foreach ($items as $key => $val) {
$items[$key]["URL"] = $items[$key]["VALUE"];
$items[$key]["LINK"] = '<A HREF="'.$items[$key]["URL"].'">'.$items[$key]["NAME"].'</A>';
// SOURCE, DATE
$items[$key]["DATE"] = mysqltimetodate($items[$key]["ENTERED"]);
array ($types);
print "Item ".$items[$key]["ID"]." ";
get_types($types, $items[$key]['QUALIFIER']);
if ($types) {
get_type_data($types, $items[$key], $items[$key]["ID"]);
}
}
//TODO use proper URL matching
}
function safe_mailto ($email) {
$parts = preg_split("/\@/",$email);
$jstring = $parts[0]."'+unescape('%40')+'".$parts[1];
$retstring = "<script>document.write('<A HREF=mai'+'lto:$jstring>$jstring</A>');</script>";
print "\n<!-- $retstring -->\n";
return $retstring;
}
function get_types(&$types, $qual) {
print "Checking $qual for types...";
if (preg_match("/TYPES?:([^\s]+)/", $qual, $matches)) {
$types = preg_split("/,/",$matches[1]);
print "Found types from $qual<p>\n";
}
}
function get_type_data(&$types, &$href, $id) {
foreach ($types as $table) {
$q = "select * from $table where ID = $id";
$result = mysql_query($q) or next;
//print("Error: ".mysql_error()." query was $q");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
if ($row) {
foreach($row as $key => $val) {
$href["$table:$key"] = $val;
print("Assigning $val to $table : $key<br>\n");
}
}
mysql_free_result($result);
}
}
function get_query_results(&$href, $q) {
$result = mysql_query($q) or print("Error: ".mysql_error()." query was $q");
while ($row = mysql_fetch_array($result,MYSQL_BOTH)) {
$href[] = $row;
}
mysql_free_result($result);
}
?>