GLOBALS, format, replace if/else with switch

This commit is contained in:
Miles Lott 2001-10-02 04:11:39 +00:00
parent a77fd203f3
commit b7b205a2fa
2 changed files with 197 additions and 169 deletions

View File

@ -87,162 +87,188 @@
* This requires PHP's XML routines. You must configure PHP with --with-xml. * This requires PHP's XML routines. You must configure PHP with --with-xml.
*/ */
function _rssparse_start_elem ($parser, $elem, $attrs)
{
switch($elem)
{
case 'CHANNEL':
$GLOBALS['_rss']->depth++;
$GLOBALS['_rss']->state[$GLOBALS['_rss']->depth] = 'channel';
$GLOBALS['_rss']->tmptitle[$GLOBALS['_rss']->depth] = '';
$GLOBALS['_rss']->tmplink[$GLOBALS['_rss']->depth] = '';
$GLOBALS['_rss']->tmpdesc[$GLOBALS['_rss']->depth] = '';
break;
case 'IMAGE':
$GLOBALS['_rss']->depth++;
$GLOBALS['_rss']->state[$GLOBALS['_rss']->depth] = 'image';
$GLOBALS['_rss']->tmptitle[$GLOBALS['_rss']->depth] = '';
$GLOBALS['_rss']->tmplink[$GLOBALS['_rss']->depth] = '';
$GLOBALS['_rss']->tmpdesc[$GLOBALS['_rss']->depth] = '';
$GLOBALS['_rss']->tmpurl[$GLOBALS['_rss']->depth] = '';
break;
case 'ITEM':
$GLOBALS['_rss']->depth++;
$GLOBALS['_rss']->state[$GLOBALS['_rss']->depth] = 'item';
$GLOBALS['_rss']->tmptitle[$GLOBALS['_rss']->depth] = '';
$GLOBALS['_rss']->tmplink[$GLOBALS['_rss']->depth] = '';
$GLOBALS['_rss']->tmpdesc[$GLOBALS['_rss']->depth] = '';
break;
case 'TITLE':
$GLOBALS['_rss']->depth++;
$GLOBALS['_rss']->state[$GLOBALS['_rss']->depth] = 'title';
break;
case 'LINK':
$GLOBALS['_rss']->depth++;
$GLOBALS['_rss']->state[$GLOBALS['_rss']->depth] = 'link';
break;
case 'DESCRIPTION':
$GLOBALS['_rss']->depth++;
$GLOBALS['_rss']->state[$GLOBALS['_rss']->depth] = 'desc';
break;
case 'URL':
$GLOBALS['_rss']->depth++;
$GLOBALS['_rss']->state[$GLOBALS['_rss']->depth] = 'url';
break;
}
}
function _rssparse_start_elem ($parser, $elem, $attrs) { function _rssparse_end_elem ($parser, $elem)
global $_rss; {
switch ($elem)
{
case 'CHANNEL':
$GLOBALS['_rss']->set_channel(
$GLOBALS['_rss']->tmptitle[$GLOBALS['_rss']->depth],
$GLOBALS['_rss']->tmplink[$GLOBALS['_rss']->depth],
$GLOBALS['_rss']->tmpdesc[$GLOBALS['_rss']->depth]
);
$GLOBALS['_rss']->depth--;
break;
case 'IMAGE':
$GLOBALS['_rss']->set_image(
$GLOBALS['_rss']->tmptitle[$GLOBALS['_rss']->depth],
$GLOBALS['_rss']->tmplink[$GLOBALS['_rss']->depth],
$GLOBALS['_rss']->tmpdesc[$GLOBALS['_rss']->depth],
$GLOBALS['_rss']->tmpurl[$GLOBALS['_rss']->depth]
);
$GLOBALS['_rss']->depth--;
break;
case 'ITEM':
$GLOBALS['_rss']->add_item(
$GLOBALS['_rss']->tmptitle[$GLOBALS['_rss']->depth],
$GLOBALS['_rss']->tmplink[$GLOBALS['_rss']->depth],
$GLOBALS['_rss']->tmpdesc[$GLOBALS['_rss']->depth]
);
$GLOBALS['_rss']->depth--;
break;
case 'TITLE':
$GLOBALS['_rss']->depth--;
break;
case 'LINK':
$GLOBALS['_rss']->depth--;
break;
case 'DESCRIPTION':
$GLOBALS['_rss']->depth--;
break;
case 'URL':
$GLOBALS['_rss']->depth--;
break;
}
}
if ($elem == "CHANNEL") { function _rssparse_elem_data ($parser, $data)
$_rss->depth++; {
$_rss->state[$_rss->depth] = "channel"; switch ($GLOBALS['_rss']->state[$GLOBALS['_rss']->depth])
$_rss->tmptitle[$_rss->depth] = ""; {
$_rss->tmplink[$_rss->depth] = ""; case 'title':
$_rss->tmpdesc[$_rss->depth] = ""; $GLOBALS['_rss']->tmptitle[($GLOBALS['_rss']->depth - 1)] .= $data;
} break;
else if ($elem == "IMAGE") { case 'link';
$_rss->depth++; $GLOBALS['_rss']->tmplink[($GLOBALS['_rss']->depth - 1)] .= $data;
$_rss->state[$_rss->depth] = "image"; break;
$_rss->tmptitle[$_rss->depth] = ""; case 'desc':
$_rss->tmplink[$_rss->depth] = ""; $GLOBALS['_rss']->tmpdesc[($GLOBALS['_rss']->depth - 1)] .= $data;
$_rss->tmpdesc[$_rss->depth] = ""; break;
$_rss->tmpurl[$_rss->depth] = ""; case 'url':
} $GLOBALS['_rss']->tmpurl[($GLOBALS['_rss']->depth - 1)] .= $data;
else if ($elem == "ITEM") { break;
$_rss->depth++; }
$_rss->state[$_rss->depth] = "item"; }
$_rss->tmptitle[$_rss->depth] = "";
$_rss->tmplink[$_rss->depth] = "";
$_rss->tmpdesc[$_rss->depth] = "";
}
else if ($elem == "TITLE") {
$_rss->depth++;
$_rss->state[$_rss->depth] = "title";
}
else if ($elem == "LINK") {
$_rss->depth++;
$_rss->state[$_rss->depth] = "link";
}
else if ($elem == "DESCRIPTION") {
$_rss->depth++;
$_rss->state[$_rss->depth] = "desc";
}
else if ($elem == "URL") {
$_rss->depth++;
$_rss->state[$_rss->depth] = "url";
}
}
function _rssparse_end_elem ($parser, $elem) {
global $_rss;
if ($elem == "CHANNEL") { class rssparser
$_rss->set_channel($_rss->tmptitle[$_rss->depth], $_rss->tmplink[$_rss->depth], $_rss->tmpdesc[$_rss->depth]); {
$_rss->depth--; var $title;
} var $link;
else if ($elem == "IMAGE") { var $desc;
$_rss->set_image($_rss->tmptitle[$_rss->depth], $_rss->tmplink[$_rss->depth], $_rss->tmpdesc[$_rss->depth], $_rss->tmpurl[$_rss->depth]); var $items = array();
$_rss->depth--; var $nitems;
} var $image = array();
else if ($elem == "ITEM") { var $state = array();
$_rss->add_item($_rss->tmptitle[$_rss->depth], $_rss->tmplink[$_rss->depth], $_rss->tmpdesc[$_rss->depth]); var $tmptitle = array();
$_rss->depth--; var $tmplink = array();
} var $tmpdesc = array();
else if ($elem == "TITLE") { var $tmpurl = array();
$_rss->depth--; var $depth;
}
else if ($elem == "LINK") {
$_rss->depth--;
}
else if ($elem == "DESCRIPTION") {
$_rss->depth--;
}
else if ($elem == "URL") {
$_rss->depth--;
}
}
function _rssparse_elem_data ($parser, $data) {
global $_rss;
if ($_rss->state[$_rss->depth] == "title") { function rssparser()
$_rss->tmptitle[($_rss->depth - 1)] .= $data; {
} $this->nitems = 0;
else if ($_rss->state[$_rss->depth] == "link") { $this->depth = 0;
$_rss->tmplink[($_rss->depth - 1)] .= $data; }
}
else if ($_rss->state[$_rss->depth] == "desc") {
$_rss->tmpdesc[($_rss->depth - 1)] .= $data;
}
else if ($_rss->state[$_rss->depth] == "url") {
$_rss->tmpurl[($_rss->depth - 1)] .= $data;
}
}
class rssparser { function set_channel($in_title, $in_link, $in_desc)
var $title; {
var $link; $this->title = $in_title;
var $desc; $this->link = $in_link;
var $items = array(); $this->desc = $in_desc;
var $nitems; }
var $image = array();
var $state = array();
var $tmptitle = array();
var $tmplink = array();
var $tmpdesc = array();
var $tmpurl = array();
var $depth;
function rssparser() { function set_image($in_title, $in_link, $in_desc, $in_url)
$this->nitems = 0; {
$this->depth = 0; $this->image['title'] = $in_title;
} $this->image['link'] = $in_link;
$this->image['desc'] = $in_desc;
$this->image['url'] = $in_url;
}
function set_channel($in_title, $in_link, $in_desc) { function add_item($in_title, $in_link, $in_desc)
$this->title = $in_title; {
$this->link = $in_link; $this->items[$this->nitems]['title'] = $in_title;
$this->desc = $in_desc; $this->items[$this->nitems]['link'] = $in_link;
} $this->items[$this->nitems]['desc'] = $in_desc;
$this->nitems++;
}
function set_image($in_title, $in_link, $in_desc, $in_url) { function parse($fp)
$this->image["title"] = $in_title; {
$this->image["link"] = $in_link; $xml_parser = xml_parser_create();
$this->image["desc"] = $in_desc;
$this->image["url"] = $in_url;
}
function add_item($in_title, $in_link, $in_desc) { xml_set_element_handler($xml_parser, '_rssparse_start_elem', '_rssparse_end_elem');
$this->items[$this->nitems]["title"] = $in_title; xml_set_character_data_handler($xml_parser, '_rssparse_elem_data');
$this->items[$this->nitems]["link"] = $in_link;
$this->items[$this->nitems]["desc"] = $in_desc;
$this->nitems++;
}
function parse($fp) { while ($data = fread($fp, 4096))
$xml_parser = xml_parser_create(); {
if (!xml_parse($xml_parser, $data, feof($fp)))
xml_set_element_handler($xml_parser, "_rssparse_start_elem", "_rssparse_end_elem"); {
xml_set_character_data_handler($xml_parser, "_rssparse_elem_data"); return 1;
}
while ($data = fread($fp, 4096)) { }
if (!xml_parse($xml_parser, $data, feof($fp))) {
return 1;
}
}
xml_parser_free($xml_parser);
return 0;
}
}
function rssparse ($fp) { xml_parser_free($xml_parser);
global $_rss;
$_rss = new rssparser(); return 0;
}
}
if ($_rss->parse($fp)) { function rssparse ($fp)
return 0; {
} $GLOBALS['_rss'] = new rssparser();
return $_rss; if ($GLOBALS['_rss']->parse($fp))
} {
?> return 0;
}
return $GLOBALS['_rss'];
}
?>

