Хранилища Subversion ant

Редакция

Редакция 217 | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS

Редакция Автор № строки Строка
41 alex-w 1
<?php
2
 
198 alex-w 3
/**
4
 * Project:     Ant: sources.list generator
5
 * File:        core.php
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 *
21
 */
22
 
23
 
41 alex-w 24
class Core {
59 alex-w 25
 
217 diffor 26
        function getSourceList($distro,$version,$repos,$dblink) {
219 diffor 27
                // TODO optimize this
28
                if(count($repos)==0) return;
201 diffor 29
                // Fetch settings
59 alex-w 30
                $query =& $dblink->query("SELECT * FROM settings");
31
                $settings = array();
32
                while ($query->fetchInto($setting, DB_FETCHMODE_ASSOC)) {
202 diffor 33
                    $settings[stripslashes($setting["opt"])] = stripslashes($setting["optvalue"]);
59 alex-w 34
                };
202 diffor 35
                // Fetch info about distribution
201 diffor 36
                $query =& $dblink->query("SELECT * FROM version v JOIN distribution d ON d.dist_id=v.dist_id JOIN dtype p ON d.disttype=p.type_id WHERE v.dist_id='$distro' AND v.version_id='$version'");
37
                $query->fetchInto($infodist, DB_FETCHMODE_ASSOC);
219 diffor 38
                // Fetch default repos if not defined
39
                if($repos[0]=="-1") {
40
                    $querydrep =& $dblink->query("SELECT * FROM repository r JOIN ver2rep v ON r.rep_id=v.rep_id JOIN version v2 ON v.ver_id=v2.version_id WHERE r.defaultrep='1' AND v2.version_id='$version'");
41
                    $i=0;
42
                    while ($querydrep->fetchInto($dreps,DB_FETCHMODE_ASSOC)) {
43
                        $repos[$i] = $dreps["rep_id"];
44
                        $i++;
45
                    }
46
                };
47
                if(count($repos)==0) return;
48
                // Processing repos
202 diffor 49
                $porigid = -1; // Previous origin id
203 diffor 50
                for($i=0;$i<count($repos);$i++) {
217 diffor 51
                    $id=$repos[$i];
202 diffor 52
                    // Fetch info about origin and scheme
53
                    $sql =& $dblink->query("SELECT * FROM repository r JOIN ver2rep v ON r.rep_id=v.rep_id JOIN origin o ON o.orig_id=r.orig_id JOIN version v2 ON v.ver_id=v2.version_id JOIN scheme s ON s.scheme_id=r.scheme_id JOIN root r2 ON r2.root_id=r.root_id WHERE r.rep_id=".$id);
54
                    $sql->fetchInto($resinfo, DB_FETCHMODE_ASSOC);
55
                    $repscheme = stripslashes($resinfo["scheme"]);
56
                    // Fetch info about sections
57
                    $querysect =& $dblink->query("SELECT * FROM section s JOIN sect2rep r ON s.sect_id=r.sect_id WHERE r.rep_id='$resinfo[rep_id]'");
58
                    $sections = "";
59
                    while ($querysect->fetchInto($section,DB_FETCHMODE_ASSOC)) {
60
                        $sections .= stripslashes($section["sectname"])." ";
61
                    }
62
                    // Conversion scheme
63
                    $repscheme = str_replace("{TYPE}",stripslashes($infodist["type"]),$repscheme);
64
                    $repscheme = str_replace("{PROTO}",$settings["proto"],$repscheme);
65
                    $repscheme = str_replace("{URL}",$settings["url"],$repscheme);
66
                    $repscheme = str_replace("{REP}",stripslashes($resinfo["repname"]),$repscheme);
67
                    $repscheme = str_replace("{DIST}",stripslashes($infodist["vcodename"]),$repscheme);
68
                    $repscheme = str_replace("{SECT}",$sections,$repscheme);
69
                    $repscheme = str_replace("{ROOT}",stripslashes($resinfo["root_folder"]),$repscheme);
70
                    // Comment if another origin
71
                    if($porigid != $resinfo["orig_id"]) {
203 diffor 72
                        $result .= "### ".$resinfo["origin"]." ( ".$resinfo["desk"]." ) - ".$resinfo["homeurl"]." ###\n";
202 diffor 73
                    }
74
                    $porigid = $resinfo["orig_id"];
75
                    // Result
76
                    $result .= "# ".stripslashes($resinfo["repdescribe"])."\n".$repscheme."\n\n";
77
                }
78
                return $result;
59 alex-w 79
        }
80
 
219 diffor 81
        // For backward compatibility for Modern interface. Current getRepList() crushed his.
204 alex-w 82
        function getRepListLegacy($distro,$version,$dblink) {
83
                $query =& $dblink->query("SELECT * FROM settings");
84
                $settings = array();
85
                while ($query->fetchInto($setting, DB_FETCHMODE_ASSOC)) {
86
                        $settings[stripslashes($setting["opt"])] = stripslashes($setting["optvalue"]);
87
                };
88
                $query =& $dblink->query("SELECT * FROM version v JOIN distribution d ON d.dist_id=v.dist_id JOIN dtype p ON d.disttype=p.type_id WHERE v.dist_id='$distro' AND v.version_id='$version'");
89
                $query->fetchInto($infodist, DB_FETCHMODE_ASSOC);
90
                $query =& $dblink->query("SELECT * FROM repository r JOIN ver2rep v ON r.rep_id=v.rep_id JOIN version v2 ON v.ver_id=v2.version_id JOIN scheme s ON s.scheme_id=r.scheme_id JOIN root r2 ON r2.root_id=r.root_id WHERE v.ver_id='$version' ORDER BY r.rtype_id, r.scheme_id ASC");
91
                while ($query->fetchInto($resinfo, DB_FETCHMODE_ASSOC)) {
92
                        $repscheme = stripslashes($resinfo["scheme"]);
93
 
94
                        $querysect =& $dblink->query("SELECT * FROM section s JOIN sect2rep r ON s.sect_id=r.sect_id WHERE
95
r.rep_id='$resinfo[rep_id]'");
96
                        $sections = "";
97
                        while ($querysect->fetchInto($section,DB_FETCHMODE_ASSOC)) {
98
                                $sections .= stripslashes($section["sectname"])." ";
99
                        }
100
 
101
                        $repscheme = str_replace("{TYPE}",stripslashes($infodist["type"]),$repscheme);
102
                        $repscheme = str_replace("{PROTO}",$settings["proto"],$repscheme);
103
                        $repscheme = str_replace("{URL}",$settings["url"],$repscheme);
104
                        $repscheme = str_replace("{REP}",stripslashes($resinfo["repname"]),$repscheme);
105
                        $repscheme = str_replace("{DIST}",stripslashes($infodist["vcodename"]),$repscheme);
106
                        $repscheme = str_replace("{SECT}",$sections,$repscheme);
107
                        $repscheme = str_replace("{ROOT}",stripslashes($resinfo["root_folder"]),$repscheme);
108
 
109
                        $result .= "# ".stripslashes($resinfo["repdescribe"])."\n".$repscheme."\n\n";
110
                }
111
                return $result;
112
        }
113
 
62 alex-w 114
        function getInfo($message,$dblink){
115
                $answer = array();
116
 
41 alex-w 117
                if (preg_match("/linux/i",$message)) {
62 alex-w 118
                        $dist_id = 0;
119
                        $dist_info = "";
63 alex-w 120
                        $vers_id = 0;
121
                        $vers_info = "";
62 alex-w 122
                        $qd =& $dblink->query("SELECT * FROM distribution");
123
                        while ($qd->fetchInto($res, DB_FETCHMODE_ASSOC)) {
124
                                if (preg_match("/".stripslashes($res["distua"])."/i",$message)) {
125
                                        $dist_id = $res["dist_id"];
126
                                        $dist_info = stripslashes($res["distname"]);
127
                                        $qv =& $dblink->query("SELECT * FROM version WHERE dist_id='$dist_id'");
128
                                        while($qv->fetchInto($rev, DB_FETCHMODE_ASSOC)) {
63 alex-w 129
                                                if (preg_match("/".stripslashes($rev["vcodename"])."/i",$message)) {
130
                                                        $vers_id = $rev["version_id"];
131
                                                        $vers_info = stripslashes($rev["version"])." &#8220;".stripslashes($rev["vname"])."&#8221;";
132
                                                }
62 alex-w 133
                                        }
134
                                }
135
                        }
136
                        $answer[] = "Linux";
137
                        $answer[] = "Судя по всему у Вас операционная система ";
138
                        if ($dist_id!=0) {
139
                                $answer[] = $dist_id;
140
                                $answer[] = $dist_info;
141
                        }
142
                        if ($vers_id!=0) {
143
                                $answer[] = $vers_id;
144
                                $answer[] = $vers_info;
145
                        }
146
 
41 alex-w 147
                } else {
62 alex-w 148
                        $answer[] = "unknown";
149
                        $answer[] = "Ресурс рассчитан явно не на Вашу операционную систему!";
41 alex-w 150
                }
62 alex-w 151
 
42 alex-w 152
                return $answer;
153
        }
70 alex-w 154
 
155
        function getInterfacesList($current,$dblink) {
156
                $url  = parse_url($current);
157
                $path = array();
158
                $path = split("/",$url["path"]);
159
                $currentIF = str_replace(".php","",$path[count($path)-1]);
160
                $req =& $dblink->query("SELECT * FROM interfaces WHERE interface NOT LIKE '$currentIF'");
74 alex-w 161
                $iflist = "<a href='./'>Интерфейсы</a>: ";
70 alex-w 162
                while ($req->fetchInto($if, DB_FETCHMODE_ASSOC)) {
163
                        $iflist .= "<a href='./".stripslashes($if["interface"]).".php'>".strtolower(stripslashes($if["interfaceinfo"]))."</a>, ";
164
                }
165
                $iflist = substr($iflist, 0, strlen($iflist)-2);
166
                return $iflist;
167
        }
79 alex-w 168
 
169
        function getCSSList($dblink) {
170
                $req =& $dblink->query("SELECT * FROM distribution");
171
                if ($req->numRows()>0) {
83 alex-w 172
                        $css = "<style type=\"text/css\">\n";
79 alex-w 173
                        while ($req->fetchInto($dist, DB_FETCHMODE_ASSOC)) {
174
                                if ($dist["distlogo"]) {
83 alex-w 175
                                        $css .= ".".stripslashes($dist["distua"])." { display: inline; padding-left: 15px; background: transparent url(./img/logo/".stripslashes($dist["distua"]).".png) top left no-repeat; }\n";
176
                                        $css .= ".".stripslashes($dist["distua"])."-em { display: inline; padding-left: 30px; background: transparent url(./img/logo/".stripslashes($dist["distua"])."-em.png) top left no-repeat; }\n";
79 alex-w 177
                                } else {
178
                                        $css .= "";
179
                                }
180
                        }
83 alex-w 181
                        $css .= "</style>";
79 alex-w 182
                } else {
183
                        $css = "";
184
                }
185
                return $css;
186
        }
132 alex-w 187
 
133 alex-w 188
        function getSetting($setting, $dblink) {
132 alex-w 189
                $query =& $dblink->query("SELECT * FROM settings WHERE opt LIKE '".$setting."'");
190
                $query->fetchInto($sett, DB_FETCHMODE_ASSOC);
191
                return stripslashes($sett["optvalue"]);
192
        }
138 alex-w 193
 
194
        function getUUID($param) {
195
                $param_s = md5($param);
196
                $time_low = bin2hex(substr($param_s,0, 4));
197
                $time_mid = bin2hex(substr($param_s,4, 2));
198
                $time_hi_and_version = bin2hex(substr($param_s,6, 2));
199
                $clock_seq_hi_and_reserved = bin2hex(substr($param_s,8, 2));
200
                $node = bin2hex(substr($param_s,10, 6));
201
 
202
                $time_hi_and_version = hexdec($time_hi_and_version);
203
                $time_hi_and_version = $time_hi_and_version >> 4;
204
                $time_hi_and_version = $time_hi_and_version | 0x4000;
205
 
206
                $clock_seq_hi_and_reserved = hexdec($clock_seq_hi_and_reserved);
207
                $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved >> 2;
208
                $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved | 0x8000;
209
 
210
                return sprintf('%08s-%04s-%04x-%04x-%012s',$time_low, $time_mid, $time_hi_and_version, $clock_seq_hi_and_reserved, $node);
211
        }
41 alex-w 212
 
192 sivan 213
 
217 diffor 214
    function getRepList($distro,$version,$dblink) {
203 diffor 215
        $query =& $dblink->query("SELECT * FROM repository r JOIN ver2rep v ON r.rep_id=v.rep_id JOIN origin o ON o.orig_id=r.orig_id JOIN version v2 ON v.ver_id=v2.version_id JOIN scheme s ON s.scheme_id=r.scheme_id JOIN root r2 ON r2.root_id=r.root_id WHERE v.ver_id='$version' ORDER BY r.rtype_id, r.scheme_id ASC");
217 diffor 216
        $i=-1;
203 diffor 217
        while ($query->fetchInto($resinfo, DB_FETCHMODE_ASSOC)) {
217 diffor 218
            $i++;
219
            $res[0][$i]=$resinfo["rep_id"];
220
            $res[1][$i]=$resinfo["repname"];
221
            $res[2][$i]=$resinfo["repdescribe"];
222
            $res[3][$i]=$resinfo["defaultrep"];
203 diffor 223
        }
217 diffor 224
        return $res;
192 sivan 225
    }
203 diffor 226
}
41 alex-w 227
?>