All pastes #816630 Raw Edit

Untitled

public php v1 · immutable
·published 2007-12-14 21:53 UTC
rendered paste body
<?	// Global functions		function fg_query( $tab, $col, $val, $ret ) {			$que = "SELECT * FROM " . $tab . " WHERE " . $col . " = '" . $val . "'";		$res = mysql_query( $que );		$fet = mysql_fetch_assoc( $res );					return stripslashes( $fet[$ret] );		}		function fg_update( $tab, $pre = array(), $col, $whe, $typ = false ) {			foreach( $pre as $key => $val ) {			$che = ( $typ == false ) ? "'" . mysql_real_escape_string( $val ) . "'" : $val;			$set[] = $key . " = " . $che;		}				$que = "UPDATE " . $tab . " SET " . implode( ', ', $set ) . " WHERE " . $col . " = '" . $whe . "'";		$ret = ( mysql_query( $que ) ) ? true : false;				return( $ret );		}		function fg_nth( $tab, $mom, $col, $inc, $suf = '' ) {			$tof = ( $mom != true ) ? 'MIN' : 'MAX';		$que = "SELECT " . $tof . "(" . $col . ") AS nthval FROM " . $tab . $suf;		$res = mysql_query( $que );		$fet = mysql_fetch_assoc( $res );				return( $fet['nthval'] + $inc );		}		function fg_count( $tab, $col = false, $ide = false, $dec = 0 ) {			$que = "SELECT * FROM " . $tab;		$que .= ( $col != false && $ide != false ) ? " WHERE " . $col . " = '" . $ide . "'" : '';		$res = mysql_query( $que );		$fet = mysql_num_rows( $res );				return( $fet - $dec );		}			function fg_timediff( $sta, $opt = array() ) {			$dop = array( 'to' => 0, 'offset' => 1, 'parts' => 1, 'precision' => 'second', 'distance' => TRUE, 'separator' => ', ' );		$per = array( 'decade' => 315569260, 'year' => 31556926, 'month' => 2629744, 'week' => 604800, 'day' => 86400, 'hour' => 3600, 'min' => 60, 'sec' => 1 );		$opt = array_merge( $dop, $opt );		$sta = $sta - $opt['offset'];		$str = '';				( !$opt['to'] ) && ( $opt['to'] = time() );		$dif = ( $opt['to'] > $sta ) ? $opt['to'] - $sta : $sta - $opt['to'];				if ( $opt['precision'] != 'second' ) {					$dif = round( ( $dif / $per[$opt['precision']] ) ) * $per[$opt['precision']];			( 0 == $dif ) && ( $str = 'less than 1 ' . $opt['precision'] );				}				foreach ( $per as $lab => $value ) {					( ( $x = floor( $dif / $value ) ) && $opt['parts']-- ) && $str .= ( $str ? $opt['separator'] : '' ) . ( $x . ' ' . $lab . ( $x > 1 ? 's' : '' ) );			if ( $opt['parts'] == 0 || $lab == $opt['precision'] ) break;			$dif -= $x * $value;					}				$opt['distance'] && $str .= ( $str && $opt['to'] > $sta ) ? ' ago' : ' away';				return( $str );			}			function fg_getext( $fil ) {			$exp = explode( '.', $fil );		$end = end( $exp );				return strtolower( '.' . $end ); 		}		function fg_redirect( $mes, $red = 'index.php', $tim = 3 ) {			$_SESSION['red'] = $red;		$_SESSION['tim'] = $tim;		$_SESSION['mes'] = $mes;		header( 'location: redir.php' );		}		function fg_bool( $mes, $boo ) {			$cla = ( $boo == 0 ) ? 'error' : 'success';		$ret = "\n\n" . '<div class="' . $cla . '">' . $mes . '</div>' . "\n\n";				return( $ret );		}		// Topic/post functions		function fg_insertid( $tab ) {			$que = "SHOW TABLE STATUS LIKE '" . $tab . "'";		$res = mysql_query( $que );		$fet = mysql_fetch_assoc( $res );				return( $fet['Auto_increment'] );		}			function fg_lastpost( $int, $col ) {			$que = "SELECT * FROM posts WHERE id = '" . fg_nth( 'posts', true, 'id', 0, " WHERE topic = '" . $int . "'" ) . "'";		$res = mysql_query( $que );		$fet = mysql_fetch_assoc( $res );						return( $fet[$col] );		}?>