$file_id ) , $username ) ) { http403(); } } } else if ( ( ! isset( $_GET['t'] ) ) && ( isset( $_GET['h'] ) ) ) { http404(); } else if ( ( isset( $_GET['t'] ) ) && ( ! isset( $_GET['h'] ) ) ) { http404(); } /* |-------------------------------------------------------------------------- | Load config |-------------------------------------------------------------------------- | */ list( $badges , $files ) = config_load(); if ( ! isset( $files[ $file_id ] ) ) { http403(); } if ( ( isset( $files[ $file_id ]['export'] ) ) && ( $files[ $file_id ]['export'] === false ) ) { http403(); } if ( ( EXPORT === false ) && ( ! isset( $files[ $file_id ]['export'] ) ) ) { http403(); } /* |-------------------------------------------------------------------------- | Get logs |-------------------------------------------------------------------------- | */ $search = ( isset( $_GET['search'] ) ) ? $_GET['search'] : ''; $format = ( isset( $_GET['format'] ) ) ? $_GET['format'] : 'JSON'; $count = ( isset( $_GET['count'] ) ) ? $_GET['count'] : ( ( isset( $files[ $file_id ][ 'max' ] ) ) ? $files[ $file_id ][ 'max' ] : LOGS_MAX ); $timeout = ( isset( $_GET['timeout'] ) ) ? $_GET['timeout'] : MAX_SEARCH_LOG_TIME; $regex = $files[ $file_id ][ 'format' ][ 'regex' ]; $match = $files[ $file_id ][ 'format' ][ 'match' ]; $types = $files[ $file_id ][ 'format' ][ 'types' ]; $multiline = ( isset( $files[ $file_id ][ 'format' ][ 'multiline' ] ) ) ? $files[ $file_id ][ 'format' ][ 'multiline' ] : ''; $exclude = ( isset( $files[ $file_id ][ 'format' ][ 'exclude' ] ) ) ? $files[ $file_id ][ 'format' ][ 'exclude' ] : array(); $title = ( isset( $files[ $file_id ][ 'format' ][ 'export_title' ] ) ) ? $files[ $file_id ][ 'format' ][ 'export_title' ] : ''; $file_path = $files[$file_id]['path']; $start_offset = 0; $start_from = SEEK_END; $load_more = false; $old_lastline = ''; $data_to_parse = filesize( $file_path ); $full = true; $logs = LogParser::getNewLines( $regex , $match , $types , $tz , $count , $exclude , $file_path , $start_offset , $start_from , $load_more , $old_lastline , $multiline , $search , $data_to_parse , $full , $timeout ); /* |-------------------------------------------------------------------------- | Error while getting logs |-------------------------------------------------------------------------- | */ if ( ! is_array( $logs ) ) { http500(); } /* |-------------------------------------------------------------------------- | Return |-------------------------------------------------------------------------- | */ $link = str_replace( 'inc/rss.php' , '' , get_current_url( true ) ); header( "Pragma: public" ); header( "Expires: 0" ); header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); switch ( $format ) { case 'ATOM': case 'RSS': require( 'classes/Feedcreator.php' ); define( 'TIME_ZONE' , $tz ); define( 'FEEDCREATOR_VERSION', 'Pimp My Log v' . get_current_pml_version() ); $rss = new UniversalFeedCreator(); $rss->title = sprintf( __( "Pimp My Log : %s" ) , $files[ $file_id ][ 'display' ] ); $rss->description = ( empty( $search ) ) ? sprintf( __( "Pimp logs for file %s" ), $files[ $file_id ][ 'path' ] ) : sprintf( __( "Pimp logs for file %s with search %s" ), $files[ $file_id ][ 'path' ] , $search ); $rss->descriptionTruncSize = 500; $rss->descriptionHtmlSyndicated = true; $rss->link = $link; $rss->syndicationURL = get_current_url( true ); $image = new FeedImage(); $image->title = $rss->title; $image->url = str_replace( 'inc/rss.php' , 'img/icon72.png' , get_current_url() ); $image->link = $link; $image->description = __( "Feed provided by Pimp My Log" ); $image->descriptionTruncSize = 500; $image->descriptionHtmlSyndicated = true; $rss->image = $image; if ( ( isset( $logs['logs'] ) ) && ( is_array( $logs['logs'] ) ) ) { foreach( array_reverse( $logs['logs'] ) as $log ) { $item = new FeedItem(); $description = ''; foreach( $log as $key => $value ) { if ( substr( $key , 0 , 3) !== 'pml' ) { $description .= '' . h( $key ) . ' : ' . h( $value ) . '
'; } } $item->description = $description; if ( isset( $log['pmld'] ) ) { $item->date = $log['pmld']; } if ( isset( $log[ $title ] ) ) { $item->title = $log[ $title ]; } else { $item->title = current( $log ) . ' - ' . sha1( serialize( $log ) ); } if ( $format === 'ATOM' ) { $item->author = 'PmL'; } $item->link = $link . '&' . $log['pmlo']; $item->guid = $link . '&' . $log['pmlo']; $item->descriptionTruncSize = 500; $item->descriptionHtmlSyndicated = true; $rss->addItem($item); } } $rss->outputFeed( $tz , $format ); break; case 'CSV': header( "Content-Transfer-Encoding: binary" ); header( "Content-Disposition: attachment;filename=PimpMyLog_" . get_slug( $file_id) . "_" . date( "Y-m-d-His" ) . '.csv' ); header( "Content-type: application/vnd.ms-excel; charset=UTF-16LE" ); echo chr( 255 ) . chr( 254 ) . mb_convert_encoding( array2csv( $logs['logs'] ) , 'UTF-16LE' , 'UTF-8' ); break; case 'XML': header('Content-type: application/xml', true); $xml = ''; $xml .= ''; $xml .= generate_xml_from_array( $logs , 'log' ); $xml .= ''; echo $xml; break; case 'JSONPR': header('Content-type: application/json', true); if ( version_compare( PHP_VERSION , '5.4.0' ) >= 0 ) { echo json_encode( $logs , JSON_PRETTY_PRINT ); } else { echo json_indent( json_encode( $logs ) ); } break; case 'JSONP': header('Content-type: application/javascript', true); echo ( isset( $_GET['callback'] ) ) ? $_GET['callback'] : '?'; echo '('; echo json_encode( $logs ); echo ')'; break; case 'JSON': default: header('Content-type: application/json', true); echo json_encode( $logs ); break; } ?>