Skip to content

Commit

Permalink
More version fixes.
Browse files Browse the repository at this point in the history
Fix code because the versions lists are no longer associative lists.
Allow to return a single module's information.
  • Loading branch information
yunosh committed Mar 11, 2014
1 parent 55ca5d2 commit efa011c
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 48 deletions.
12 changes: 6 additions & 6 deletions app/controllers/Development.php
Expand Up @@ -63,19 +63,19 @@ protected function _setup()

public function git_and_ver($module)
{
$horde_apps_stable = HordeWeb_Utils::getStableApps();
$horde_apps_dev = HordeWeb_Utils::getDevApps();
$stable = HordeWeb_Utils::getStableApps($module);
$dev = HordeWeb_Utils::getDevApps($module);
return '<td><a href="http://git.horde.org/horde-git/-/browse/' . htmlspecialchars($module) . '/">' . htmlspecialchars($module) . '</a>'
. '</td><td>' . (isset($horde_apps_stable[$module]) ? htmlspecialchars($horde_apps_stable[$module]['ver']) : (isset($horde_apps_dev[$module]) ? htmlspecialchars($horde_apps_dev[$module]['ver']) : '&nbsp;'))
. '</td><td>' . ($stable ? htmlspecialchars($stable['ver']) : ($dev ? htmlspecialchars($dev['ver']) : '&nbsp;'))
. '</td>';
}

public function cvs_and_ver($module)
{
$horde_apps_stable = HordeWeb_Utils::getH3Apps();
$horde_apps_dev = HordeWeb_Utils::getDevApps();
$stable = HordeWeb_Utils::getH3Apps($module);
$dev = HordeWeb_Utils::getDevApps($module);
return '<td><a href="http://git.horde.org/horde/-/browse/' . htmlspecialchars($module) . '/">' . htmlspecialchars($module) . '</a>'
. '</td><td>' . (isset($horde_apps_stable[$module]) ? htmlspecialchars($horde_apps_stable[$module]['ver']) : (isset($horde_apps_dev[$module]) && substr($horde_apps_dev[$module]['ver'], 0, 2) == 'H3' ? htmlspecialchars($horde_apps_dev[$module]['ver']) : '&nbsp;'))
. '</td><td>' . ($stable ? htmlspecialchars($stable['ver']) : ($dev && substr($dev['ver'], 0, 2) == 'H3' ? htmlspecialchars($dev['ver']) : '&nbsp;'))
. '</td>';
}
}
48 changes: 25 additions & 23 deletions app/controllers/Download.php
Expand Up @@ -83,46 +83,48 @@ protected function _app(Horde_Controller_Response $response)
$app_list = array_unique($app_list);

foreach ($app_list as $val) {
$stabledate[$val] = isset($horde_apps_stable[$val])
? strtotime($horde_apps_stable[$val]['date'])
: 0;
$h4date[$val] = isset($horde_apps_h4[$val])
? strtotime($horde_apps_h4[$val]['date'])
: 0;
$stable = HordeWeb_Utils::getStableApps($val);
$h4 = HordeWeb_Utils::getH4Apps($val);
$stabledate[$val] = $stable ? strtotime($stable['date']) : 0;
$h4date[$val] = $h4 ? strtotime($h4['date']) : 0;
}

