Update of /cvsroot/phpvortex/phpvortex
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24613
Modified Files:
TB_Base.class.php
Added Files:
URL.class.php
Log Message:
Added utility class URL (and used it in TB_Base)
--- NEW FILE: URL.class.php ---
<?php
/**
* File for class URL.
*
* @package Vortex
* @subpackage Util
* @author Thiago Ramon Gonçalves Montoya
* @copyright Copyright 2004, Thiago Ramon Gonçalves Montoya
* @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
*/
/**
* Utility class to help the use of URLs.
*
* @package Vortex
* @subpackage Util
*/
class URL
{
/**
* Base URL (everything before the ?).
*
* @var string
*/
var $base;
/**
* URL Parameters (everything after the ?) as 'name' => 'value'.
*
* @var array
*/
var $parameters;
/**
* Constructor: Create a new URL object with a URL, using the present page as default.
*/
function URL($url = '')
{
if (empty($url)) {
$this->Parse($_SERVER['PHP_SELF'] . (isset($_SERVER['QUERY_STRING'])?('?'.$_SERVER['QUERY_STRING']):''));
} else {
$this->Parse($url);
}
}
/**
* Parse a URL into it's parts.
*
* @param string $url URL to parse.
*/
function Parse($url)
{
$parts = explode('?',$url);
$this->base = $parts[0];
$this->parameters = array();
if (count($parts)==1) {
$params = explode('&', $parts[1]);
foreach ($params as $param) {
$pieces = explode('=',$param);
if (count($pieces)==2) $this->parameters[$pieces[0]] = $pieces[1];
}
}
}
/**
* Gets the full URL.
*
* @return string Returns the full URL.
*/
function Get()
{
$url = $this->base;
if (!empty($this->parameters)) {
$pieces = array();
foreach ($this->parameters as $key => $value) $pieces[] = "$key=$value";
$url .= '?'.implode('&',$pieces);
}
return $url;
}
}
?>
Index: TB_Base.class.php
===================================================================
RCS file: /cvsroot/phpvortex/phpvortex/TB_Base.class.php,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** TB_Base.class.php 5 Oct 2004 19:35:09 -0000 1.11
--- TB_Base.class.php 6 Oct 2004 19:49:22 -0000 1.12
***************
*** 276,285 ****
* Outputs a list for viewing/editing records.
*
! * @param string $url URL to link the records to. The function replaces the string "PKEY" with the pkeys and values for the record. Leave blank for no links.
* @param int $page Current page to show the records. Leave -1 to show all records.
* @param array $data Array containing the data to seek as 'field' => 'value'.
* @return bool Returns TRUE on success, FALSE on error.
*/
! function ShowList($url = '', $page = -1, $data = NULL)
{
$fields = '';
--- 276,285 ----
* Outputs a list for viewing/editing records.
*
! * @param URL $url URL to link the records to. Leave blank for no links.
* @param int $page Current page to show the records. Leave -1 to show all records.
* @param array $data Array containing the data to seek as 'field' => 'value'.
* @return bool Returns TRUE on success, FALSE on error.
*/
! function ShowList($url = NULL, $page = -1, $data = NULL)
{
$fields = '';
***************
*** 317,328 ****
echo "<tr>\n";
if (!empty($url)) {
- $pkeys = '';
foreach ($this->fields as $field) if ($field->pkey) {
! $pkeys .= (strlen($pkeys)?'&':'')."{$field->name_db}={$row[$field->name_db]}";
}
}
foreach ($this->fields_list as $field) {
echo "<td class='fd_{$field->name}'>";
! if (!empty($url)) echo "<a href='".str_replace('PKEY',$pkeys,$url)."'>";
$field->ShowPlain($row[$field->name_db]);
if (!empty($url)) echo '</a>';
--- 317,327 ----
echo "<tr>\n";
if (!empty($url)) {
foreach ($this->fields as $field) if ($field->pkey) {
! $url->parameters[$field->name_db] = $row[$field->name_db];
}
}
foreach ($this->fields_list as $field) {
echo "<td class='fd_{$field->name}'>";
! if (!empty($url)) echo "<a href='".$url->Get()."'>";
$field->ShowPlain($row[$field->name_db]);
if (!empty($url)) echo '</a>';
|