Редакция 204 |
Редакция 207 |
К новейшей редакции |
Авторство |
Сравнить с предыдущей |
Последнее изменение |
Открыть журнал
| Скачать
| RSS
<?php
/**
* Project: Ant: sources.list generator
* File: core.php
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
class Core
{
function getRepList
($distro,$version,$dblink) {
// Fetch settings
$query =& $dblink->query("SELECT * FROM settings");
$settings = array();
while ($query->fetchInto($setting, DB_FETCHMODE_ASSOC
)) {
$settings[stripslashes($setting["opt"])] = stripslashes($setting["optvalue"]);
};
// Fetch info about distribution
$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'");
$query->fetchInto($infodist, DB_FETCHMODE_ASSOC
);
// Fetch repos
$repos=$_GET["r"];
$porigid = -1; // Previous origin id
for($i=0;$i<count($repos);$i++) {
$id=$_GET["r"][$i];
// Fetch info about origin and scheme
$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);
$sql->fetchInto($resinfo, DB_FETCHMODE_ASSOC
);
$repscheme = stripslashes($resinfo["scheme"]);
// Fetch info about sections
$querysect =& $dblink->query("SELECT * FROM section s JOIN sect2rep r ON s.sect_id=r.sect_id WHERE r.rep_id='$resinfo[rep_id]'");
$sections = "";
while ($querysect->fetchInto($section,DB_FETCHMODE_ASSOC
)) {
$sections .= stripslashes($section["sectname"])." ";
}
// Conversion scheme
$repscheme = str_replace("{TYPE}",stripslashes($infodist["type"]),$repscheme);
$repscheme = str_replace("{PROTO}",$settings["proto"],$repscheme);
$repscheme = str_replace("{URL}",$settings["url"],$repscheme);
$repscheme = str_replace("{REP}",stripslashes($resinfo["repname"]),$repscheme);
$repscheme = str_replace("{DIST}",stripslashes($infodist["vcodename"]),$repscheme);
$repscheme = str_replace("{SECT}",$sections,$repscheme);
$repscheme = str_replace("{ROOT}",stripslashes($resinfo["root_folder"]),$repscheme);
// Comment if another origin
if($porigid != $resinfo["orig_id"]) {
$result .= "### ".$resinfo["origin"]." ( ".$resinfo["desk"]." ) - ".$resinfo["homeurl"]." ###\n";
}
$porigid = $resinfo["orig_id"];
// Result
$result .= "# ".stripslashes($resinfo["repdescribe"])."\n".$repscheme."\n\n";
}
return $result;
}
// For backward compatibility for Modern and Telepathy interfaces. Current getRepList() crushed his.
function getRepListLegacy
($distro,$version,$dblink) {
$query =& $dblink->query("SELECT * FROM settings");
$settings = array();
while ($query->fetchInto($setting, DB_FETCHMODE_ASSOC
)) {
$settings[stripslashes($setting["opt"])] = stripslashes($setting["optvalue"]);
};
$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'");
$query->fetchInto($infodist, DB_FETCHMODE_ASSOC
);
$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");
while ($query->fetchInto($resinfo, DB_FETCHMODE_ASSOC
)) {
$repscheme = stripslashes($resinfo["scheme"]);
$querysect =& $dblink->query("SELECT * FROM section s JOIN sect2rep r ON s.sect_id=r.sect_id WHERE
r.rep_id='$resinfo[rep_id]'");
$sections = "";
while ($querysect->fetchInto($section,DB_FETCHMODE_ASSOC
)) {
$sections .= stripslashes($section["sectname"])." ";
}
$repscheme = str_replace("{TYPE}",stripslashes($infodist["type"]),$repscheme);
$repscheme = str_replace("{PROTO}",$settings["proto"],$repscheme);
$repscheme = str_replace("{URL}",$settings["url"],$repscheme);
$repscheme = str_replace("{REP}",stripslashes($resinfo["repname"]),$repscheme);
$repscheme = str_replace("{DIST}",stripslashes($infodist["vcodename"]),$repscheme);
$repscheme = str_replace("{SECT}",$sections,$repscheme);
$repscheme = str_replace("{ROOT}",stripslashes($resinfo["root_folder"]),$repscheme);
$result .= "# ".stripslashes($resinfo["repdescribe"])."\n".$repscheme."\n\n";
}
return $result;
}
function getInfo
($message,$dblink){
$answer = array();
if (preg_match("/linux/i",$message)) {
$dist_id = 0;
$dist_info = "";
$vers_id = 0;
$vers_info = "";
$qd =& $dblink->query("SELECT * FROM distribution");
while ($qd->fetchInto($res, DB_FETCHMODE_ASSOC
)) {
if (preg_match("/".stripslashes($res["distua"])."/i",$message)) {
$dist_id = $res["dist_id"];
$dist_info = stripslashes($res["distname"]);
$qv =& $dblink->query("SELECT * FROM version WHERE dist_id='$dist_id'");
while($qv->fetchInto($rev, DB_FETCHMODE_ASSOC
)) {
if (preg_match("/".stripslashes($rev["vcodename"])."/i",$message)) {
$vers_id = $rev["version_id"];
$vers_info = stripslashes($rev["version"])." “".stripslashes($rev["vname"])."”";
}
}
}
}
$answer[] = "Linux";
$answer[] = "Судя по всему у Вас операционная система ";
if ($dist_id!=0) {
$answer[] = $dist_id;
$answer[] = $dist_info;
}
if ($vers_id!=0) {
$answer[] = $vers_id;
$answer[] = $vers_info;
}
} else {
$answer[] = "unknown";
$answer[] = "Ресурс рассчитан явно не на Вашу операционную систему!";
}
return $answer;
}
function getInterfacesList
($current,$dblink) {
$url = parse_url($current);
$path = array();
$path = split("/",$url["path"]);
$currentIF = str_replace(".php","",$path[count($path)-1]);
$req =& $dblink->query("SELECT * FROM interfaces WHERE interface NOT LIKE '$currentIF'");
$iflist = "<a href='./'>Интерфейсы</a>: ";
while ($req->fetchInto($if, DB_FETCHMODE_ASSOC
)) {
$iflist .= "<a href='./".stripslashes($if["interface"]).".php'>".strtolower(stripslashes($if["interfaceinfo"]))."</a>, ";
}
$iflist = substr($iflist, 0, strlen($iflist)-2);
return $iflist;
}
function getCSSList
($dblink) {
$req =& $dblink->query("SELECT * FROM distribution");
if ($req->numRows()>0) {
$css = "<style type=\"text/css\">\n";
while ($req->fetchInto($dist, DB_FETCHMODE_ASSOC
)) {
if ($dist["distlogo"]) {
$css .= ".".stripslashes($dist["distua"])." { display: inline; padding-left: 15px; background: transparent url(./img/logo/".stripslashes($dist["distua"]).".png) top left no-repeat; }\n";
$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";
} else {
$css .= "";
}
}
$css .= "</style>";
} else {
$css = "";
}
return $css;
}
function getSetting
($setting, $dblink) {
$query =& $dblink->query("SELECT * FROM settings WHERE opt LIKE '".$setting."'");
$query->fetchInto($sett, DB_FETCHMODE_ASSOC
);
return stripslashes($sett["optvalue"]);
}
function getUUID
($param) {
$param_s = md5($param);
$time_low = bin2hex(substr($param_s,0, 4));
$time_mid = bin2hex(substr($param_s,4, 2));
$time_hi_and_version = bin2hex(substr($param_s,6, 2));
$clock_seq_hi_and_reserved = bin2hex(substr($param_s,8, 2));
$node = bin2hex(substr($param_s,10, 6));
$time_hi_and_version = hexdec($time_hi_and_version);
$time_hi_and_version = $time_hi_and_version >> 4;
$time_hi_and_version = $time_hi_and_version | 0x4000;
$clock_seq_hi_and_reserved = hexdec($clock_seq_hi_and_reserved);
$clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved >> 2;
$clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved | 0x8000;
return sprintf('%08s-%04s-%04x-%04x-%012s',$time_low, $time_mid, $time_hi_and_version, $clock_seq_hi_and_reserved, $node);
}
function getAddsRepList
($distro,$version,$dblink) {
$query =& $dblink->query("SELECT * FROM settings");
$settings = array();
while ($query->fetchInto($setting, DB_FETCHMODE_ASSOC
)) {
$settings[stripslashes($setting["opt"])] = stripslashes($setting["optvalue"]);
};
$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'");
$query->fetchInto($infodist, DB_FETCHMODE_ASSOC
);
$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");
$result.="<input type='hidden' name='d' value='".$_GET["d"]."'><input type='hidden' name='v' value='".$_GET["v"]."'>";
$tmp=0;
while ($query->fetchInto($resinfo, DB_FETCHMODE_ASSOC
)) {
$tmp++;
if ($resinfo["rtype_id"]!=3){$ch="checked";} else{$ch="";} // Default reps hack, replace in future
$result.="<input type='checkbox' name='r[]' ".$ch." value='".$resinfo["rep_id"]."'>".$resinfo["repname"]." <em>(".$resinfo["repdescribe"].")</em><br>";
}
return $result;
}
}
?>