View File

@ -23,29 +23,31 @@
/* $Id$ */ /* $Id$ */
$d1 = strtolower(substr($phpgw_info["server"]["api_inc"],0,3)); $d1 = strtolower(substr(PHPGW_API_INC,0,3));
if($d1 == "htt" || $d1 == "ftp") { if($d1 == 'htt' || $d1 == 'ftp')
echo "Failed attempt to break in via an old Security Hole!<br>\n"; {
exit; echo 'Failed attempt to break in via an old Security Hole!<br>' . "\n";
} unset($d1); exit;
}
unset($d1);
class utilities class utilities
{ {
var $rssparser; var $rssparser;
var $clientsniffer; var $clientsniffer;
var $http; var $http;
var $matrixview; var $matrixview;
var $menutree; var $menutree;
var $sbox; var $sbox;
function utilities_() function utilities_()
{ {
// $phpgw->rssparser = CreateObject("phpgwapi.rssparser"); // $GLOBALS['phpgw']->rssparser = CreateObject("phpgwapi.rssparser");
// $phpgw->clientsniffer = CreateObject("phpgwapi.clientsniffer"); // $GLOBALS['phpgw']->clientsniffer = CreateObject("phpgwapi.clientsniffer");
// $phpgw->http = CreateObject("phpgwapi.http"); // $GLOBALS['phpgw']->http = CreateObject("phpgwapi.http");
// $phpgw->matrixview = CreateObject("phpgwapi.matrixview"); // $GLOBALS['phpgw']->matrixview = CreateObject("phpgwapi.matrixview");
// $phpgw->menutree = CreateObject("phpgwapi.menutree"); // $GLOBALS['phpgw']->menutree = CreateObject("phpgwapi.menutree");
$phpgw->sbox = CreateObject("phpgwapi.portalbox"); $GLOBALS['phpgw']->sbox = CreateObject('phpgwapi.portalbox');
} }
} }
?> ?>