Changeset 73
- Timestamp:
- 09/06/05 14:56:10
- Files:
-
- trunk/pat/patXMLRenderer.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/pat/patXMLRenderer.php
r68 r73 504 504 $oldMask = @umask( 0 ); 505 505 506 if ( !@$this->_mkdir_recursive( $this->cacheDir, 0777 ) ) {506 if ( !@$this->_mkdir_recursive( $this->cacheDir, 0777 ) ) { 507 507 @umask( $oldMask ); 508 508 die( '<b>patXMLRenderer:</b> Could not create cachedir \''.$this->cacheDir.'\'.' ); … … 727 727 728 728 // get default skin 729 foreach ( $this->skins as $name => $skin )730 if ( $skin['default'] )729 foreach ( $this->skins as $name => $skin ) 730 if ( $skin['default'] ) 731 731 return $skin; 732 732 … … 851 851 if ( isset( $_SERVER['HTTP_REFERER'] ) ) { 852 852 $referer = strtolower( $_SERVER['HTTP_REFERER'] ); 853 if ( str_replace( $this->refererBlocks, '', $referer ) === $referer )853 if ( str_replace( $this->refererBlocks, '', $referer ) === $referer ) 854 854 $this->logger->writeRefererLog( $_SERVER['HTTP_REFERER'], $this->xmlFile ); 855 855 } … … 1309 1309 if ( $cache != 'off' ) 1310 1310 { 1311 $this->cacheAble[ ( $this->parsers+1 )] = true;1312 if ( $content = $this->getCachedContent( $file ) )1311 $this->cacheAble[ $this->parsers+1 ] = true; 1312 if ( $content = $this->getCachedContent( $file ) ) 1313 1313 return $content; 1314 1314 } … … 1324 1324 if ( !xml_parse( $parser, $data, feof($fp) ) ) 1325 1325 { 1326 die( sprintf( "XML error: %s at line %d in file %s",1326 die( sprintf( 'XML error: %s at line %d in file %s', 1327 1327 xml_error_string( xml_get_error_code( $parser ) ), 1328 1328 xml_get_current_line_number( $parser ), … … 1396 1396 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, true ); 1397 1397 1398 return $parser;1398 return $parser; 1399 1399 } 1400 1400 … … 1409 1409 $cacheFile = $this->getCacheFileName( $xmlFile ); 1410 1410 1411 // check, if cache file exists 1412 if ( file_exists( $cacheFile['cache'] ) ) 1413 { 1414 if ( filemtime( $xmlFile ) > filemtime( $cacheFile['cache'] ) ) 1415 $cachable = false; 1416 else 1411 // check if cache file exists and is up-to-date 1412 if ( file_exists( $cacheFile['cache'] ) and filemtime( $xmlFile ) <= filemtime( $cacheFile['cache'] ) ) 1413 { 1414 $fp = fopen( $cacheFile['info'], 'r' ); 1415 flock( $fp, LOCK_SH ); 1416 1417 while ( $line = trim( fgets( $fp, 4096 ) ) ) 1417 1418 { 1418 $cachable = true; 1419 $fp = fopen( $cacheFile['info'], 'r' ); 1420 flock( $fp, LOCK_SH ); 1421 1422 while ( $line = trim( fgets( $fp, 4096 ) ) ) 1419 list( $command, $param ) = explode( '=', $line ); 1420 1421 switch ( $command ) 1423 1422 { 1424 list( $command, $param ) = explode( '=', $line ); 1425 switch( $command ) 1426 { 1427 case 'validUntil': 1428 if( $param < time() ) 1429 { 1430 $cachable = false; 1431 break 2; 1432 } 1433 break; 1434 1435 case 'checkExternal': 1436 if( !file_exists( $param ) || ( filemtime( $param ) > filemtime( $cacheFile['cache'] ) ) ) 1437 { 1438 $cachable = false; 1439 break 2; 1440 } 1441 break; 1442 case 'checkTemplate': 1443 if( !file_exists( $param ) || ( filemtime( $param ) > filemtime( $cacheFile['cache'] ) ) ) 1444 { 1445 $cachable = false; 1446 break 2; 1447 } 1448 break; 1449 case 'action': 1450 if( $param == 'startCache' ) 1451 break 2; 1452 break; 1453 default: 1454 break; 1455 } 1423 case 'validUntil': 1424 if ( $param < time() ) 1425 return false; 1426 break; 1427 1428 case 'checkExternal': 1429 case 'checkTemplate': 1430 if ( !file_exists( $param ) || ( filemtime( $param ) > filemtime( $cacheFile['cache'] ) ) ) 1431 return false; 1432 break; 1433 1456 1434 } 1457 flock( $fp, LOCK_UN );1458 fclose( $fp );1459 1460 return ( $cachable )1461 ? @implode( '', @file( $cacheFile['cache'] ) )1462 : false;1463 1435 } 1464 } 1465 else 1466 return false; 1436 flock( $fp, LOCK_UN ); 1437 fclose( $fp ); 1438 1439 return @implode( '', @file( $cacheFile['cache'] ) ); 1440 } 1441 1442 return false; 1467 1443 } 1468 1444 … … 1472 1448 * @param string $xmlFile filename of the xml file 1473 1449 * @param string $content content of the cached file 1474 * @todo see comment in the code1475 1450 */ 1476 1451 function writeCache( $xmlFile, $content ) … … 1481 1456 $tmp = dirname( $cacheFile['cache'] ); 1482 1457 1483 // TODO: if ( $tmp != $cacheFile ) :TODO: what was this for?1484 1458 $this->_mkdir_recursive( $tmp, 0700 ); 1485 1459 … … 1504 1478 while ( $tmpl = array_pop( $templates ) ) 1505 1479 { 1506 $tmplFile = ( $this->tmpl->basedir!= "" ) ? $this->tmpl->basedir."/".$tmpl : $tmpl;1507 fputs( $fp, "checkTemplate=".$tmplFile."\n" );1480 $tmplFile = ( $this->tmpl->basedir!='' ) ? $this->tmpl->basedir.'/'.$tmpl : $tmpl; 1481 fputs( $fp, 'checkTemplate='.$tmplFile."\n" ); 1508 1482 } 1509 fputs( $fp, "action=StartCache\n" );1510 1483 flock( $fp, LOCK_UN ); 1511 1484 fclose( $fp ); … … 1522 1495 fputs( $fp, "cachetype=force\n" ); 1523 1496 fputs( $fp, 'validUntil='.( time() + $cachetime )."\n" ); 1524 fputs( $fp, "action=StartCache\n" );1525 1497 flock( $fp, LOCK_UN ); 1526 1498 fclose( $fp ); … … 1559 1531 * build the cache filename for a xmlfile 1560 1532 * 1561 * @param string $xmlFile filename of the xmlfile1562 * @return string $cacheFile filename of the cache file1533 * @param string $xmlFile filename of the XML file 1534 * @return string $cacheFile filenames of the cache file 1563 1535 */ 1564 1536 function getCacheFileName( $xmlFile ) 1565 1537 { 1566 // create name of the cache file 1567 $pos = strrpos( $xmlFile, '.' ); 1568 if ( $pos != false ) 1569 $base = $this->cacheDir.'/'.md5( substr( $xmlFile, 0, $pos ) ); 1570 1571 $cacheFile = array( 1572 'cache' => $base.'.cache', 1573 'info' => $base.'.info', 1538 $base = $this->cacheDir . '/' . md5( $xmlFile ); 1539 1540 $cacheFile = array( 1541 'cache' => $base.'.cache', 1542 'info' => $base.'.info', 1574 1543 ); 1575 1544 return $cacheFile; … … 1577 1546 1578 1547 /** 1579 * get urlfor Randy1580 * 1581 * @return string $randy urlfor randy1548 * get URL for Randy 1549 * 1550 * @return string $randy URL for randy 1582 1551 */ 1583 1552 function getSelfUrl() 1584 1553 { 1585 $self = $_SERVER['PHP_SELF'] .'?';1586 1587 for ( $i=0; $i<count( $this->keepVars ); $i++)1588 if ( $GLOBALS[$this->keepVars[$i]])1589 $self .= '&'. $this->keepVars[$i].'='.$GLOBALS[$this->keepVars[$i]];1590 1591 return $self;1592 } 1593 1594 /** 1595 * create a string representation of an XML tag1554 $self = $_SERVER['PHP_SELF'] . '?'; 1555 1556 foreach ( $this->keepVars as $keepVar ) 1557 if ( isset( $GLOBALS[$keepVar] ) ) 1558 $self .= '&'. $keepVar .'='. $GLOBALS[$keepVar]; 1559 1560 return $self; 1561 } 1562 1563 /** 1564 * creates a string representation of an XML tag 1596 1565 * 1597 1566 * @param string $name name of the tag, including the namespace … … 1600 1569 * @return string $string string representation of the tag 1601 1570 */ 1602 function tagToString( $name, $attributes, $content = "" ) 1603 { 1604 $string = '<'.$name; 1571 function tagToString( $name, $attributes, $content = '' ) 1572 { 1573 $string = '<'.$name; 1574 1605 1575 foreach ( $attributes as $key => $value ) 1606 $string .= sprintf( ' %s="%s"', strtolower( $key ), $this->replaceEntities( $value ) ); 1607 1608 if ( $content ) 1609 $string .= '>'.$content.'</'.$name.'>'; 1610 else 1611 $string .= '/>'; 1612 1613 return $string; 1614 } 1615 1616 /** 1617 * replace XML entities in a string 1618 * 1619 * @access public 1620 * @param string $string string in whuich entities should be replaced 1576 $string .= ' '. strtolower( $key ) .'="'. $this->replaceEntities( $value ) .'"'; 1577 1578 $string .= ( strlen($content) > 0 ) 1579 ? '>'. $content .'</'. $name .'>' 1580 : '/>'; 1581 1582 return $string; 1583 } 1584 1585 /** 1586 * replaces XML entities in a string 1587 * 1588 * @access public 1589 * @param string $string string in which entities should be replaced 1621 1590 * @return string $string 1622 1591 */ … … 1636 1605 { 1637 1606 list( $usec, $sec ) = explode( ' ', microtime() ); 1638 return ( (float)$usec + (float)$sec );1639 } 1640 1641 /** 1642 * Attempts to create all non-existing directories of a specified path1607 return (float)$usec + (float)$sec; 1608 } 1609 1610 /** 1611 * attempts to create all non-existing directories of a specified path 1643 1612 * 1644 1613 * Despite of its name, it doesn't use recursion.