if (isset($horde_apps_stable[$app])) {
$stable = HordeWeb_Utils::getStableApps($app);
if ($stable) {
foreach ($app_list as $val) {
$stableapp[] = HordeWeb_Utils::app_download_link($val, $horde_apps_stable[$val], false, $this);
$stableapp[] = HordeWeb_Utils::app_download_link($val, HordeWeb_Utils::getStableApps($val), false, $this);
}
$app_info = $horde_apps_stable[$app];
$stableapp[] = '<a href="' . htmlspecialchars(HordeWeb_Utils::app_patches_url($val, $horde_apps_stable[$app])) . '">Patches for Current Stable Release</a>';
$app_info = $stable;
$stableapp[] = '<a href="' . htmlspecialchars(HordeWeb_Utils::app_patches_url($val, $stable)) . '">Patches for Current Stable Release</a>';
} else {
$stableapp[] = 'No current stable release';
}

if (isset($horde_apps_h4[$app])) {
$h4 = HordeWeb_Utils::getH4Apps($app);
if ($h4) {
foreach ($app_list as $val) {
$h4app[] = HordeWeb_Utils::app_download_link($val, $horde_apps_h4[$val], false, $this);
$h4app[] = HordeWeb_Utils::app_download_link($val, HordeWeb_Utils::getH4Apps($val), false, $this);
}
}

if (isset($horde_apps_dev[$app]) &&
$stabledate[$app] < strtotime($horde_apps_dev[$val]['date']) &&
$h4date[$app] < strtotime($horde_apps_dev[$val]['date'])) {
$dev = HordeWeb_Utils::getDevApps($app);
if ($dev &&
$stabledate[$app] < strtotime($dev['date']) &&
$h4date[$app] < strtotime($dev['date'])) {
foreach ($app_list as $val) {
if (!isset($horde_apps_dev[$val])) {
$devapp[] = HordeWeb_Utils::app_download_link($val, $horde_apps_stable[$val]);
} elseif ($h4date[$val] > strtotime($horde_apps_dev[$val]['date'])) {
$devapp[] = HordeWeb_Utils::app_download_link($val, $horde_apps_h4[$val]);
} elseif ($stabledate[$val] > strtotime($horde_apps_dev[$val]['date'])) {
$devapp[] = HordeWeb_Utils::app_download_link($val, $horde_apps_stable[$val]);
$info = HordeWeb_Utils::getDevApps($val);
if (!$info) {
$devapp[] = HordeWeb_Utils::app_download_link($val, HordeWeb_Utils::getStableApps($val));
} elseif ($h4date[$val] > strtotime($dev['date'])) {
$devapp[] = HordeWeb_Utils::app_download_link($val, HordeWeb_Utils::getH4Apps($val));
} elseif ($stabledate[$val] > strtotime($dev['date'])) {
$devapp[] = HordeWeb_Utils::app_download_link($val, HordeWeb_Utils::getStableApps($val));
} else {
$devapp[] = HordeWeb_Utils::app_download_link($val, $horde_apps_dev[$val]);
$devapp[] = HordeWeb_Utils::app_download_link($val, HordeWeb_Utils::getDevApps($val));
}
}
if (empty($app_info)) {
$app_info = $horde_apps_dev[$app];
$app_info = $dev;
}
}

Expand Down
83 changes: 67 additions & 16 deletions app/lib/HordeWeb/Utils.php
Expand Up @@ -28,53 +28,104 @@ static public function getVersionDb()
/**
* Get list of released stable applications.
*
* @param string $app Only return information for this application.
*
* @return array
*/
static public function getStableApps()
static public function getStableApps($app = null)
{
$query = 'SELECT * FROM versions WHERE state = ?';
$values = array('stable');
if ($app) {
$query .= ' AND application = ?';
$values[] = $app;
}

$stmt = self::getVersionDb()
->prepare('SELECT * FROM versions WHERE state = ?');
->prepare($query);

if ($stmt->execute(array('stable'))) {
return $stmt->fetchAll();
if ($stmt->execute($values)) {
return $app
? $stmt->fetch(PDO::FETCH_ASSOC)
: $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}

/**
* Get list of Horde 4 released applications.
*
* @param string $app Only return information for this application.
*
* @return array
*/
static public function getH4Apps()
static public function getH4Apps($app = null)
{
$query = 'SELECT * FROM versions WHERE pear = ?';
$values = array(true);
if ($app) {
$query .= ' AND application = ?';
$values[] = $app;
}

$stmt = self::getVersionDb()
->prepare('SELECT * FROM versions WHERE pear = ?');
->prepare($query);

if ($stmt->execute(array(true))) {
return $stmt->fetchAll();
if ($stmt->execute($values)) {
return $app
? $stmt->fetch(PDO::FETCH_ASSOC)
: $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}

/**
* Get list of Horde 3 released applications.
*
* @param string $app Only return information for this application.
*
* @return array
*/
static public function getH3Apps()
static public function getH3Apps($app = null)
{
$query = 'SELECT * FROM versions WHERE state = ?';
$values = array('three');
if ($app) {
$query .= ' AND application = ?';
$values[] = $app;
}

$stmt = self::getVersionDb()
->prepare('SELECT * FROM versions WHERE state = ?');
if ($stmt->execute(array('three'))) {
return $stmt->fetchAll();
->prepare($query);

if ($stmt->execute($values)) {
return $app
? $stmt->fetch(PDO::FETCH_ASSOC)
: $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}

static public function getDevApps()
/**
* Get list of applications in development.
*
* @param string $app Only return information for this application.
*
* @return array
*/
static public function getDevApps($app = null)
{
$query = 'SELECT * FROM versions WHERE state = ?';
$values = array('dev');
if ($app) {
$query .= ' AND application = ?';
$values[] = $app;
}

$stmt = self::getVersionDb()
->prepare('SELECT * FROM versions WHERE state = ?');
if ($stmt->execute(array('dev'))) {
return $stmt->fetchAll();
->prepare($query);

if ($stmt->execute($values)) {
return $app
? $stmt->fetch(PDO::FETCH_ASSOC)
: $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}

Expand Down
6 changes: 3 additions & 3 deletions versions.php
Expand Up @@ -9,10 +9,10 @@
?>
<versions>
<stable>
<?php foreach ($horde_apps_stable as $app => $info): ?>
<application name="<?php echo $app ?>">
<?php foreach ($horde_apps_stable as $info): ?>
<application name="<?php echo $info['application'] ?>">
<version><?php echo $info['ver'] ?></version>
<url><?php echo htmlspecialchars(HordeWeb_Utils::app_download_url($app, $info)) ?></url>
<url><?php echo htmlspecialchars(HordeWeb_Utils::app_download_url($info['application'], $info)) ?></url>
</application>
<?php endforeach; ?>
</stable>
Expand Down

0 comments on commit efa011c

Please sign in to comment.