summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--all.php2
-rw-r--r--autocompleter.php2
-rw-r--r--class/CommonTable.php327
-rw-r--r--class/FedoraClient.php114
-rw-r--r--class/FedoraPkgdb.php150
-rw-r--r--class/TableIterator.php286
-rw-r--r--class/TablePearRepo.php136
-rw-r--r--class/TableRRepo.php123
-rwxr-xr-xfedcli.php5
-rw-r--r--include/config.php7
-rw-r--r--include/config.php.dist (renamed from config.inc.php.dist)0
-rw-r--r--include/main.php (renamed from main.inc.php)39
-rw-r--r--index.php4
-rw-r--r--pkgdb-ajax.php4
-rw-r--r--refresh.php45
-rw-r--r--rpm.php2
-rw-r--r--scripts/rpmphp.js2
-rw-r--r--smarty/templates/rpmphp/zoom.tpl4
-rw-r--r--zoom.php4
20 files changed, 770 insertions, 488 deletions
diff --git a/.gitignore b/.gitignore
index ad5b253..d96c607 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-config.inc.php
+include/config.php
*.gz
.sendate
sendbox
diff --git a/all.php b/all.php
index cfaa524..8e42e46 100644
--- a/all.php
+++ b/all.php
@@ -34,7 +34,7 @@
* @link http://github.com/remicollet/rpmphp/
* @since The begining of times.
*/
-require 'main.inc.php';
+require 'include/main.php';
$what=(isset($_GET["what"]) ? $_GET["what"] : false);
$ariane[] = array(
diff --git a/autocompleter.php b/autocompleter.php
index e693e9a..2acb21e 100644
--- a/autocompleter.php
+++ b/autocompleter.php
@@ -34,7 +34,7 @@
* @link http://github.com/remicollet/rpmphp/
* @since The begining of times.
*/
-require 'main.inc.php';
+require 'include/main.php';
$q = null;
$limit = null;
diff --git a/class/CommonTable.php b/class/CommonTable.php
index 261c7aa..8fd0471 100644
--- a/class/CommonTable.php
+++ b/class/CommonTable.php
@@ -81,7 +81,7 @@ abstract class CommonTable
$res = $this->db->exec($sql);
if ($res===false) {
$err = $this->db->errorInfo();
- throw new Exception($err[2]);
+ throw new Exception("\nSQL: $sql\nERROR: ".$err[2]."\nCODE:");
}
return $res;
}
@@ -145,6 +145,7 @@ abstract class CommonTable
return $nb;
}
+
/**
* Create the table
*/
@@ -193,333 +194,37 @@ abstract class CommonTable
*
* @param string $fieldkey name of the field to use as index
* @param string $fieldvalue name of the field to use as value
+ * @param array $crit for request
*
* @return hashtable
*/
- public function getAllArray($fieldkey, $fieldvalue)
+ public function getHashtable($fieldkey, $fieldvalue, array $crit=array())
{
- $crit = array('FIELDS' => array($fieldkey, $fieldvalue),
- 'ORDER' => $fieldkey);
+ $crit['FIELDS'] = array($fieldkey, $fieldvalue);
+ $crit['ORDER'] = $fieldkey;
+
$tab = array();
foreach ($this->request($crit) as $data) {
$tab[$data[$fieldkey]] = $data[$fieldvalue];
}
return $tab;
}
-}
-
-class TablePearRepo extends CommonTable
-{
/**
- * Instanciate a TablePearRepo to manage pearrepo table
+ * Retrieve a big array with all date from the table
*
- * @param object $db PDO instance of the DB connection
- */
- function __construct($db)
- {
- parent::__construct($db, 'pearrepo');
- }
-
- /**
- * Create the table and populate it with known repo
+ * @param array|string $crit for the request
*
- * @return void
+ * @return array, index is rowid, value is a hastable
*/
- protected function createTable()
+ public function getArray($crit='')
{
-
- // Table schema
- $sql = "CREATE TABLE `pearrepo` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `alias` varchar(30) NOT NULL,
- `url` varchar(255) NOT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `alias` (`alias`)
- ) DEFAULT CHARSET=utf8";
-
- $this->exec($sql);
-
- // Some known repo, other could be add manually
- // no reply from "phpdb" => "pear.phpdb.org"
- $channels = array(
- "pear" => "pear.php.net"
- ,"doctrine" => "pear.phpdoctrine.org"
- ,"ezc" => "components.ez.no"
- ,"pdepend" => "pear.pdepend.org"
- ,"phing" => "pear.phing.info"
- ,"phpmd" => "pear.phpmd.org"
- ,"phpunit" => "pear.phpunit.de"
- ,"swift" => "pear.swiftmailer.org"
- ,"symphony" => "pear.symfony-project.com"
- );
-
- foreach ($channels as $alias => $url) {
- $this->add(array('alias'=>$alias, 'url'=>$url));
+ $tab = array();
+ foreach ($this->request($crit) as $id => $data) {
+ $tab[$id] = $data;
}
- }
-
- /**
- * Retrieve all the known repository
- *
- * @return hastable of alias => url
- */
- function getAllRepo()
- {
- return $this->getAllArray('alias', 'url');
+ return $tab;
}
}
-/**
- * Helper for simple query => use directly or through CommonTable::request()
- *
- * Freely inspired from DBmysqlIterator class from GLPI
- * (already written by Remi, and ported to PDO)
- * See http://www.glpi-project.org/
- */
-class TableIterator implements Iterator
-{
- private $con;
- private $sql;
- private $res = false;
- private $row;
- private $pos;
-
- /**
- * Constructor
- *
- * @param CommonDBTM $dbconnexion Database Connnexion
- * (must be a CommonDBTM object)
- * @param string $table table name
- * @param string|array $crit string or array of filed/values,
- * ex array("id"=>1), if empty => all rows
- */
- function __construct (PDO $dbconnexion, $table, $crit='')
- {
-
- $this->conn = $dbconnexion;
- if (is_string($table) && strpos($table, " ")) {
- $this->sql = $table;
- } else {
- // check field, orderby, limit, start in criterias
- $field="";
- $orderby="";
- $limit=0;
- $start=0;
-
- if (is_array($crit) && count($crit)) {
- foreach ($crit as $key => $val) {
- if ($key==="FIELDS") {
- $field = $val;
- unset($crit[$key]);
- } else if ($key==="ORDER") {
- $orderby = $val;
- unset($crit[$key]);
- } else if ($key==="LIMIT") {
- $limit = $val;
- unset($crit[$key]);
- } else if ($key==="START") {
- $start = $val;
- unset($crit[$key]);
- }
- }
- }
-
- // SELECT field list
- if (is_array($field)) {
- $this->sql = "";
- foreach ($field as $t => $f) {
- if (is_numeric($t)) {
- $this->sql .= (empty($this->sql)
- ? "SELECT " : ",") . $f;
- } else if (is_array($f)) {
- $this->sql .= (empty($this->sql)
- ? "SELECT $t." : ",$t.") . implode(",$t.", $f);
- } else {
- $this->sql .= (empty($this->sql)
- ? "SELECT " : ",") . "$t.$f";
- }
- }
- } else if (empty($field)) {
- $this->sql = "SELECT *";
- } else {
- $this->sql = "SELECT `$field`";
- }
- // FROM table list
- if (is_array($table)) {
- $this->sql .= " FROM `".implode("`, `", $table)."`";
- } else {
- $this->sql .= " FROM `$table`";
- }
- // WHERE criteria list
- if (!empty($crit)) {
- print_r($crit);
- $this->sql .= " WHERE ".$this->_analyseCrit($crit);
- }
- // ORDER BY
- if (is_array($orderby)) {
- $this->sql .= " ORDER BY `".implode("`, `", $orderby)."`";
- } else if (!empty($orderby)) {
- $this->sql .= " ORDER BY `$orderby`";
- }
- if (is_numeric($limit) && $limit>0) {
- $this->sql .= " LIMIT $limit";
- if (is_numeric($start) && $start>0) {
- $this->sql .= " OFFSET $start";
- }
- }
- }
- //echo "SQL: ".$this->sql."\n";
- $this->res = $this->conn->prepare($this->sql);
- if ($this->res===false) {
- $err = $this->db->errorInfo();
- throw new Exception($err[2]);
- }
-
- $this->pos = -1;
- }
-
- /**
- * Class destructor
- */
- function __destruct ()
- {
- if ($this->res) {
- $this->res->closeCursor();
- }
- }
-
- /**
- * Build WHERE clause
- *
- * @param TODO $crit To document
- * @param TODO $bool To document
- *
- * @return To document
- */
- private function _analyseCrit ($crit, $bool="AND")
- {
-
- if (!is_array($crit)) {
- return $crit;
- }
- $ret = "";
- foreach ($crit as $name => $value) {
- if (!empty($ret)) {
- $ret .= " $bool ";
- }
- if (is_numeric($name)) {
- // No Key case => recurse.
- $ret .= "(" . $this->_analyseCrit($value, $bool) . ")";
- } else if ($name==="OR" || $name==="AND") {
- // Binary logical operator
- $ret .= "(" . $this->_analyseCrit($value, $name) . ")";
- } else if ($name==="NOT") {
- // Uninary logicial operator
- $ret .= " NOT (" . $this->_analyseCrit($value, "AND") . ")";
- } else if ($name==="FKEY") {
- // Foreign Key condition
- if (is_array($value) && count($value)==2) {
- reset($value);
- list($t1,$f1)=each($value);
- list($t2,$f2)=each($value);
- $ret .= (is_numeric($t1) ? "$f1" : "$t1.$f1") . "=" .
- (is_numeric($t2) ? "$f2" : "$t2.$f2");
- } else {
- trigger_error("BAD FOREIGN KEY", E_USER_ERROR);
- }
- } else if (is_array($value)) {
- // Array of Value
- $ret .= "$name IN ('". implode("','", $value)."')";
- } else if (is_null($value)) {
- // NULL condition
- $ret .= "$name IS NULL";
- } else if (is_numeric($value)) {
- // Integer
- $ret .= "$name=$value";
- } else {
- // String
- $ret .= "$name='$value'";
- }
- }
- return $ret;
- }
-
- /**
- * To document
- *
- * @return To document
- */
- public function rewind ()
- {
-
- if ($this->res && $this->pos>=0) {
- $this->res->closeCursor();
- $this->pos = -1;
- }
-
- if ($this->res && $this->pos<0) {
- if (!$this->res->execute()) {
- $err = $this->res->errorInfo();
- throw new Exception($err[2]);
- }
- }
- return $this->next();
- }
-
- /**
- * To document
- *
- * @return To document
- */
- public function current()
- {
- return $this->row;
- }
-
- /**
- * To document
- *
- * @return To document
- */
- public function key()
- {
- return (isset($this->row["id"]) ? $this->row["id"] : $this->pos);
- }
-
- /**
- * To document
- *
- * @return To document
- */
- public function next()
- {
- if (!$this->res) {
- return false;
- }
- $this->row = $this->res->fetch(PDO::FETCH_ASSOC);
- $this->pos++;
- return $this->row;
- }
-
- /**
- * To document
- *
- * @return To document
- */
- public function valid()
- {
- return $this->res && $this->row;
- }
-
- /**
- * To document
- *
- * @return To document
- */
- public function numrows()
- {
- return ($this->res ? $this->res->rowCount() : 0);
- }
-}
-?>
+?> \ No newline at end of file
diff --git a/class/FedoraClient.php b/class/FedoraClient.php
index 43d9dce..f1ce8f6 100644
--- a/class/FedoraClient.php
+++ b/class/FedoraClient.php
@@ -35,8 +35,6 @@
* @since The begining of times.
*/
-define('FEDORACLIENT_VERSION', '0.1.0-dev');
-
if (!function_exists('curl_version')) {
die("curl extension required\n");
}
@@ -44,7 +42,8 @@ require_once 'Cache/Lite.php';
abstract class FedoraClient
{
- private $url;
+ const VERSION='0.1.0-dev';
+ protected $url;
private $agent;
private $debug = 0;
protected $cache;
@@ -65,7 +64,7 @@ abstract class FedoraClient
if (isset($options['agent']) && !empty($options['agent'])) {
$this->agent = $options['agent'];
} else {
- $this->agent = 'Fedora PHPClient/'.FEDORACLIENT_VERSION;
+ $this->agent = 'Fedora PHPClient/'.self::VERSION;
}
if (isset($options['debug']) && intval($options['debug'])>0) {
$this->debug = intval($options['debug']);
@@ -161,109 +160,4 @@ abstract class FedoraClient
}
}
-
-class FedoraPkgdb extends FedoraClient
-{
-
- function __construct (array $options=array())
- {
- parent::__construct('https://admin.fedoraproject.org/pkgdb/', $options);
- $this->logDebug(
- 3,
- __CLASS__."::".__FUNCTION__
- );
- }
-
- function getBranches($refresh=false)
- {
- $rep = ($refresh ? false : $this->cache->get(__FUNCTION__, __CLASS__));
- if ($rep) {
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."() get from cache"
- );
- } else {
- $rep =$this->sendRequest('collections');
- $this->cache->save($rep, __FUNCTION__, __CLASS__);
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."() save to cache"
- );
- }
-
- $branches = array();
- if (isset($rep['collections'])) {
- foreach ($rep['collections'] as $coll) {
- if (isset($coll[0]['branchname'])) {
- $branches[$coll[0]['branchname']] = $coll[0];
- }
- }
- }
- return $branches;
- }
-
- function getPackageInfo($name, $refresh=false)
- {
- $url="acls/name/$name";
- $rep = ($refresh ? false : $this->cache->get($url, __CLASS__));
- if ($rep) {
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."($name) get from cache"
- );
- } else {
- $rep =$this->sendRequest($url);
- $this->cache->save($rep, $url, __CLASS__);
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."($name) save to cache"
- );
- }
-
- if (isset($rep['status']) && !$rep['status']) {
- $this->logDebug(
- 1,
- __CLASS__."::".__FUNCTION__."($name) ".$rep['message']
- );
- return false;
- }
- $this->logDebug(8,print_r($rep,true));
- $branches = array();
- foreach ($rep['packageListings'] as $pack) {
- $branches[$pack['collection']['branchname']] = $pack;
- }
- $this->logDebug(7,print_r($branches,true));
- return $branches;
- }
-
- function getBranch($name, $refresh=false)
- {
- $branches = $this->getBranches($refresh);
-
- if (isset($branches[$name])) {
- return $branches[$name];
- }
- return false;
- }
-
- function getCritPath($refresh=false)
- {
- $url="lists/critpath";
- $rep = ($refresh ? false : $this->cache->get($url, __CLASS__));
- if ($rep) {
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__." get from cache"
- );
- } else {
- $rep =$this->sendRequest($url);
- $this->cache->save($rep, $url, __CLASS__);
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__." save to cache"
- );
- }
- return $rep['pkgs'];
- }
-}
-?>
+?> \ No newline at end of file
diff --git a/class/FedoraPkgdb.php b/class/FedoraPkgdb.php
new file mode 100644
index 0000000..d170911
--- /dev/null
+++ b/class/FedoraPkgdb.php
@@ -0,0 +1,150 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * FedoraClient is a PHP class to interact with web services
+ *
+ * PHP version 5
+ *
+ * Copyright (C) 2010 Remi Collet
+ * http://github.com/remicollet/rpmphp.
+ *
+ * Inspired from python-fedora
+ *
+ * FedoraClient 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.
+ *
+ * FedoraClient 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.
+ *
+ * See <http://www.gnu.org/licenses/>
+ *
+ * @category Main
+ * @package FedoraClient
+ *
+ * @author Remi Collet <unknown@unknwown.com>
+ * @author Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2010 Remi Collet
+ * @license http://www.gnu.org/licenses/lgpl-2.1.txt LGPL License 2.1 or (at your option) any later version
+ * @link http://github.com/remicollet/rpmphp/
+ * @since The begining of times.
+ */
+
+class FedoraPkgdb extends FedoraClient
+{
+ private $suburl;
+
+ function __construct (array $options=array())
+ {
+ parent::__construct('https://admin.fedoraproject.org/pkgdb/', $options);
+ $this->suburl = 'acls/name/';
+
+ $this->logDebug(
+ 3,
+ __CLASS__."::".__FUNCTION__
+ );
+ }
+
+ function getBranches($refresh=false)
+ {
+ $rep = ($refresh ? false : $this->cache->get(__FUNCTION__, __CLASS__));
+ if ($rep) {
+ $this->logDebug(
+ 2,
+ __CLASS__."::".__FUNCTION__."() get from cache"
+ );
+ } else {
+ $rep =$this->sendRequest('collections');
+ $this->cache->save($rep, __FUNCTION__, __CLASS__);
+ $this->logDebug(
+ 2,
+ __CLASS__."::".__FUNCTION__."() save to cache"
+ );
+ }
+
+ $branches = array();
+ if (isset($rep['collections'])) {
+ foreach ($rep['collections'] as $coll) {
+ if (isset($coll[0]['branchname'])) {
+ $branches[$coll[0]['branchname']] = $coll[0];
+ }
+ }
+ }
+ return $branches;
+ }
+
+ function getPackageURL($name)
+ {
+ return $this->url.$this->suburl.$name;
+ }
+
+ function getPackageInfo($name, $refresh=false)
+ {
+ $url=$this->suburl.urlencode($name);
+ $rep = ($refresh ? false : $this->cache->get($url, __CLASS__));
+ if ($rep) {
+ $this->logDebug(
+ 2,
+ __CLASS__."::".__FUNCTION__."($name) get from cache"
+ );
+ } else {
+ $rep =$this->sendRequest($url);
+ $this->cache->save($rep, $url, __CLASS__);
+ $this->logDebug(
+ 2,
+ __CLASS__."::".__FUNCTION__."($name) save to cache"
+ );
+ }
+
+ if (isset($rep['status']) && !$rep['status']) {
+ $this->logDebug(
+ 1,
+ __CLASS__."::".__FUNCTION__."($name) ".$rep['message']
+ );
+ return false;
+ }
+ $this->logDebug(8,print_r($rep,true));
+ $branches = array();
+ foreach ($rep['packageListings'] as $pack) {
+ $branches[$pack['collection']['branchname']] = $pack;
+ }
+ $this->logDebug(7,print_r($branches,true));
+ return $branches;
+ }
+
+ function getBranch($name, $refresh=false)
+ {
+ $branches = $this->getBranches($refresh);
+
+ if (isset($branches[$name])) {
+ return $branches[$name];
+ }
+ return false;
+ }
+
+ function getCritPath($refresh=false)
+ {
+ $url="lists/critpath";
+ $rep = ($refresh ? false : $this->cache->get($url, __CLASS__));
+ if ($rep) {
+ $this->logDebug(
+ 2,
+ __CLASS__."::".__FUNCTION__." get from cache"
+ );
+ } else {
+ $rep =$this->sendRequest($url);
+ $this->cache->save($rep, $url, __CLASS__);
+ $this->logDebug(
+ 2,
+ __CLASS__."::".__FUNCTION__." save to cache"
+ );
+ }
+ return $rep['pkgs'];
+ }
+}
+?> \ No newline at end of file
diff --git a/class/TableIterator.php b/class/TableIterator.php
new file mode 100644
index 0000000..0903f37
--- /dev/null
+++ b/class/TableIterator.php
@@ -0,0 +1,286 @@
+<?php
+/**
+ * Class which implement a simple Iterator over a PDO connexion
+ *
+ * PHP version 5
+ *
+ * Copyright © 2010 Remi Collet
+ *
+ * This file is part of rpmphp.
+ *
+ * rpmphp is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * rpmphp 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with rpmphp. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Main
+ * @package RPMPHP
+ *
+ * @author Remi Collet <unknown@unknwown.com>
+ * @author Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2010 Remi Collet
+ * @license http://www.gnu.org/licenses/agpl-3.0-standalone.html AGPL License 3.0 or (at your option) any later version
+ * @link http://github.com/remicollet/rpmphp/
+ * @since The begining of times.
+*/
+
+/**
+ * Helper for simple query => use directly or through CommonTable::request()
+ *
+ * Freely inspired from DBmysqlIterator class from GLPI
+ * (already written by Remi, and ported to PDO)
+ * See http://www.glpi-project.org/
+ */
+class TableIterator implements Iterator
+{
+ private $con;
+ private $sql;
+ private $res = false;
+ private $row;
+ private $pos;
+
+ /**
+ * Constructor
+ *
+ * @param CommonDBTM $dbconnexion Database Connnexion
+ * (must be a CommonDBTM object)
+ * @param string $table table name or complete SQL request
+ * @param string|array $crit string or array of filed/values,
+ * ex array("id"=>1), if empty => all rows
+ */
+ function __construct (PDO $dbconnexion, $table, $crit='')
+ {
+
+ $this->conn = $dbconnexion;
+ if (is_string($table) && strpos($table, " ")) {
+ $this->sql = $table;
+ } else {
+ // check field, orderby, limit, start in criterias
+ $field="";
+ $orderby="";
+ $limit=0;
+ $start=0;
+
+ if (is_array($crit) && count($crit)) {
+ foreach ($crit as $key => $val) {
+ if ($key==="FIELDS") {
+ $field = $val;
+ unset($crit[$key]);
+ } else if ($key==="ORDER") {
+ $orderby = $val;
+ unset($crit[$key]);
+ } else if ($key==="LIMIT") {
+ $limit = $val;
+ unset($crit[$key]);
+ } else if ($key==="START") {
+ $start = $val;
+ unset($crit[$key]);
+ }
+ }
+ }
+
+ // SELECT field list
+ if (is_array($field)) {
+ $this->sql = "";
+ foreach ($field as $t => $f) {
+ if (is_numeric($t)) {
+ $this->sql .= (empty($this->sql)
+ ? "SELECT " : ",") . $f;
+ } else if (is_array($f)) {
+ $this->sql .= (empty($this->sql)
+ ? "SELECT $t." : ",$t.") . implode(",$t.", $f);
+ } else {
+ $this->sql .= (empty($this->sql)
+ ? "SELECT " : ",") . "$t.$f";
+ }
+ }
+ } else if (empty($field)) {
+ $this->sql = "SELECT *";
+ } else {
+ $this->sql = "SELECT `$field`";
+ }
+ // FROM table list
+ if (is_array($table)) {
+ $this->sql .= " FROM `".implode("`, `", $table)."`";
+ } else {
+ $this->sql .= " FROM `$table`";
+ }
+ // WHERE criteria list
+ if (!empty($crit)) {
+ $this->sql .= " WHERE ".$this->_analyseCrit($crit);
+ }
+ // ORDER BY
+ if (is_array($orderby)) {
+ $this->sql .= " ORDER BY `".implode("`, `", $orderby)."`";
+ } else if (!empty($orderby)) {
+ $this->sql .= " ORDER BY `$orderby`";
+ }
+ if (is_numeric($limit) && $limit>0) {
+ $this->sql .= " LIMIT $limit";
+ if (is_numeric($start) && $start>0) {
+ $this->sql .= " OFFSET $start";
+ }
+ }
+ }
+ //echo "SQL: ".$this->sql."\n";
+ $this->res = $this->conn->prepare($this->sql);
+ if ($this->res===false) {
+ $err = $this->db->errorInfo();
+ throw new Exception($err[2]);
+ }
+
+ $this->pos = -1;
+ }
+
+ /**
+ * Class destructor
+ */
+ function __destruct ()
+ {
+ if ($this->res) {
+ $this->res->closeCursor();
+ }
+ }
+
+ /**
+ * Build WHERE clause
+ *
+ * @param string|array $crit To document
+ * @param string $bool logical operator between criteria
+ *
+ * @return To document
+ */
+ private function _analyseCrit ($crit, $bool="AND")
+ {
+
+ if (!is_array($crit)) {
+ return $crit;
+ }
+ $ret = "";
+ foreach ($crit as $name => $value) {
+ if (!empty($ret)) {
+ $ret .= " $bool ";
+ }
+ if (is_numeric($name)) {
+ // No Key case => recurse.
+ $ret .= "(" . $this->_analyseCrit($value, $bool) . ")";
+ } else if ($name==="OR" || $name==="AND") {
+ // Binary logical operator
+ $ret .= "(" . $this->_analyseCrit($value, $name) . ")";
+ } else if ($name==="NOT") {
+ // Uninary logicial operator
+ $ret .= " NOT (" . $this->_analyseCrit($value, "AND") . ")";
+ } else if ($name==="FKEY") {
+ // Foreign Key condition
+ if (is_array($value) && count($value)==2) {
+ reset($value);
+ list($t1,$f1)=each($value);
+ list($t2,$f2)=each($value);
+ $ret .= (is_numeric($t1) ? "$f1" : "$t1.$f1") . "=" .
+ (is_numeric($t2) ? "$f2" : "$t2.$f2");
+ } else {
+ trigger_error("BAD FOREIGN KEY", E_USER_ERROR);
+ }
+ } else if (is_array($value)) {
+ // Array of Value
+ $ret .= "$name IN ('". implode("','", $value)."')";
+ } else if (is_null($value)) {
+ // NULL condition
+ $ret .= "$name IS NULL";
+ } else if (is_numeric($value)) {
+ // Integer
+ $ret .= "$name=$value";
+ } else {
+ // String
+ $ret .= "$name='$value'";
+ }
+ }
+ return $ret;
+ }
+
+ /**
+ * Go to the begin of the request (launch it)
+ *
+ * @return hastable|false : next row
+ */
+ public function rewind ()
+ {
+
+ if ($this->res && $this->pos>=0) {
+ $this->res->closeCursor();
+ $this->pos = -1;
+ }
+
+ if ($this->res && $this->pos<0) {
+ if (!$this->res->execute()) {
+ $err = $this->res->errorInfo();
+ throw new Exception($err[2]);
+ }
+ }
+ return $this->next();
+ }
+
+ /**
+ * Retrieve current row
+ *
+ * @return hastable|false
+ */
+ public function current()
+ {
+ return $this->row;
+ }
+
+ /**
+ * Retrieve key of current row
+ *
+ * @return mixed
+ */
+ public function key()
+ {
+ return (isset($this->row["id"]) ? $this->row["id"] : $this->pos);
+ }
+
+ /**
+ * Retrieve next row
+ *
+ * @return hastable|false
+ */
+ public function next()
+ {
+ if (!$this->res) {
+ return false;
+ }
+ $this->row = $this->res->fetch(PDO::FETCH_ASSOC);
+ $this->pos++;
+ return $this->row;
+ }
+
+ /**
+ * Is current row defined
+ *
+ * @return boolean
+ */
+ public function valid()
+ {
+ return $this->res && $this->row;
+ }
+
+ /**
+ * Compute number of rows
+ *
+ * @return integer
+ */
+ public function numrows()
+ {
+ return ($this->res ? $this->res->rowCount() : 0);
+ }
+}
+?> \ No newline at end of file
diff --git a/class/TablePearRepo.php b/class/TablePearRepo.php
new file mode 100644
index 0000000..34a0c17
--- /dev/null
+++ b/class/TablePearRepo.php
@@ -0,0 +1,136 @@
+<?php
+/**
+ * Class for "pearrepo" Table management
+ *
+ * PHP version 5
+ *
+ * Copyright © 2010 Remi Collet
+ *
+ * This file is part of rpmphp.
+ *
+ * rpmphp is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * rpmphp 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with rpmphp. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Main
+ * @package RPMPHP
+ *
+ * @author Remi Collet <unknown@unknwown.com>
+ * @author Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2010 Remi Collet
+ * @license http://www.gnu.org/licenses/agpl-3.0-standalone.html AGPL License 3.0 or (at your option) any later version
+ * @link http://github.com/remicollet/rpmphp/
+ * @since The begining of times.
+*/
+
+class TablePearRepo extends CommonTable
+{
+
+ /**
+ * Instanciate a TablePearRepo to manage pearrepo table
+ *
+ * @param object $db PDO instance of the DB connection
+ */
+ function __construct($db)
+ {
+ parent::__construct($db, 'pearrepo');
+ }
+
+ /**
+ * Create the table and populate it with known repo
+ *
+ * @return void
+ */
+ protected function createTable()
+ {
+
+ // Table schema
+ $sql = "CREATE TABLE `pearrepo` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `alias` varchar(30) NOT NULL,
+ `url` varchar(255) NOT NULL,
+ `active` tinyint NOT NULL default 1,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `alias` (`alias`),
+ KEY `active` (`active`)
+ ) DEFAULT CHARSET=utf8";
+
+ $this->exec($sql);
+
+ // Some known repo, other could be add manually
+ // no reply from "" => ""
+ $channels = array(
+ array(
+ 'alias' => 'pear',
+ 'url' => 'pear.php.net'
+ ),
+ array(
+ 'alias' => 'doctrine',
+ 'url' => 'pear.phpdoctrine.org'
+ ),
+ array(
+ 'alias' => 'ezc',
+ 'url' => 'components.ez.no'
+ ),
+ array(
+ 'alias' => 'pdepend',
+ 'url' => 'pear.pdepend.org'
+ ),
+ array(
+ 'alias' => 'phing',
+ 'url' => 'pear.phing.info'
+ ),
+ array(
+ 'alias' => 'phpmd',
+ 'url' => 'pear.phpmd.org'
+ ),
+ array(
+ 'alias' => 'phpunit',
+ 'url' => 'pear.phpunit.de'
+ ),
+ array(
+ 'alias' => 'swift',
+ 'url' => 'pear.swiftmailer.org'
+ ),
+ array(
+ 'alias' => 'symphony',
+ 'url' => 'pear.symfony-project.com'
+ ),
+ array(
+ 'alias' => 'phpdb',
+ 'active' => 0,
+ 'url' => 'pear.phpdb.org'
+ )
+ );
+
+ foreach ($channels as $channel) {
+ $this->add($channel);
+ }
+ }
+
+ /**
+ * Retrieve all the known repository
+ *
+ * @param boolean $active true for only active repo (false for all)
+ *
+ * @return hastable of alias => url
+ */
+ function getAllRepo($active=true)
+ {
+ if ($active) {
+ return $this->getHashtable('alias', 'url', array('active'=>1));
+ }
+ return $this->getHashtable('alias', 'url');
+ }
+}
+
+?> \ No newline at end of file
diff --git a/class/TableRRepo.php b/class/TableRRepo.php
new file mode 100644
index 0000000..884b4e3
--- /dev/null
+++ b/class/TableRRepo.php
@@ -0,0 +1,123 @@
+<?php
+/**
+ * Class for "rrepo" Table management
+ *
+ * PHP version 5
+ *
+ * Copyright © 2010 Remi Collet
+ *
+ * This file is part of rpmphp.
+ *
+ * rpmphp is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * rpmphp 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with rpmphp. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Main
+ * @package RPMPHP
+ *
+ * @author Remi Collet <unknown@unknwown.com>
+ * @author Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2010 Remi Collet
+ * @license http://www.gnu.org/licenses/agpl-3.0-standalone.html AGPL License 3.0 or (at your option) any later version
+ * @link http://github.com/remicollet/rpmphp/
+ * @since The begining of times.
+*/
+
+class TableRRepo extends CommonTable
+{
+
+ /**
+ * Instanciate a TablePearRepo to manage pearrepo table
+ *
+ * @param object $db PDO instance of the DB connection
+ */
+ function __construct($db)
+ {
+ parent::__construct($db, 'rrepo');
+ }
+
+ /**
+ * Create the table and populate it with known repo
+ *
+ * @return void
+ */
+ protected function createTable()
+ {
+
+ // Table schema
+ $sql = "CREATE TABLE `rrepo` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(30) NOT NULL,
+ `state` varchar(30) NOT NULL default 'stable',
+ `url` varchar(255) NOT NULL,
+ `active` tinyint NOT NULL default 1,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `name_state` (`name`,`state`),
+ KEY `active` (`active`)
+ ) DEFAULT CHARSET=utf8";
+
+ $this->exec($sql);
+
+ // Some known repo, other could be add manually
+ $repos = array(
+ array(
+ "name" => "R",
+ "url" => "http://cran.at.r-project.org/src/contrib/PACKAGES"
+ ),
+ array(
+ "name" => "biocp",
+ "url" => "http://www.bioconductor.org/packages/release/bioc/src/contrib/PACKAGES"
+ ),
+ array(
+ "name" => "biocp",
+ "state" => "unstable",
+ "url" => "http://www.bioconductor.org/packages/devel/bioc/src/contrib/PACKAGES"
+ ),
+ array(
+ "name" => "bioca",
+ "url" => "http://www.bioconductor.org/packages/release/data/annotation/src/contrib/PACKAGES"
+ ),
+ array(
+ "name" => "bioca",
+ "state" => "unstable",
+ "url" => "http://www.bioconductor.org/packages/devel/data/annotation/src/contrib/PACKAGES"
+ ),
+ array(
+ "name" => "bioce",
+ "url" => "http://www.bioconductor.org/packages/release/data/experiment/src/contrib/PACKAGES"
+ ),
+ array(
+ "name" => "bioce",
+ "state" => "unstable",
+ "url" => "http://www.bioconductor.org/packages/devel/data/experiment/src/contrib/PACKAGES"
+ )
+ );
+
+ foreach ($repos as $repo) {
+ $this->add($repo);
+ }
+ }
+
+ /**
+ * Retrieve all the known repository
+ *
+ * @param boolean $active true for only active repo (false for all)
+ *
+ * @return hastable of alias => url
+ */
+ function getAllRepo($active=true)
+ {
+ return $this->getArray($active ? array('active'=>1) : '');
+ }
+}
+
+?> \ No newline at end of file
diff --git a/fedcli.php b/fedcli.php
index eb897c4..40b5b0c 100755
--- a/fedcli.php
+++ b/fedcli.php
@@ -23,9 +23,10 @@
* See <http://www.gnu.org/licenses/>
*/
+define ('CLIONLY', true);
+require 'include/main.php';
require 'Console/Getargs.php';
-require 'class/FedoraClient.php';
function Help() {
echo "\nFedora Client Command Line usage\n\n";
@@ -136,7 +137,7 @@ function Version() {
die (Console_Getargs::getHelp($config)."\n");
}
- echo "PHP Fedora Client class version ".FEDORACLIENT_VERSION."\n";
+ echo "PHP Fedora Client class version ".FedoraClient::VERSION."\n";
}
$cmd = array_shift($_SERVER['argv']);
diff --git a/include/config.php b/include/config.php
new file mode 100644
index 0000000..a3ba75c
--- /dev/null
+++ b/include/config.php
@@ -0,0 +1,7 @@
+<?php
+define("MYHOST", "localhost");
+define("MYUSER", "root");
+define("MYPASS", "valentin");
+define("MYBASE", "rpmphp");
+?>
+
diff --git a/config.inc.php.dist b/include/config.php.dist
index 8895cdc..8895cdc 100644
--- a/config.inc.php.dist
+++ b/include/config.php.dist
diff --git a/main.inc.php b/include/main.php
index c9ec889..286cf4e 100644
--- a/main.inc.php
+++ b/include/main.php
@@ -35,21 +35,36 @@
*/
define('RPMPHP_VERSION', '1.0.0-dev');
-require 'config.inc.php';
-require '/usr/share/php/Smarty/Smarty.class.php';
-require 'class/FedoraClient.php';
+require 'config.php';
-$smarty = new Smarty();
+if (!defined('CLIONLY'))
+{
+ require 'Smarty/Smarty.class.php';
+
+ $smarty = new Smarty();
-$smarty->template_dir = 'smarty/templates/rpmphp';
-$smarty->compile_dir = 'smarty/templates_c';
-$smarty->cache_dir = 'smarty/cache';
-$smarty->config_dir = 'smarty/configs';
+ $smarty->template_dir = 'smarty/templates/rpmphp';
+ $smarty->compile_dir = 'smarty/templates_c';
+ $smarty->cache_dir = 'smarty/cache';
+ $smarty->config_dir = 'smarty/configs';
-$ariane[] = array (
- 'url' => './',
- 'text' => 'Reports home'
-);
+ $ariane[] = array (
+ 'url' => './',
+ 'text' => 'Reports home'
+ );
+}
+
+/**
+ * Manage class autoload
+ *
+ * @param string $classname
+ *
+ * @return void
+ */
+function __autoload($classname)
+{
+ require dirname(__FILE__).'/../class/'.$classname.'.php';
+}
/**
* Get repositories list
diff --git a/index.php b/index.php
index f7a1546..0c163b1 100644
--- a/index.php
+++ b/index.php
@@ -34,7 +34,7 @@
* @link http://github.com/remicollet/rpmphp/
* @since The begining of times.
*/
-require 'main.inc.php';
+require 'include/main.php';
$smarty->assign('ariane', $ariane);
$smarty->assign('page_title', 'Packages in Fedora repositories');
@@ -70,7 +70,7 @@ try {
);
}
$smarty->assign('rpmphp_version', RPMPHP_VERSION);
-$smarty->assign('fedcli_version', FEDORACLIENT_VERSION);
+$smarty->assign('fedcli_version', FedoraClient::VERSION);
$page_content = $smarty->fetch('index.tpl');
$smarty->assign('page_content', $page_content);
diff --git a/pkgdb-ajax.php b/pkgdb-ajax.php
index a07a3e4..24d07b8 100644
--- a/pkgdb-ajax.php
+++ b/pkgdb-ajax.php
@@ -35,7 +35,7 @@
* @since The begining of times.
*/
header('Content-Type: application/json;charset=utf-8');
-require 'main.inc.php';
+require 'include/main.php';
$name = $_GET['name'];
if ( !isset($name) || !$name ) {
@@ -80,6 +80,6 @@ if ( !isset($name) || !$name ) {
}
}
}
-
+error_log("RETURN:".print_r($fedpkg,true));
echo json_encode($fedpkg);
?> \ No newline at end of file
diff --git a/refresh.php b/refresh.php
index cc56e84..e839e93 100644
--- a/refresh.php
+++ b/refresh.php
@@ -43,7 +43,7 @@ if (isset($_SERVER["SERVER_NAME"])) {
die("This script is launched twice a day, be patient");
}
-require "config.inc.php";
+require "include/main.php";
require "class/CommonTable.php";
/**
@@ -508,47 +508,10 @@ try {
// -------------------------------------------------------------------
if ($_SERVER['argc']==1 || in_array('R', $_SERVER['argv'])) {
-
- $repos = array(
- array(
- "name" => "R",
- "state" => "stable",
- "url" => "http://cran.at.r-project.org/src/contrib/PACKAGES"
- ),
- //array("name"=>"R-forge","state"=>"unstable", "url" => "http://r-forge.r-project.org/src/contrib/PACKAGES"),
- array(
- "name" => "biocp",
- "state" => "stable",
- "url" => "http://www.bioconductor.org/packages/release/bioc/src/contrib/PACKAGES"
- ),
- array(
- "name" => "biocp",
- "state" => "unstable",
- "url" => "http://www.bioconductor.org/packages/devel/bioc/src/contrib/PACKAGES"
- ),
- array(
- "name" => "bioca",
- "state" => "stable",
- "url" => "http://www.bioconductor.org/packages/release/data/annotation/src/contrib/PACKAGES"
- ),
- array(
- "name" => "bioca",
- "state" => "unstable",
- "url" => "http://www.bioconductor.org/packages/devel/data/annotation/src/contrib/PACKAGES"
- ),
- array(
- "name" => "bioce",
- "state" => "stable",
- "url" => "http://www.bioconductor.org/packages/release/data/experiment/src/contrib/PACKAGES"
- ),
- array(
- "name" => "bioce",
- "state" => "unstable",
- "url" => "http://www.bioconductor.org/packages/devel/data/experiment/src/contrib/PACKAGES"
- )
- );
+//
$tottot=0;
- foreach ($repos as $repo) {
+ $rrepo = new TableRRepo($db);
+ foreach ($rrepo->request() as $repo) {
echo date("r : ") . "Reading " . $repo["name"] . " (" .
$repo["state"] . ")\n";
$index = @file_get_contents($repo["url"]);
diff --git a/rpm.php b/rpm.php
index 5073f9f..8b140a8 100644
--- a/rpm.php
+++ b/rpm.php
@@ -34,7 +34,7 @@
* @link http://github.com/remicollet/rpmphp/
* @since The begining of times.
*/
-require 'main.inc.php';
+require 'include/main.php';
$what=(isset($_GET["what"]) ? $_GET["what"] : "%fedora");
$type=(isset($_GET["type"]) ? $_GET["type"] : "pecl");
diff --git a/scripts/rpmphp.js b/scripts/rpmphp.js
index 18dfa32..6723438 100644
--- a/scripts/rpmphp.js
+++ b/scripts/rpmphp.js
@@ -30,7 +30,7 @@ function initZoomJS(name)
if ( data.error ) {
alert(data.error);
} else {
- $('#' + name + '_desc').empty().html(data.devel.package.description);
+ $('#' + 'pkgdb_desc').empty().html(data.devel.package.description);
$.each(
data,
function(k, v){
diff --git a/smarty/templates/rpmphp/zoom.tpl b/smarty/templates/rpmphp/zoom.tpl
index 704c6b7..5841478 100644
--- a/smarty/templates/rpmphp/zoom.tpl
+++ b/smarty/templates/rpmphp/zoom.tpl
@@ -40,10 +40,10 @@
{foreach from=$summary key=k item=v}
<tr>
<th>{$k}:</th>
- <td{if $k eq 'Description'} id="{$name}_desc"{/if}>
+ <td{if $k eq 'Description'} id="pkgdb_desc"{/if}>
{if $k eq 'Bugzilla'}
<a href="{$v}">Active bugs</a>
- {elseif $k eq 'URL' or $k eq 'ViewVC'}
+ {elseif $k eq 'URL' or $k eq 'ViewVC' or $k eq 'PkgDB'}
<a href="{$v}">{$v}</a>
{else}
{$v}
diff --git a/zoom.php b/zoom.php
index fdb340f..a7ec090 100644
--- a/zoom.php
+++ b/zoom.php
@@ -34,7 +34,7 @@
* @link http://github.com/remicollet/rpmphp/
* @since The begining of times.
*/
-require 'main.inc.php';
+require 'include/main.php';
$fedcli = new FedoraPkgdb();
@@ -167,6 +167,8 @@ if ( !isset($name) || !$name ) {
$summary['ViewVC'] = 'http://cvs.fedoraproject.org/viewvc/rpms/' .
$name . '/';
+ $summary['PkgDB'] = $fedcli->getPackageURL($name);
+
if (isset($_GET['pkgdb'])) {
$fedpkg = $fedcli->getPackageInfo($name);
} else {